pub struct Agent { /* private fields */ }Expand description
The unified agent. Holds the model client, context store and sandbox.
The system prompt is static: the agent name plus optional instructions.
Implementations§
Source§impl Agent
impl Agent
Sourcepub const MAX_AGENTIC_STEPS: usize = 8
pub const MAX_AGENTIC_STEPS: usize = 8
Upper bound on model↔tool iterations within one turn (loop-guard).
Sourcepub fn with_sandbox(
config: AgentConfig,
model: Box<dyn ModelClient>,
context: Arc<dyn ContextStore>,
sandbox: Arc<dyn Sandbox>,
) -> Result<Self, CoreError>
pub fn with_sandbox( config: AgentConfig, model: Box<dyn ModelClient>, context: Arc<dyn ContextStore>, sandbox: Arc<dyn Sandbox>, ) -> Result<Self, CoreError>
Build with an explicit sandbox backend (e.g. a local test sandbox or a
codex-backed Sandbox). Useful when the
provider string alone does not describe the execution environment.
Sourcepub fn with_model(
config: AgentConfig,
model: Box<dyn ModelClient>,
context: Arc<dyn ContextStore>,
) -> Result<Self, CoreError>
pub fn with_model( config: AgentConfig, model: Box<dyn ModelClient>, context: Arc<dyn ContextStore>, ) -> Result<Self, CoreError>
Build with an explicit model client (e.g. StubModel or [OpenAiModel]);
the sandbox is resolved from config.sandbox_provider.
Sourcepub fn new(
config: AgentConfig,
context: Arc<dyn ContextStore>,
) -> Result<Self, CoreError>
pub fn new( config: AgentConfig, context: Arc<dyn ContextStore>, ) -> Result<Self, CoreError>
Build using the default model (stub unless openai feature is on).
pub fn session(&self) -> &str
Sourcepub fn system_text(&self) -> String
pub fn system_text(&self) -> String
The static system prompt sent to the model (agent name + optional session/agent instructions).
Sourcepub fn context(&self) -> Arc<dyn ContextStore> ⓘ
pub fn context(&self) -> Arc<dyn ContextStore> ⓘ
Shared context store (used by the SDK to expose Session).
Sourcepub async fn run(&self, input: &str) -> Result<String, CoreError>
pub async fn run(&self, input: &str) -> Result<String, CoreError>
Run one turn. Injects recalled context, calls the model, persists both turns.
Sourcepub async fn exec_tool(&self, command: &[String]) -> Result<String, CoreError>
pub async fn exec_tool(&self, command: &[String]) -> Result<String, CoreError>
Run a shell command inside the sandbox and remember the result.
Sourcepub async fn run_stream(
&self,
input: &str,
) -> Result<BoxStream<'static, Result<String, CoreError>>, CoreError>
pub async fn run_stream( &self, input: &str, ) -> Result<BoxStream<'static, Result<String, CoreError>>, CoreError>
Stream one turn token-by-token. Mirrors Agent::run for the memo
contract (recall before / persist both turns after) but emits model
tokens as they arrive. The returned stream is 'static and owns its
memo handle and model client, so the Agent may be dropped.
Sourcepub async fn exec_tool_call(
&self,
call: &ToolCall,
) -> Result<ToolResult, CoreError>
pub async fn exec_tool_call( &self, call: &ToolCall, ) -> Result<ToolResult, CoreError>
Execute a single tool call inside the sandbox and return its captured
output. The command is taken from the command argument (a JSON array
of strings); the result is persisted to memo as a ToolResult fragment
so subsequent turns can recall it.
Sourcepub async fn run_event_stream(
&self,
input: &str,
tools: &[Tool],
) -> Result<BoxStream<'static, Result<AgentEvent, CoreError>>, CoreError>
pub async fn run_event_stream( &self, input: &str, tools: &[Tool], ) -> Result<BoxStream<'static, Result<AgentEvent, CoreError>>, CoreError>
Run an agentic turn as an event stream: recall memo context → call the
model (with tools) → execute any requested tool calls in the sandbox →
refill memo → repeat until the model emits a final reply. The returned
stream is 'static and owns every dependency, so the Agent may be
dropped while it is still consumed.
Tool execution is delegated to codex’s real SandboxManager via the
CodexSandbox backend (ADR-0005 §Decision) — never a bespoke
in-process executor. Tests inject a local Sandbox
through Agent::with_sandbox.