@mariozechner/pi-agent-core package provides the core agent runtime with tool execution, message handling, and state management.
Import
Agent Class
TheAgent 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
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.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 beginsagent_end- Agent turn completesturn_start- Turn startsturn_end- Turn endsmessage_start- Message added to contextmessage_update- Streaming message deltamessage_end- Message completetool_execution_start- Tool execution beginstool_execution_update- Tool execution progresstool_execution_end- Tool execution completes