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:
- Streaming via
Agent::run_with_channel, translating the engine’sAgentEventstream into protocol events (stream_token,stream_chunk,eventual_response). - 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::newrandomizes 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§
- Confirmation
Config - Hooks the runner needs to wire write-confirmation HITL into a turn
without depending on
AppStatedirectly (keeps the runner unit-testable). - Turn
Request - Everything one streaming turn needs. Bundled into a struct so the call sites
(the reference server’s
handle_send_messageand the lambda’ssend_message) stay readable and the security-criticalaccessfield can never be silently dropped from a positional argument list. - Turn
Result - The terminal outcome of a streamed turn.
- Workflow
Turn - 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’seventual_responsecarries. The reference runtime doesn’t produce the full structured analytics, so we surface the reply text inresponsePartsand supply neutral defaults for the analytic fields (clients renderresponseParts). - run_
streaming_ turn - Runs one knowledge-grounded, streaming turn for a session’s conversation and
emits protocol-shaped events through
sinkas they happen.
Type Aliases§
- Clear
Confirmation - Clears any registered confirmation sender for a session id when its turn ends.
Typically
AppState::clear_confirmation. - Register
Confirmation - Registers a parked turn’s
HumanResponsesender under a session id (so a laterconfirm_tool_actioncan take it). TypicallyAppState::register_confirmation.