pub async fn spawn_agent<H>(
harness: &H,
spec: AgentRunSpec,
event_sender: ActivityEventSender,
control_receiver: Option<ControlReceiver>,
) -> Result<DispatchOutcome, HarnessError>where
H: AgentHarness,Expand description
Drives one activity attempt through the neutral AgentHarness seam and
returns its terminal DispatchOutcome.
This is the harness-blind trait driver (NOI-4). It:
- starts the harness for
spec(spawn/connect + capability handshake), - concurrently pumps the session’s
AgentSession::eventstoevent_senderand feedscontrol_receivercommands toAgentSession::interveneuntil the event stream ends, then - awaits
AgentSession::wait_resultand maps it intoDispatchOutcome::Completed { output }.
A control_receiver of None runs the session with no intervention channel —
the observability-only shape. When present, a command whose primitive the
session does not advertise is rejected by the session with
HarnessError::CapabilityNotSupported; the driver logs that rejection and
keeps running (a gated command is a normal, non-fatal outcome, not a run
failure).
The event stream ending signals end-of-run: the driver then takes the terminal
result. This is why events must be a distinct channel from the result — the
driver relies on the stream closing (not on inspecting any event) to know the
run is done, and the result arrives only from AgentSession::wait_result.
§Errors
Returns HarnessError when the harness cannot be started or when the
terminal result cannot be received. A harness-reported application failure
(HarnessError::Harness) is returned to the caller, which maps it to a
DispatchOutcome::Failed via harness_error_to_outcome; transport and
protocol faults are surfaced as-is for the caller to classify.