pub struct AgentRuntime { /* private fields */ }Expand description
The single Turn/Step loop. Build it with AgentRuntime::new and the with_* methods, then call run per Turn.
Implementations§
Source§impl AgentRuntime
impl AgentRuntime
Sourcepub fn new(
model: Arc<dyn ChatModel>,
model_name: impl Into<String>,
system_prompt: impl Into<String>,
) -> Self
pub fn new( model: Arc<dyn ChatModel>, model_name: impl Into<String>, system_prompt: impl Into<String>, ) -> Self
Runtime for model under model_name with system_prompt as the product prompt section and default limits.
Sourcepub fn with_tools(self, tools: ToolRegistry) -> Self
pub fn with_tools(self, tools: ToolRegistry) -> Self
Replace the tool registry.
Sourcepub fn with_hooks(self, hooks: Vec<Arc<dyn Hook>>) -> Self
pub fn with_hooks(self, hooks: Vec<Arc<dyn Hook>>) -> Self
Install hooks; they run in this order.
Sourcepub fn with_limits(self, limits: RuntimeLimits) -> Self
pub fn with_limits(self, limits: RuntimeLimits) -> Self
Replace the runtime limits.
Sourcepub fn with_token_meter(self, meter: Arc<dyn TokenMeter>) -> Self
pub fn with_token_meter(self, meter: Arc<dyn TokenMeter>) -> Self
Replace the token meter.
Sourcepub fn with_compactor(self, compactor: Arc<dyn Compactor>) -> Self
pub fn with_compactor(self, compactor: Arc<dyn Compactor>) -> Self
Replace the compactor.
Sourcepub fn with_reasoning_effort(self, effort: ReasoningEffort) -> Self
pub fn with_reasoning_effort(self, effort: ReasoningEffort) -> Self
Pin the reasoning effort for every model request.
Sourcepub fn with_output_policy(self, schema: Value) -> Result<Self, PluginError>
pub fn with_output_policy(self, schema: Value) -> Result<Self, PluginError>
Validate assistant output against this JSON Schema before it is persisted.
Sourcepub fn with_prompt_section(
self,
section: PromptSection,
) -> Result<Self, PluginError>
pub fn with_prompt_section( self, section: PromptSection, ) -> Result<Self, PluginError>
Add a prompt section; duplicate ids are rejected.
Sourcepub fn with_context_contributor(
self,
context: Arc<dyn ContextContributor>,
) -> Self
pub fn with_context_contributor( self, context: Arc<dyn ContextContributor>, ) -> Self
Add a per-step context contributor.
Sourcepub fn with_plugins(self, mounted: MountedPlugins) -> Result<Self, PluginError>
pub fn with_plugins(self, mounted: MountedPlugins) -> Result<Self, PluginError>
Adopt the prompts, tools, hooks and contributors of mounted plugins.
Sourcepub fn with_allowed_tools(self, allowed: Option<&BTreeSet<String>>) -> Self
pub fn with_allowed_tools(self, allowed: Option<&BTreeSet<String>>) -> Self
Narrow the tool registry to allowed; None keeps every tool.
Source§impl AgentRuntime
impl AgentRuntime
Sourcepub async fn run(
&self,
request: TurnRequest,
writer: &dyn EventWriter,
cancellation: CancellationToken,
) -> Result<RuntimeOutcome, RuntimeError>
pub async fn run( &self, request: TurnRequest, writer: &dyn EventWriter, cancellation: CancellationToken, ) -> Result<RuntimeOutcome, RuntimeError>
Run one Turn for request, appending every model-visible fact through writer and honouring cancellation.
Returns the terminal outcome, or an error after the failure has been recorded.