Skip to main content

RuntimeAgentBuilder

Struct RuntimeAgentBuilder 

Source
pub struct RuntimeAgentBuilder { /* private fields */ }
Expand description

Builder for RuntimeAgent with fluent API

Use new() to start building, then chain methods like with_agent(), model(), temperature(), etc. Call build() to get the final runtime agent.

Implementations§

Source§

impl RuntimeAgentBuilder

Source

pub fn new() -> Self

Start building a new runtime agent from scratch

Source

pub async fn from_overlay( layer: AgentConfigOverlay, registry: &CapabilityRegistry, ctx: &SystemPromptContext, ) -> Self

Build from a pre-merged AgentConfigOverlay.

This is the preferred way to build a RuntimeAgent. The caller merges Harness/Agent/Session into a single AgentConfigOverlay (via AgentConfigOverlay::fold), then this method resolves capabilities and assembles the final config.

§Example
let layer = AgentConfigOverlay::fold([
    AgentConfigOverlay::from(&harness),
    AgentConfigOverlay::from(&agent),
    AgentConfigOverlay::from(&session),
]);
let runtime_agent = RuntimeAgentBuilder::from_overlay(layer, &registry, &ctx)
    .await
    .model("gpt-5.2")
    .build();
Source

pub async fn with_harness( self, harness: &Harness, registry: &CapabilityRegistry, ctx: &SystemPromptContext, ) -> Self

Apply a Harness’s configuration to this builder.

Sets the system prompt from the harness and applies harness capabilities. Calls system_prompt_contribution() on each capability for dynamic content. Call this BEFORE with_agent() to establish the base prompt layer.

Source

pub async fn with_agent( self, agent: &Agent, registry: &CapabilityRegistry, ctx: &SystemPromptContext, ) -> Self

Apply an Agent’s configuration to this builder.

Prepends the agent’s system prompt and capabilities on top of the existing prompt (typically from a harness). Call after with_harness().

§Example
let ctx = SystemPromptContext::without_file_store(session_id);
let runtime_agent = RuntimeAgentBuilder::new()
    .with_harness(&harness, &registry, &ctx).await
    .with_agent(&agent, &registry, &ctx).await
    .with_capabilities(&session_caps, &registry, &ctx).await
    .model("gpt-4o")
    .build();
Source

pub async fn with_capabilities( self, capability_ids: &[String], registry: &CapabilityRegistry, ctx: &SystemPromptContext, ) -> Self

Apply capabilities to this builder.

Resolves dependencies, then collects contributions from capabilities:

  • Dependencies are automatically included (topologically sorted)
  • system_prompt_contribution(ctx) called on each (may read from filesystem)
  • System prompt additions are prepended to the current system prompt
  • Tool definitions are added to the tools list
§Arguments
  • capability_ids - Ordered list of capability IDs to apply
  • registry - The capability registry containing implementations
  • ctx - Session context for dynamic prompt resolution
Source

pub async fn with_capability_configs( self, capability_configs: &[AgentCapabilityConfig], registry: &CapabilityRegistry, ctx: &SystemPromptContext, ) -> Self

Apply capability configs to this builder, preserving per-capability configuration.

Source

pub fn system_prompt(self, prompt: impl Into<String>) -> Self

Set the system prompt

Source

pub fn prepend_system_prompt(self, prefix: impl Into<String>) -> Self

Prepend text to the system prompt

Source

pub fn with_locale(self, locale: Option<&str>) -> Self

Prepend locale instructions for session-aware localization.

Source

pub fn model(self, model: impl Into<String>) -> Self

Set the model

Source

pub fn tool(self, tool: ToolDefinition) -> Self

Add a tool

Source

pub fn tools(self, tools: impl IntoIterator<Item = ToolDefinition>) -> Self

Add multiple tools

Source

pub fn max_iterations(self, max: usize) -> Self

Set maximum iterations

Source

pub fn network_access(self, network_access: Option<NetworkAccessList>) -> Self

Set the merged network access list.

Source

pub fn temperature(self, temp: f32) -> Self

Set temperature

Source

pub fn max_tokens(self, tokens: u32) -> Self

Set max tokens

Set tool_search configuration

Source

pub fn prompt_cache(self, config: PromptCacheConfig) -> Self

Set prompt caching configuration

Source

pub fn build(self) -> RuntimeAgent

Build the runtime agent.

Validates that tool_search is only enabled for models that support it (currently GPT-5.4 and newer). Clears tool_search for unsupported models to prevent 400 errors from the OpenAI API.

tool_search is capability-driven: it is only set when the openai_tool_search capability is explicitly added to the agent or harness. This method does NOT auto-enable it.

Trait Implementations§

Source§

impl Default for RuntimeAgentBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FutureExt for T

Source§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
Source§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoRequest<T> for T

Source§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
Source§

impl<L> LayerExt<L> for L

Source§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in Layered.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more