Skip to main content

InProcessAgentRunner

Struct InProcessAgentRunner 

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

Runs a delegated sub-agent in-process by driving its own AgentLoop.

Why: This is the concrete AgentRunner the PM’s delegate_to_agent tool dispatches to in the M1 harness. Running in-process (vs. subprocess) keeps a comparison run a single, observable process and lets the sub-agent’s token usage accrue onto the same shared client the PM uses, so the orchestrator can roll engineer cost up into the PM’s transcript (#1030). What: Holds the shared LLM client, a RegistryFactory, the agents config directory, optional project context, and the default loop budget. For each run, it loads <config_dir>/<agent_name>.md, asks the factory for the agent’s tools, gates them by tools.allowed, resolves the model and assembled system prompt, then runs an AgentLoop and returns its output. Test: runner::tests::* cover the full delegation path offline.

Implementations§

Source§

impl InProcessAgentRunner

Source

pub fn new( llm: Arc<dyn InferenceAdapter>, registry_factory: Arc<dyn RegistryFactory>, config_dir: impl Into<PathBuf>, ) -> Self

Construct a runner from its collaborators.

Why: Constructor injection keeps the runner testable — production passes a real LlmClient and a real registry factory; tests pass a scripted mock client and a closure factory. What: Stores the shared client, the registry factory, the agents config directory, and a default InProcessRunnerConfig. Project context is None until with_project_context is called. Test: runner::tests::delegate_runs_engineer_loop.

Source

pub fn with_permissions(self, ctx: PermissionContext) -> Self

Attach the session-scoped permission context every delegated sub-agent loop this runner drives is gated by (#7948).

Why: this is the one production construction site for a delegated sub-agent’s AgentLoop (run_task and task::executor both delegate through it), so wiring the context here gates every delegation. What: builder-style setter. The gate itself is minted per delegation in run_pipeline, because its map comes from the delegated agent. Test: agent_loop::tests::permission_gate::deny_never_dispatches.

Source

pub fn with_tool_event_sink(self, sink: Arc<dyn ToolEventSink>) -> Self

Attach a ToolEventSink every delegated sub-agent loop this runner drives will notify around its own tool dispatches (#2056).

Why: Makes a delegated sub-agent’s tool activity observable to the same sink the delegating loop uses, without the delegate tool or the PM loop needing to know about it. What: Builder-style setter; returns self for chaining. Test: runner::tests::sink_reaches_delegated_loop.

Source

pub fn with_cancel_flag(self, cancel: Arc<AtomicBool>) -> Self

Attach a cancellation flag every delegated sub-agent loop this runner drives will check (#2056).

Why: Cancelling the delegating (PM) run must also stop an in-flight delegated sub-agent loop, not just the PM’s own turns. What: Builder-style setter; returns self for chaining. Test: runner::tests::cancel_flag_reaches_delegated_loop.

Source

pub fn with_mode(self, mode: HarnessMode) -> Self

Set the resolved HarnessMode every sub-agent AgentLoop this runner drives will use (#2059).

Why: a delegated sub-agent’s prompt/tool-schema assembly must use the SAME resolved mode as its delegator — a daily-driver PM run should not silently delegate to a parity-mode engineer, or vice versa. What: Builder-style setter; returns self for chaining. Test: runner::tests::with_mode_completes_a_delegated_run_in_both_modes.

Source

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

Attach project CLAUDE.md context injected into every assembled prompt.

Why: The parity prompt assembler (#1032) merges verbatim project context as a fixed section; threading it here means every sub-agent the runner drives sees the same project rules the PM does. What: Stores context to pass to assemble_system_prompt. Test: runner::tests::project_context_reaches_prompt (via the system prompt captured by the scripted client).

Source

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

Attach the rendered skill catalog (#2069) injected into every HarnessMode::DailyDriver prompt this runner assembles.

Why: A delegated sub-agent should see the same cheap, metadata-only skill catalog the delegating PM does, without the runner needing to know how the catalog was discovered (the caller renders it via skills::format_skill_catalog and passes the result straight through). What: Builder-style setter; returns self for chaining. Ignored entirely by HarnessMode::Parity at prompt-assembly time. Test: runner::tests::skills_catalog_reaches_daily_driver_prompt, runner::tests::skills_catalog_ignored_in_parity.

Source

pub fn with_work_root(self, work_root: impl Into<PathBuf>) -> Self

Bind the work root the verify-before-finish gate probes for a detectable test suite (#8206).

Why: Without it the gate refused a finish_task on an empty projectless scratch root, where no test command could ever have run — the live #8206 transcript wedged on exactly that refusal. What: The SAME directory the caller scoped this runner’s fs/bash tools to. Unset leaves the gate’s refusal arm unreachable. Test: runner::tests::work_root_reaches_the_finish_gate.

Source

pub fn with_config(self, config: InProcessRunnerConfig) -> Self

Override the default loop budget (turn cap + timeout).

Why: Deployments and tests may want a tighter or looser default than the built-in 40 turns / 120s. What: Replaces self.config. Test: runner::tests::run_context_overrides_max_turns sets a config then overrides it per-call.

Source

pub fn with_timeout_secs(self, timeout_secs: u64) -> Self

Override only the wall-clock timeout of the default loop budget (#2207).

Why: run_task/task::executor resolve a single run-wide deadline (crate::provider::resolve_deadline_secs) that must apply to the delegated engineer’s loop as well as the delegating PM’s own — but they have no reason to touch max_turns. A dedicated setter avoids forcing every call site to reconstruct a whole InProcessRunnerConfig (and risk silently resetting max_turns to its default) just to change one field. What: Builder-style setter; returns self for chaining. Leaves self.config.max_turns untouched. Test: runner::tests::with_timeout_secs_overrides_only_timeout.

Trait Implementations§

Source§

impl AgentRunner for InProcessAgentRunner

Source§

fn run<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, agent_name: &'life1 str, task: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<AgentOutput>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Run task against the named agent with default per-call context.

Why: The simplest entry point the delegate tool calls; no overrides. What: Delegates to run_pipeline with a default RunContext, converting RunnerError into the trait’s anyhow::Error. Test: runner::tests::delegate_runs_engineer_loop.

Source§

fn run_with_context<'life0, 'life1, 'life2, 'life3, 'async_trait>( &'life0 self, agent_name: &'life1 str, task: &'life2 str, ctx: &'life3 RunContext, ) -> Pin<Box<dyn Future<Output = Result<AgentOutput>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait,

Run task against the named agent honouring per-call ctx overrides.

Why: The orchestrator may pin a model, working directory, or turn cap for a single delegation; RunContext carries those without global state. What: Delegates to run_pipeline with the supplied ctx. Test: runner::tests::run_context_overrides_max_turns, runner::tests::run_context_overrides_model.

Source§

fn run_with_history<'life0, 'life1, 'life2, 'life3, 'life4, 'async_trait>( &'life0 self, agent_name: &'life1 str, task: &'life2 str, _history: &'life3 [HistoryMessage], ctx: &'life4 RunContext, ) -> Pin<Box<dyn Future<Output = Result<AgentOutput>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait, 'life3: 'async_trait, 'life4: 'async_trait,

Run a task while forwarding prior session history. 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<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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> 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 = !

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

fn try_from(value: U) -> Result<T, !>

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<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