Expand description
Stable SDK-facing API surface for embedding Pi as a library.
This module is the supported entry point for external library consumers.
Prefer importing from pi::sdk instead of deep internal modules.
§Examples
use pi::sdk::{AgentEvent, Message, ToolDefinition};
let _events: Vec<AgentEvent> = Vec::new();
let _messages: Vec<Message> = Vec::new();
let _tools: Vec<ToolDefinition> = Vec::new();Internal implementation types are intentionally not part of this surface.
ⓘ
use pi::sdk::RpcSharedState;Structs§
- Abort
Handle - Handle to request an abort of an in-flight agent run.
- Abort
Signal - Signal for observing abort requests.
- Agent
- The agent runtime that orchestrates LLM calls and tool execution.
- Agent
Config - Configuration for the agent.
- Agent
Session - Agent
Session Handle - Lightweight handle for programmatic embedding.
- Agent
Session State - Snapshot of the current agent session state.
- Assistant
Message - An assistant message.
- Config
- Main configuration structure.
- Cost
- Cost breakdown in dollars.
- Custom
Message - A custom message injected by the host or extensions.
- Event
Listeners - Collection of session-level event listeners.
- Extension
Manager - Extension manager for handling loaded extensions.
- Extension
Policy - Extension
Region - RAII guard for extension lifecycle with structured concurrency guarantees.
- Image
Content - Image content block.
- Model
- A model definition loaded from the models registry.
- Model
Cost - Model pricing per million tokens.
- Model
Entry - Model
Registry - Provider
Context - Inputs to a single completion request.
- Provider
Thinking Budgets - Custom thinking token budgets per level.
- RpcBash
Result - Bash execution result returned by RPC
bash. - RpcCancelled
Result - Result payload for
new_sessionandswitch_session. - RpcCommand
Info - Slash command metadata returned by RPC
get_commands. - RpcCompaction
Result - Compaction result returned by RPC
compact. - RpcCycle
Model Result - Result payload returned by RPC
cycle_model. - RpcExport
Html Result - Export HTML response payload.
- RpcFork
Message - Forkable message entry returned by RPC
get_fork_messages. - RpcFork
Result - Result payload returned by RPC
fork. - RpcLast
Assistant Text - Last-assistant-text response payload.
- RpcModel
Info - Model metadata exposed by RPC APIs.
- RpcSession
State - Session state payload returned by RPC
get_state. - RpcSession
Stats - Session stats payload returned by RPC
get_session_stats. - RpcThinking
Level Result - Result payload returned by RPC
cycle_thinking_level. - RpcToken
Stats - Session-level token aggregates returned by RPC
get_session_stats. - RpcTransport
Client - Subprocess-backed SDK transport for
pi --mode rpc. - RpcTransport
Options - Process-boundary transport options for SDK callers that prefer RPC mode.
- Session
- A session manages conversation state and persistence.
- Session
Options - SDK session construction options.
- Stream
Options - Options that control streaming completion behavior.
- Subscription
Id - Opaque identifier for an event subscription.
- Text
Content - Text content block.
- Thinking
Content - Thinking/reasoning content block.
- Tool
Call - Tool call content block.
- ToolDef
- A tool definition exposed to the model.
- Tool
Output - Tool execution output.
- Tool
Registry - Registry of enabled tools for a Pi run.
- Tool
Result Message - A tool result message.
- Tool
Update - Incremental update during tool execution.
- Usage
- Token usage and cost tracking.
- User
Message - A user message.
Enums§
- Agent
Event - Events emitted by the agent during execution.
- Content
Block - A content block in a message.
- Error
- Main error type for the Pi application.
- Input
Type - Input types supported by a model.
- Message
- A message in a conversation.
- Queue
Mode - RpcExtension
UiResponse - Extension UI response payload used by RPC
extension_ui_response. - Session
Prompt Result - Prompt completion payload returned by
SessionTransport. - Session
Transport - Unified adapter over in-process and subprocess-backed session control.
- Session
Transport Event - Event wrapper used by the unified
SessionTransportcallback. - Session
Transport State - Unified session state snapshot across in-process and RPC transports.
- Stop
Reason - Why a response ended.
- Stream
Event - Streaming event from a provider.
- Thinking
Level - Extended thinking level.
- User
Content - User message content - either plain text or blocks.
Constants§
- BUILTIN_
TOOL_ NAMES - All built-in tool names.
Traits§
- Provider
- An LLM backend capable of streaming assistant output (and tool calls).
- Tool
- A tool that can be executed by the agent.
- Tool
Factory - Hook for assembling the session’s
ToolRegistry.
Functions§
- all_
tool_ definitions - Return
ToolDefinitionschemas for all built-in tools. - create_
agent_ session - Create a fully configured embeddable agent session.
- create_
all_ tools - Create all built-in tools configured for
cwd. - create_
bash_ tool - Create a bash tool configured for
cwd. - create_
edit_ tool - Create an edit tool configured for
cwd. - create_
find_ tool - Create a find tool configured for
cwd. - create_
grep_ tool - Create a grep tool configured for
cwd. - create_
hashline_ edit_ tool - Create a hashline edit tool configured for
cwd. - create_
ls_ tool - Create an ls tool configured for
cwd. - create_
read_ tool - Create a read tool configured for
cwd. - create_
write_ tool - Create a write tool configured for
cwd. - default_
tool_ registry - Build the same
ToolRegistrycreate_agent_sessionuses by default. - tool_
to_ definition - Convert a
Toolinto itsToolDefinitionschema.
Type Aliases§
- Event
Subscriber - OnStream
Event - Callback invoked for every raw provider
StreamEvent. - OnTool
End - Callback invoked when a tool execution ends.
- OnTool
Start - Callback invoked when a tool execution starts.
- Result
- Result type alias using our error type.
- Tool
Definition - Stable alias for model-exposed tool schema definitions.