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;Re-exports§
pub use crate::agent::AbortHandle;pub use crate::agent::AbortSignal;pub use crate::agent::Agent;pub use crate::agent::AgentConfig;pub use crate::agent::AgentEvent;pub use crate::agent::AgentSession;pub use crate::agent::QueueMode;pub use crate::config::Config;pub use crate::error::Error;pub use crate::error::Result;pub use crate::extensions::ExtensionManager;pub use crate::extensions::ExtensionPolicy;pub use crate::extensions::ExtensionRegion;pub use crate::model::AssistantMessage;pub use crate::model::ContentBlock;pub use crate::model::Cost;pub use crate::model::CustomMessage;pub use crate::model::ImageContent;pub use crate::model::Message;pub use crate::model::StopReason;pub use crate::model::StreamEvent;pub use crate::model::TextContent;pub use crate::model::ThinkingContent;pub use crate::model::ToolCall;pub use crate::model::ToolResultMessage;pub use crate::model::Usage;pub use crate::model::UserContent;pub use crate::model::UserMessage;pub use crate::models::ModelEntry;pub use crate::models::ModelRegistry;pub use crate::provider::Context as ProviderContext;pub use crate::provider::InputType;pub use crate::provider::Model;pub use crate::provider::ModelCost;pub use crate::provider::Provider;pub use crate::provider::StreamOptions;pub use crate::provider::ThinkingBudgets as ProviderThinkingBudgets;pub use crate::provider::ToolDef;pub use crate::session::Session;pub use crate::tools::Tool;pub use crate::tools::ToolOutput;pub use crate::tools::ToolRegistry;pub use crate::tools::ToolUpdate;
Structs§
- Agent
Session Handle - Lightweight handle for programmatic embedding.
- Agent
Session State - Snapshot of the current agent session state.
- Event
Listeners - Collection of session-level event listeners.
- 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
Options - SDK session construction options.
- Subscription
Id - Opaque identifier for an event subscription.
Enums§
- 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.
Constants§
- BUILTIN_
TOOL_ NAMES - All built-in tool names.
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_
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. - 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.
- Tool
Definition - Stable alias for model-exposed tool schema definitions.