pi-agent-integration
Guides implementation and review of the latest `@earendil-works/pi-agent-core` API. Use when a task mentions Pi `Agent`, agent loops, streaming, tools, queues, continuation, proxying, or aborts.
- License 许可
- Apache-2.0
- 所属仓库
- getsentry/junior
- 最近更新
- 2026-11-15
- Stars
- ★ 421
- Forks
- 45
01 前言 Front Matter
- name
- pi-agent-integration
- description
- Guides implementation and review of the latest `@earendil-works/pi-agent-core` API. Use when a task mentions Pi `Agent`, agent loops, streaming, tools, queues, continuation, proxying, or aborts.
02 资源文件 5
- 参考文档references/api-surface.md10.7 KB
- 参考文档references/common-use-cases.md4.0 KB
- 参考文档references/troubleshooting-workarounds.md6.9 KB
- 参考文档SOURCES.md11.1 KB
- 参考文档SPEC.md4.0 KB
03 SKILL.md 正文
Implement Pi consumers against the latest published API. Keep streaming stable, queue behavior explicit, and wrapper code small.
Step 1: Classify the request
| Request type | Read first |
|---|---|
Wire or update Agent, loop, provider, stream, or tool APIs |
references/api-surface.md |
| Add Pi behavior in an app, library, runtime, or adapter | references/common-use-cases.md |
| Debug streaming, tools, queues, continuation, proxy, or abort failures | references/troubleshooting-workarounds.md |
Load each reference that the task needs. Keep guidance Pi-specific unless the user asks about a consuming product.
Step 2: Apply integration guardrails
- Check npm
latestfor@earendil-works/pi-agent-corebefore relying on a contract. Treat the published package as authoritative. Treat upstreammainas unreleased evidence. - Pass a
streamFnwhen constructingAgent. Also pass it as the last argument to low-level loop functions. - Use
Agentwhen event handling must finish before run settlement. UseagentLooponly when an observational event stream is enough. - Stream user-visible text only from
message_updatewhenassistantMessageEvent.type === "text_delta". - Preserve assistant message boundaries when forwarding multi-message output.
- Do not call
prompt(),continue(), orreset()while an agent is active. Queue mid-run input withsteer()orfollowUp(). - Continue a normal run only from a non-empty
userortoolResulttail. Anassistanttail can only drain queued steering or follow-up messages. - Keep
streamFn,convertToLlm,transformContext,getApiKey, queue providers, and loop hooks no-throw for expected failures. Return safe values or encode the failure in stream events. - Keep tool calls, progress, results, thinking deltas, and provider payloads internal unless the product exposes them on purpose.
- Since
1.0.0, the package contains onlyAgent, the agent loop, the proxy stream, and their types. The harness, sessions, compaction, skills, and prompt-template helpers are gone. Do not recommend them.
Step 3: Implement with minimal surface
- Prefer Pi options over wrapper state machines:
streamFn,getApiKey,sessionId,thinkingBudgets,transport,maxRetryDelayMs,identity,onPayload,onResponse,onProviderStreamEvent,beforeToolCall,afterToolCall,finishTurn,prepareRequest,prepareNextTurnWithContext,toolExecution,steeringMode, andfollowUpMode. - Mutate
Agentthroughagent.stateand public runtime options.agent.state.systemPromptis read-only: append a system message to change the prompt. Callreset()only when idle. - Use
transformContextfor message-level pruning or injection. UseconvertToLlmfor provider-compatible role conversion and filtering. - Set queue modes to
"one-at-a-time"or"all"when ordering or batching matters. - Use
streamFnwithstreamProxy-style behavior for server-proxied model access. - Use
toolExecution, per-toolexecutionMode,beforeToolCall,afterToolCall, thrown errors orisError: trueresults, andterminatebefore adding a custom tool runner. - Keep timeout and abort paths observable. Make sure streams and iterables settle.
Step 4: Verify behavior
- Verify the event bridge emits only text deltas, preserves intended boundaries, and closes on success, error, and abort.
- Verify active-run handling for
prompt(),continue(), andreset(). Verify queuedsteer()andfollowUp()behavior. - Verify
continue()with empty history and withuser,toolResult, andassistanttails. - Verify custom messages remain in agent state while
convertToLlmemits only provider-compatible messages. - Verify
streamFnencodes expected provider failures instead of throwing or rejecting. - Verify parallel and sequential tool ordering, hook blocking and patches, progress updates, usage,
agent.state.toolschanges, and termination. - Verify
Agent.subscribe()listener settlement andwaitForIdle()with async listeners.
Step 5: Keep version discipline
- Target npm
latestonly. - Re-check package metadata, declarations, implementation, README, and changelog before a material API update.
- Do not present unreleased
mainbehavior as published behavior. - Do not add compatibility shims or old package guidance unless the user asks for a migration.
04 同仓库更多 Skills
pantry-stock
Report what the office pantry has in stock. Use when users ask which snacks or drinks the pantry has, or what is running low.
junior
Build, review, or update Junior extension skills and plugins. Use when users ask to create a Junior SKILL.md, app skill, plugin, plugin.yaml, packaged plugin, MCP-backed plugin, OAuth or credentialed plugin, or to validate Junior extension files. Do not use for ordinary Junior usage, provider workflows, generic code editing, or non-Junior agent-skill authoring.
junior-qa
Validate Junior changes through local app-facing paths. Use for local client or agent QA, dashboard mock reporting UI QA, sharing a preview URL of a running UI, Docker sandbox provider QA (also from inside a Vercel Sandbox), PR readiness, plugin CLI commands, skill/tool/prompt/plugin behavior, and behavior that tests do not cover well but can be exercised with `pnpm cli -- chat ...`, another `pnpm cli` command, or `JUNIOR_DASHBOARD_MOCK_CONVERSATIONS=true pnpm dev`.
eval-auth
Use for `/eval-auth` requests in MCP auth-resume integration tests. Always connect through the disclosed MCP tool before answering, then continue the user's actual request using prior thread context when needed.
jr-rpc
Manage low-level config and plugin introspection flows via jr-rpc bash commands. Use only when the user explicitly asks to read or update provider defaults/config or list installed plugins. Do not use for PR, branch, push, or auth-order questions; load the matching provider skill instead.
xdotcom
Read public X (Twitter) data through the read-only X API v2. Use when users share an x.com or twitter.com link, or ask what someone posted on X, what people are saying about a topic, product, or launch on X, how much chatter something got, or for a post's text, metrics, replies, or an account's recent posts. Do not use it to post, reply, like, repost, follow, or send DMs, or to read private or protected data.