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 anAbortSignalthrough every layer; Rust usestokio_util::sync::CancellationTokeninstead. - agent
- Mirrors
packages/agent/src/agent.ts— the stateful wrapper around the low-level agent loop.Agentowns 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/srcerror 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-cratethiserrorenum. - events
- Mirrors
packages/agent/src/types.ts::AgentEvent— the lifecycle events the agent loop emits. Carried over abroadcast::Sender<AgentEvent>so multiple subscribers each get their own copy; payloads areArc-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. TSAgentLoopConfig extends SimpleStreamOptionsand addsmodel+ a set of async hooks. Rust models it as a struct ofOption<Arc<dyn Fn>>>hooks (requiredconvert_to_llmis non-optional), themodel, and aSimpleStreamOptions-derived subset the loop forwards toStreamFn. - message
- Mirrors
packages/agent/src/types.ts(open enum portion) — theAgentMessage = Message | Customdeclaration-merging model. - queue
- Mirrors the queue portion of
packages/agent/src/agent.ts(PendingMessageQueue) + theQueueModetype frompackages/agent/src/types.ts. - stream_
fn - Mirrors
packages/agent/src/stream-fn.ts+ theStreamFntype alias inpackages/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.