pub struct Agent { /* private fields */ }Expand description
The unified agent. Holds the model client, memo store, sandbox, and a
shared handle to the currently-served ActiveHarness (which may be
hot-swapped by a self-improvement loop).
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_harness(
config: AgentConfig,
model: Box<dyn ModelClient>,
memo: Arc<dyn MemoStore>,
harness: Arc<ActiveHarness>,
) -> Result<Self, CoreError>
pub fn with_harness( config: AgentConfig, model: Box<dyn ModelClient>, memo: Arc<dyn MemoStore>, harness: Arc<ActiveHarness>, ) -> Result<Self, CoreError>
Build with an explicit model client (e.g. StubModel or [OpenAiModel])
and a shared, hot-swappable harness handle.
Sourcepub fn with_sandbox(
config: AgentConfig,
model: Box<dyn ModelClient>,
memo: Arc<dyn MemoStore>,
harness: Arc<ActiveHarness>,
sandbox: Arc<dyn Sandbox>,
) -> Result<Self, CoreError>
pub fn with_sandbox( config: AgentConfig, model: Box<dyn ModelClient>, memo: Arc<dyn MemoStore>, harness: Arc<ActiveHarness>, 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>,
memo: Arc<dyn MemoStore>,
) -> Result<Self, CoreError>
pub fn with_model( config: AgentConfig, model: Box<dyn ModelClient>, memo: Arc<dyn MemoStore>, ) -> Result<Self, CoreError>
Build with an explicit model client (e.g. StubModel or [OpenAiModel]).
A baseline harness is generated from the config’s agent name.
Sourcepub fn new(
config: AgentConfig,
memo: Arc<dyn MemoStore>,
) -> Result<Self, CoreError>
pub fn new( config: AgentConfig, memo: Arc<dyn MemoStore>, ) -> Result<Self, CoreError>
Build using the default model (stub unless openai feature is on).
pub fn session(&self) -> &str
Sourcepub fn harness(&self) -> Arc<ActiveHarness> ⓘ
pub fn harness(&self) -> Arc<ActiveHarness> ⓘ
Shared harness handle — hot-swappable by a self-improvement loop.
Sourcepub fn memo(&self) -> Arc<dyn MemoStore> ⓘ
pub fn memo(&self) -> Arc<dyn MemoStore> ⓘ
Shared memo 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 memo 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.