pi-agent-integration
par sentry
Integrate `@mariozechner/pi-agent-core` as the agent abstraction inside another library or runtime. Use when implementing or refactoring Pi Agent wrappers,…
npx skills add https://github.com/getsentry/junior --skill pi-agent-integrationImplement 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.