Skip to main content

Module sdk

Module sdk 

Source
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§

AgentSessionHandle
Lightweight handle for programmatic embedding.
AgentSessionState
Snapshot of the current agent session state.
EventListeners
Collection of session-level event listeners.
RpcBashResult
Bash execution result returned by RPC bash.
RpcCancelledResult
Result payload for new_session and switch_session.
RpcCommandInfo
Slash command metadata returned by RPC get_commands.
RpcCompactionResult
Compaction result returned by RPC compact.
RpcCycleModelResult
Result payload returned by RPC cycle_model.
RpcExportHtmlResult
Export HTML response payload.
RpcForkMessage
Forkable message entry returned by RPC get_fork_messages.
RpcForkResult
Result payload returned by RPC fork.
RpcLastAssistantText
Last-assistant-text response payload.
RpcModelInfo
Model metadata exposed by RPC APIs.
RpcSessionState
Session state payload returned by RPC get_state.
RpcSessionStats
Session stats payload returned by RPC get_session_stats.
RpcThinkingLevelResult
Result payload returned by RPC cycle_thinking_level.
RpcTokenStats
Session-level token aggregates returned by RPC get_session_stats.
RpcTransportClient
Subprocess-backed SDK transport for pi --mode rpc.
RpcTransportOptions
Process-boundary transport options for SDK callers that prefer RPC mode.
SessionOptions
SDK session construction options.
SubscriptionId
Opaque identifier for an event subscription.

Enums§

RpcExtensionUiResponse
Extension UI response payload used by RPC extension_ui_response.
SessionPromptResult
Prompt completion payload returned by SessionTransport.
SessionTransport
Unified adapter over in-process and subprocess-backed session control.
SessionTransportEvent
Event wrapper used by the unified SessionTransport callback.
SessionTransportState
Unified session state snapshot across in-process and RPC transports.

Constants§

BUILTIN_TOOL_NAMES
All built-in tool names.

Functions§

all_tool_definitions
Return ToolDefinition schemas 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 Tool into its ToolDefinition schema.

Type Aliases§

EventSubscriber
OnStreamEvent
Callback invoked for every raw provider StreamEvent.
OnToolEnd
Callback invoked when a tool execution ends.
OnToolStart
Callback invoked when a tool execution starts.
ToolDefinition
Stable alias for model-exposed tool schema definitions.