Skip to main content

create_react_agent_streaming

Function create_react_agent_streaming 

Source
pub fn create_react_agent_streaming(
    model: Arc<dyn ChatModel>,
    tools: ToolRegistry,
    token_tx: Sender<GraphEvent>,
) -> Result<Graph>
Expand description

Build a prebuilt ReAct agent graph whose agent node streams token deltas as GraphEvent::Tokens through token_tx (ChatModel::chat_stream under the hood; LangGraph’s messages stream mode).

Typically token_tx is a clone of the run’s event sender (crate::executor::RunConfig::token_tx) so token deltas interleave with the executor’s own events on one channel. Forwarding is best-effort (try_send): a full or closed channel drops tokens but never aborts the run.

Identical to create_react_agent in topology and behavior otherwise; models that only implement ChatModel::chat work unchanged (the trait’s default chat_stream delivers the whole answer as one token).