Skip to main content
The @mariozechner/pi-agent-core package provides the core agent runtime with tool execution, message handling, and state management.

Import

Agent Class

The Agent class manages conversation state, tool execution, and LLM interactions.

Constructor

AgentOptions

Properties

AgentState
Current agent state (read-only)

Methods

prompt

Send a user message and run the agent.
string | Content[]
required
User message content
AbortSignal
Abort signal for cancellation
Returns an event stream that emits agent events and resolves to new messages.

continue

Continue the agent from current state (for retries).

updateState

Update agent state.
Partial<AgentState>
required
State fields to update

Example

Agent Loop Functions

Lower-level functions for custom agent implementations.

agentLoop

Start an agent loop with new user message(s).
AgentMessage[]
required
User messages to add to context
AgentContext
required
Current conversation context
AgentLoopConfig
required
Loop configuration (model, convertToLlm, etc.)

agentLoopContinue

Continue an agent loop from current context.
Used for retries when the last message is a user message or tool result.

Agent State

The agent’s current state.
string
System prompt defining agent behavior
Model
Current LLM model
ThinkingLevel
Reasoning intensity level
AgentTool[]
Available tools
AgentMessage[]
Conversation history
boolean
Whether agent is currently streaming
AgentMessage | null
Current streaming message (if any)
Set<string>
Tool call IDs awaiting execution
string
Last error message (if any)

Agent Tool

Tool definition for the agent.
string
required
Unique tool name
string
required
Description for the LLM
TSchema
required
TypeBox schema for parameters
function
required
Execute the tool and return result

AgentToolResult

Content[]
Content to send to LLM
T
Metadata for UI/logging (not sent to LLM)

Events

The agent emits events during execution:
  • agent_start - Agent turn begins
  • agent_end - Agent turn completes
  • turn_start - Turn starts
  • turn_end - Turn ends
  • message_start - Message added to context
  • message_update - Streaming message delta
  • message_end - Message complete
  • tool_execution_start - Tool execution begins
  • tool_execution_update - Tool execution progress
  • tool_execution_end - Tool execution completes

Example