Skip to main content

Module runner

Module runner 

Source
Expand description

The streaming, memory-carrying agent runner used by the WS service.

smooth-operator’s [KnowledgeChatRuntime] proves the engine ↔ gateway path but (a) is non-streaming (run_turn returns only after the turn completes) and (b) has no cross-turn memory — each run_turn builds a fresh Agent with a random id and no prior messages, so turn 2 forgets turn 1 (documented in core/tests/e2e_llm_smoo_ai.rs).

The service needs both, so this module builds the agent itself, wiring the same knowledge-grounding as core PLUS:

  1. Streaming via Agent::run_with_channel, translating the engine’s AgentEvent stream into protocol events (stream_token, stream_chunk, eventual_response).
  2. Per-session memory via AgentConfig::with_prior_messages: before each turn the session’s persisted message log is loaded from the storage adapter and replayed into the conversation, so the model sees turn 1 when answering turn 2. (Agent::new randomizes the agent id every time, so the checkpoint-resume path can’t be keyed stably — replaying the persisted log is the robust, backend-agnostic way to carry memory. The log is the source of truth the adapter already persists.)

Structs§

ConfirmationConfig
Hooks the runner needs to wire write-confirmation HITL into a turn without depending on AppState directly (keeps the runner unit-testable).
TurnRequest
Everything one streaming turn needs. Bundled into a struct so the call sites (the reference server’s handle_send_message and the lambda’s send_message) stay readable and the security-critical access field can never be silently dropped from a positional argument list.
TurnResult
The terminal outcome of a streamed turn.
WorkflowTurn
A turn’s conversation-workflow context: the agent’s configured workflow plus the step the conversation is currently on. When present on a TurnRequest, the runner injects the current step’s intent/criteria into the system prompt and, after the turn, runs the judge to decide whether to advance. None (the default) means the agent runs freeform — no workflow section, no judge, byte-for-byte unchanged.

Functions§

general_agent_response
Build the structured GeneralAgentResponse-shaped payload the protocol’s eventual_response carries. The reference runtime doesn’t produce the full structured analytics, so we surface the reply text in responseParts and supply neutral defaults for the analytic fields (clients render responseParts).
run_streaming_turn
Runs one knowledge-grounded, streaming turn for a session’s conversation and emits protocol-shaped events through sink as they happen.

Type Aliases§

ClearConfirmation
Clears any registered confirmation sender for a session id when its turn ends. Typically AppState::clear_confirmation.
RegisterConfirmation
Registers a parked turn’s HumanResponse sender under a session id (so a later confirm_tool_action can take it). Typically AppState::register_confirmation.