Skip to main content

Crate rpi_agent

Crate rpi_agent 

Source
Expand description

Mirrors packages/agent/src (core layer: agent + agent-loop + types + stream-fn).

Provider-agnostic agent runtime. The only LLM boundary is StreamFn (sync return → [AssistantMessageEventStream]); everything else talks in AgentMessage and never touches a provider wire format.

M2 scope per the plan: AgentTool trait, Agent + AgentBuilder, run_agent_loop / run_agent_loop_continue free functions, events, hooks, queues, abort. The critical invariants — tool-execution ordering (end in completion order, tool-result MessageEnd in source/ordinal order), truncate-fail, and late-update suppression — live in agent_loop.

Re-exports§

pub use abort::AbortHandle;
pub use agent::Agent;
pub use agent::AgentBuilder;
pub use agent::AgentOptions;
pub use agent_loop::run_agent_loop;
pub use agent_loop::run_agent_loop_continue;
pub use agent_loop::LoopOutcome;
pub use agent_loop::NewMessages;
pub use agent_tool::AgentTool;
pub use error::AgentError;
pub use events::AgentEmitter;
pub use events::AgentEvent;
pub use events::CollectorEmitter;
pub use hooks::AfterToolCall;
pub use hooks::AfterToolResults;
pub use hooks::AgentLoopConfig;
pub use hooks::BeforeToolCall;
pub use hooks::ConvertToLlm;
pub use hooks::GetApiKey;
pub use hooks::GetFollowUpMessages;
pub use hooks::GetSteeringMessages;
pub use hooks::PrepareNextTurn;
pub use hooks::ShouldStopAfterTurn;
pub use hooks::TransformContext;
pub use message::AgentMessage;
pub use message::AgentMessageRole;
pub use message::CustomMessage;
pub use queue::PendingMessageQueue;
pub use stream_fn::stream_fn;
pub use stream_fn::StreamFn;
pub use types::AfterToolCallContext;
pub use types::AfterToolCallResult;
pub use types::AgentContext;
pub use types::AgentLoopTurnUpdate;
pub use types::AgentState;
pub use types::AgentToolResult;
pub use types::BeforeToolCallContext;
pub use types::BeforeToolCallResult;
pub use types::QueueMode;
pub use types::ShouldStopAfterTurnContext;
pub use types::TextContentOrImage;
pub use types::ToolExecutionMode;
pub use types::ToolResultPartial;

Modules§

abort
Mirrors the abort surface of packages/agent/src/agent.ts / packages/agent/src/agent-loop.ts. TS threads an AbortSignal through every layer; Rust uses tokio_util::sync::CancellationToken instead.
agent
Mirrors packages/agent/src/agent.ts — the stateful wrapper around the low-level agent loop. Agent owns the current transcript, emits lifecycle events to subscribers, executes tools, and exposes queueing APIs for steering and follow-up messages.
agent_loop
Mirrors packages/agent/src/agent-loop.ts — the provider-agnostic agent loop.
agent_tool
Mirrors the tool-definition portion of packages/agent/src/types.ts (AgentTool<TParameters, TDetails>).
error
Mirrors packages/agent/src error surface. Pi’s agent layer reports failures via thrown errors that the loop catches and encodes into tool results / event sequences; Rust encodes the same cases as a per-crate thiserror enum.
events
Mirrors packages/agent/src/types.ts::AgentEvent — the lifecycle events the agent loop emits. Carried over a broadcast::Sender<AgentEvent> so multiple subscribers each get their own copy; payloads are Arc-wrapped where they are large to keep broadcast clones cheap.
hooks
Mirrors packages/agent/src/types.ts::AgentLoopConfig — the config bundle the low-level loop consumes. TS AgentLoopConfig extends SimpleStreamOptions and adds model + a set of async hooks. Rust models it as a struct of Option<Arc<dyn Fn>>> hooks (required convert_to_llm is non-optional), the model, and a SimpleStreamOptions-derived subset the loop forwards to StreamFn.
message
Mirrors packages/agent/src/types.ts (open enum portion) — the AgentMessage = Message | Custom declaration-merging model.
queue
Mirrors the queue portion of packages/agent/src/agent.ts (PendingMessageQueue) + the QueueMode type from packages/agent/src/types.ts.
stream_fn
Mirrors packages/agent/src/stream-fn.ts + the StreamFn type alias in packages/agent/src/types.ts.
types
Mirrors packages/agent/src/types.ts — the public type contract of the agent layer: tool results, hook payloads, agent state, events.