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
impl InProcessAgentRunner
Sourcepub fn new(
llm: Arc<dyn InferenceAdapter>,
registry_factory: Arc<dyn RegistryFactory>,
config_dir: impl Into<PathBuf>,
) -> Self
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.
Sourcepub fn with_tool_event_sink(self, sink: Arc<dyn ToolEventSink>) -> Self
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.
Sourcepub fn with_cancel_flag(self, cancel: Arc<AtomicBool>) -> Self
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.
Sourcepub fn with_mode(self, mode: HarnessMode) -> Self
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.
Sourcepub fn with_project_context(self, context: impl Into<String>) -> Self
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).
Sourcepub fn with_skills_catalog(self, catalog: impl Into<String>) -> Self
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.
Sourcepub fn with_config(self, config: InProcessRunnerConfig) -> Self
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.
Sourcepub fn with_timeout_secs(self, timeout_secs: u64) -> Self
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
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,
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,
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,
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,
Auto Trait Implementations§
impl !RefUnwindSafe for InProcessAgentRunner
impl !UnwindSafe for InProcessAgentRunner
impl Freeze for InProcessAgentRunner
impl Send for InProcessAgentRunner
impl Sync for InProcessAgentRunner
impl Unpin for InProcessAgentRunner
impl UnsafeUnpin for InProcessAgentRunner
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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