model_select and thinking_level_select events to model_update and thinking_level_update.tools_update events, branch-scoped active-tool persistence, and duplicate tool validation.auto so providers can use their best available transport by default (#4083).shouldStopAfterTurn to the low-level agent loop config for gracefully exiting after a completed turn before polling queued messages or starting another LLM call.@sinclair/typebox 0.34.x to typebox 1.x. Install and import from typebox instead of relying on @sinclair/typebox transitively (#3112)terminate: true tool-result hints to skip the automatic follow-up LLM call when every finalized tool result in the current batch opts into early termination (#3525)streamProxy() to preserve the proxy-safe serializable subset of stream options, including session, transport, retry-delay, metadata, header, cache-retention, and thinking-budget settings (#3512)tool_execution_end as soon as each tool is finalized, while still emitting persisted tool-result messages in assistant source order (#3503)afterToolCall hook throws into error tool results instead of aborting the batch (#3084)AgentState has been reshaped:
streamMessage was renamed to streamingMessageerror was renamed to errorMessageisStreaming, streamingMessage, pendingToolCalls, and errorMessage are now readonly in the public APIpendingToolCalls is now typed as ReadonlySet<string>tools and messages are now accessor properties, and assigning either field copies the provided top-level array instead of preserving array identityAgentOptions.initialState no longer accepts runtime-owned fields. Remove isStreaming, streamingMessage, pendingToolCalls, and errorMessage from initialState values.Agent mutator methods in favor of direct property access:
agent.setSystemPrompt(value) -> agent.state.systemPrompt = valueagent.setModel(model) -> agent.state.model = modelagent.setThinkingLevel(level) -> agent.state.thinkingLevel = levelagent.setTools(tools) -> agent.state.tools = toolsagent.replaceMessages(messages) -> agent.state.messages = messagesagent.appendMessage(message) -> agent.state.messages.push(message)agent.clearMessages() -> agent.state.messages = []agent.setToolExecution(mode) -> agent.toolExecution = modeagent.setBeforeToolCall(fn) -> agent.beforeToolCall = fnagent.setAfterToolCall(fn) -> agent.afterToolCall = fnagent.setTransport(transport) -> agent.transport = transportagent.setSteeringMode(mode) -> agent.steeringMode = modeagent.getSteeringMode() -> agent.steeringModeagent.setFollowUpMode(mode) -> agent.followUpMode = modeagent.getFollowUpMode() -> agent.followUpModeAgent.subscribe() listeners are now awaited and receive the active AbortSignal:
agent.subscribe((event) => { ... }) -> agent.subscribe(async (event, signal) => { ... })agent_end is now the final emitted event for a run, but not the idle boundaryagent.waitForIdle(), agent.prompt(...), and agent.continue() now settle only after awaited agent_end listeners finishagent.state.isStreaming remains true until that settlement completesAgentTool.prepareArguments hook to prepare raw tool call arguments before schema validation, enabling compatibility shims for resumed sessions with outdated tool schemasAgent.signal to expose the active abort signal for the current turn, allowing callers to forward cancellation into nested async work (#2660)beforeToolCall and afterToolCall hooks to AgentOptions and AgentLoopConfig for preflight blocking and post-execution tool result mutation.Agent and agentLoop via toolExecution: "parallel" | "sequential", with parallel as the default. Parallel mode preflights tool calls sequentially, executes allowed tools concurrently, and emits final tool results in assistant source order.transport to AgentOptions and AgentLoopConfig forwarding, allowing stream transport preference ("sse", "websocket", "auto") to flow into provider calls.continue() to resume queued steering/follow-up messages when context currently ends in an assistant message, and preserved one-at-a-time steering ordering during assistant-tail resumes (#1312 by @ferologics)maxRetryDelayMs option to AgentOptions to cap server-requested retry delays. Passed through to the underlying stream function. (#1123)thinkingBudgets option on Agent and AgentOptions to customize token budgets per thinking level (#529 by @melihmucuk)sessionId option on Agent to forward session identifiers to LLM providers for session-based caching.minimal thinking level now maps to minimal reasoning effort instead of being treated as low.queueMessage() method has been split into two methods with different delivery semantics (#403):
steer(msg): Interrupts the agent mid-run. Delivered after current tool execution, skips remaining tools.followUp(msg): Waits until the agent finishes. Delivered only when there are no more tool calls or steering messages.queueMode option renamed to steeringMode. Added new followUpMode option. Both control whether messages are delivered one-at-a-time or all at once.getQueuedMessages split into getSteeringMessages and getFollowUpMessages.queueMessage() → steer() and followUp()clearMessageQueue() → clearSteeringQueue(), clearFollowUpQueue(), clearAllQueues()setQueueMode()/getQueueMode() → setSteeringMode()/getSteeringMode() and setFollowUpMode()/getFollowUpMode()prompt() and continue() now throw if called while the agent is already streaming, preventing race conditions and corrupted state. Use steer() or followUp() to queue messages during streaming, or await the previous call.Transport abstraction removed: ProviderTransport, AppTransport, and AgentTransport interface have been removed. Use the streamFn option directly for custom streaming implementations.
Agent options renamed:
transport → removed (use streamFn instead)messageTransformer → convertToLlmpreprocessor → transformContextAppMessage renamed to AgentMessage: All references to AppMessage have been renamed to AgentMessage for consistency.
CustomMessages renamed to CustomAgentMessages: The declaration merging interface has been renamed.
UserMessageWithAttachments and Attachment types removed: Attachment handling is now the responsibility of the convertToLlm function.
Agent loop moved from @mariozechner/pi-ai: The agentLoop, agentLoopContinue, and related types have moved to this package. Import from @mariozechner/pi-agent-core instead.
streamFn option on Agent for custom stream implementations. Default uses streamSimple from pi-ai.
streamProxy() utility function for browser apps that need to proxy LLM calls through a backend server. Replaces the removed AppTransport.
getApiKey option for dynamic API key resolution (useful for expiring OAuth tokens like GitHub Copilot).
agentLoop() and agentLoopContinue() low-level functions for running the agent loop without the Agent class wrapper.
New exported types: AgentLoopConfig, AgentContext, AgentTool, AgentToolResult, AgentToolUpdateCallback, StreamFn.
Agent constructor now has all options optional (empty options use defaults).
queueMessage() is now synchronous (no longer returns a Promise).