1use std::sync::Arc;
58
59use serde_json::Value;
60use tokio::sync::mpsc;
61
62use crate::error::{Result, RustyError};
63use crate::executor::GraphEvent;
64use crate::graph::{Graph, GraphBuilder, Route};
65use crate::journal::{Journal, PARENT_EVENT_KEY};
66use crate::llm::{ChatMessage, ChatModel};
67use crate::node::NodeOutput;
68use crate::replay::{
69 RecordingChatModel, RecordingTool, ReplaySource, ReplayingChatModel, ReplayingTool,
70};
71use crate::tool::{ToolExecutor, ToolRegistry};
72
73pub const MESSAGES_CHANNEL: &str = "messages";
76
77pub const AGENT_NODE: &str = "agent";
79
80pub const TOOLS_NODE: &str = "tools";
82
83fn read_messages(state: &crate::state::State) -> Result<Vec<ChatMessage>> {
88 Ok(state
89 .get_as::<Vec<ChatMessage>>(MESSAGES_CHANNEL)?
90 .unwrap_or_default())
91}
92
93#[derive(Debug, Clone)]
97enum EvidenceMode {
98 None,
101
102 Record(Journal),
104
105 Replay {
108 source: ReplaySource,
110 journal: Journal,
112 },
113}
114
115fn invocation_parent(ctx: &crate::node::NodeContext, node: &str) -> Result<String> {
123 ctx.config()
124 .extra
125 .get(PARENT_EVENT_KEY)
126 .and_then(Value::as_str)
127 .map(str::to_owned)
128 .ok_or_else(|| {
129 RustyError::Node(format!(
130 "node `{node}` is wired for Flight Recorder evidence but the run supplied no \
131 `{PARENT_EVENT_KEY}` — drive the graph through `Executor::run`, which hands each \
132 invocation its node-input event id as the causal parent"
133 ))
134 })
135}
136
137fn sorted_tool_schemas(tools: &ToolRegistry) -> Vec<Value> {
147 fn tool_name(schema: &Value) -> &str {
148 schema
149 .pointer("/function/name")
150 .and_then(Value::as_str)
151 .unwrap_or("")
152 }
153 let mut schemas = tools.schemas();
154 schemas.sort_by(|a, b| tool_name(a).cmp(tool_name(b)));
155 schemas
156}
157
158pub fn create_react_agent(model: Arc<dyn ChatModel>, tools: ToolRegistry) -> Result<Graph> {
172 build_react_agent(model, tools, None, EvidenceMode::None)
173}
174
175pub fn create_react_agent_streaming(
190 model: Arc<dyn ChatModel>,
191 tools: ToolRegistry,
192 token_tx: mpsc::Sender<GraphEvent>,
193) -> Result<Graph> {
194 build_react_agent(model, tools, Some(token_tx), EvidenceMode::None)
195}
196
197pub fn create_react_agent_with_recording(
221 model: Arc<dyn ChatModel>,
222 tools: ToolRegistry,
223 journal: Journal,
224) -> Result<Graph> {
225 build_react_agent(model, tools, None, EvidenceMode::Record(journal))
226}
227
228pub fn create_react_agent_replaying(
247 model: Arc<dyn ChatModel>,
248 tools: ToolRegistry,
249 source: ReplaySource,
250 journal: Journal,
251) -> Result<Graph> {
252 build_react_agent(model, tools, None, EvidenceMode::Replay { source, journal })
253}
254
255fn build_react_agent(
256 model: Arc<dyn ChatModel>,
257 tools: ToolRegistry,
258 token_tx: Option<mpsc::Sender<GraphEvent>>,
259 evidence: EvidenceMode,
260) -> Result<Graph> {
261 let tool_schemas = sorted_tool_schemas(&tools);
262 let tool_executor = ToolExecutor::new(tools);
263
264 let agent_node = {
265 let model = Arc::clone(&model);
266 let evidence = evidence.clone();
267 move |ctx: crate::node::NodeContext| {
268 let model = Arc::clone(&model);
269 let evidence = evidence.clone();
270 let tool_schemas = tool_schemas.clone();
271 let token_tx = token_tx.clone();
272 async move {
273 let messages = read_messages(ctx.state())?;
274 let model: Arc<dyn ChatModel> = match &evidence {
278 EvidenceMode::None => model,
279 EvidenceMode::Record(journal) => Arc::new(
280 RecordingChatModel::new(
281 model,
282 journal.clone(),
283 invocation_parent(&ctx, AGENT_NODE)?,
284 )
285 .node(AGENT_NODE),
286 ),
287 EvidenceMode::Replay { source, journal } => Arc::new(ReplayingChatModel::new(
288 model,
289 source.clone(),
290 journal.clone(),
291 invocation_parent(&ctx, AGENT_NODE)?,
292 )),
293 };
294 tracing::debug!(
295 node = AGENT_NODE,
296 messages = messages.len(),
297 tools = tool_schemas.len(),
298 "calling chat model"
299 );
300 let response = match token_tx {
301 Some(tx) => {
302 model
303 .chat_stream(&messages, &tool_schemas, &mut |chunk| {
304 if !chunk.delta.is_empty() {
305 let _ = tx.try_send(GraphEvent::Token {
306 node: AGENT_NODE.to_owned(),
307 delta: chunk.delta,
308 });
309 }
310 })
311 .await?
312 }
313 None => model.chat(&messages, &tool_schemas).await?,
314 };
315 let appended = serde_json::to_value(&response.message)?;
316 Ok(NodeOutput::update(MESSAGES_CHANNEL, appended))
319 }
320 }
321 };
322
323 let tools_node = move |ctx: crate::node::NodeContext| {
324 let tool_executor = tool_executor.clone();
325 let evidence = evidence.clone();
326 async move {
327 let messages = read_messages(ctx.state())?;
328 let last = messages.last().ok_or_else(|| {
329 RustyError::Node(format!(
330 "node `{TOOLS_NODE}` ran with an empty `{MESSAGES_CHANNEL}` channel"
331 ))
332 })?;
333 if !last.has_tool_calls() {
334 return Err(RustyError::Node(format!(
335 "node `{TOOLS_NODE}` expected the last message to carry tool calls"
336 )));
337 }
338 let tool_names: Vec<&str> = last
339 .tool_calls
340 .iter()
341 .map(|call| call.name.as_str())
342 .collect();
343 tracing::debug!(
344 node = TOOLS_NODE,
345 calls = last.tool_calls.len(),
346 tools = ?tool_names,
347 "dispatching tool calls"
348 );
349 let mut tool_executor =
354 match &evidence {
355 EvidenceMode::None => tool_executor,
356 EvidenceMode::Record(journal) => {
357 let parent = invocation_parent(&ctx, TOOLS_NODE)?;
358 let mut wrapped = ToolRegistry::new();
359 for name in tool_executor.registry().names() {
360 let tool = tool_executor.registry().get(name).expect(
361 "tool names iterated from a registry resolve in that registry",
362 );
363 wrapped.register_shared(Arc::new(
364 RecordingTool::new(tool, journal.clone(), parent.clone())
365 .node(TOOLS_NODE),
366 ));
367 }
368 ToolExecutor::new(wrapped)
369 }
370 EvidenceMode::Replay { source, journal } => {
371 let parent = invocation_parent(&ctx, TOOLS_NODE)?;
372 let mut wrapped = ToolRegistry::new();
373 for name in tool_executor.registry().names() {
374 let tool = tool_executor.registry().get(name).expect(
375 "tool names iterated from a registry resolve in that registry",
376 );
377 wrapped.register_shared(Arc::new(ReplayingTool::new(
378 tool,
379 source.clone(),
380 journal.clone(),
381 parent.clone(),
382 )));
383 }
384 ToolExecutor::new(wrapped)
385 }
386 };
387 tool_executor = tool_executor
392 .with_middleware(ctx.middleware().clone())
393 .with_call_context(ctx.thread_id(), TOOLS_NODE);
394 if let Some(admission) = ctx.effect_admission() {
395 tool_executor = tool_executor.with_effect_admission(admission.clone());
396 }
397 let results = tool_executor.execute_batch(&last.tool_calls).await;
399 let appended = serde_json::to_value(&results)?;
400 Ok(NodeOutput::update(MESSAGES_CHANNEL, appended))
401 }
402 };
403
404 let mut builder = GraphBuilder::new();
405 builder.add_node(AGENT_NODE, agent_node);
406 builder.add_node(TOOLS_NODE, tools_node);
407 builder.set_entry_point(AGENT_NODE);
408
409 builder.add_conditional_edges(AGENT_NODE, |state| async move {
411 let needs_tools = read_messages(&state)?
412 .last()
413 .map(ChatMessage::has_tool_calls)
414 .unwrap_or(false);
415 Ok(if needs_tools {
416 Route::Node(TOOLS_NODE.to_owned())
417 } else {
418 Route::End
419 })
420 });
421 builder.add_edge(TOOLS_NODE, AGENT_NODE);
422
423 builder.compile()
424}
425
426#[cfg(test)]
427mod tests {
428 use super::*;
429 use crate::graph::Edge;
430 use crate::llm::{ChatResponse, TokenChunk, ToolCall};
431 use crate::node::{Node, NodeConfig, NodeContext};
432 use crate::state::{Reducer, State, StateSpec};
433 use crate::tool::Tool;
434 use async_trait::async_trait;
435 use serde_json::{json, Value};
436 use std::collections::VecDeque;
437 use std::sync::Mutex;
438
439 struct ScriptedModel {
441 script: Mutex<VecDeque<ChatMessage>>,
442 seen_tool_schemas: Mutex<Vec<usize>>,
443 }
444
445 impl ScriptedModel {
446 fn new(script: Vec<ChatMessage>) -> Self {
447 Self {
448 script: Mutex::new(script.into()),
449 seen_tool_schemas: Mutex::new(Vec::new()),
450 }
451 }
452 }
453
454 #[async_trait]
455 impl ChatModel for ScriptedModel {
456 async fn chat(&self, _messages: &[ChatMessage], tools: &[Value]) -> Result<ChatResponse> {
457 self.seen_tool_schemas.lock().unwrap().push(tools.len());
458 let message = self
459 .script
460 .lock()
461 .unwrap()
462 .pop_front()
463 .ok_or_else(|| RustyError::Llm("script exhausted".into()))?;
464 Ok(ChatResponse {
465 message,
466 model: None,
467 usage: None,
468 })
469 }
470 }
471
472 struct StreamingModel;
475
476 #[async_trait]
477 impl ChatModel for StreamingModel {
478 async fn chat(&self, _messages: &[ChatMessage], _tools: &[Value]) -> Result<ChatResponse> {
479 Ok(ChatResponse {
480 message: ChatMessage::assistant("streamed"),
481 model: None,
482 usage: None,
483 })
484 }
485 async fn chat_stream(
486 &self,
487 messages: &[ChatMessage],
488 tools: &[Value],
489 on_token: &mut (dyn FnMut(TokenChunk) + Send),
490 ) -> Result<ChatResponse> {
491 for delta in ["str", "eamed"] {
492 on_token(TokenChunk {
493 delta: delta.to_owned(),
494 finish: false,
495 raw: None,
496 });
497 }
498 self.chat(messages, tools).await
499 }
500 }
501
502 #[tokio::test]
503 async fn streaming_variant_forwards_token_events() {
504 let (tx, mut rx) = mpsc::channel::<GraphEvent>(8);
505 let model: Arc<dyn ChatModel> = Arc::new(StreamingModel);
506 let graph = create_react_agent_streaming(model, registry(), tx).unwrap();
507
508 let state = State::from_value(json!({
509 MESSAGES_CHANNEL: [serde_json::to_value(ChatMessage::user("hi")).unwrap()]
510 }))
511 .unwrap();
512 let ctx = NodeContext::new(state, NodeConfig::default());
513 let out = graph.node(AGENT_NODE).unwrap().run(ctx).await.unwrap();
514
515 let appended = out.updates.get(MESSAGES_CHANNEL).unwrap();
517 let msg: ChatMessage = serde_json::from_value(appended.clone()).unwrap();
518 assert_eq!(msg.content.as_deref(), Some("streamed"));
519
520 let mut deltas = String::new();
522 for _ in 0..2 {
523 match rx.try_recv().expect("two token events") {
524 GraphEvent::Token { node, delta } => {
525 assert_eq!(node, AGENT_NODE);
526 deltas.push_str(&delta);
527 }
528 other => panic!("expected Token event, got {other:?}"),
529 }
530 }
531 assert_eq!(deltas, "streamed");
532 }
533
534 #[tokio::test]
536 async fn non_streaming_variant_emits_no_token_events() {
537 let model: Arc<dyn ChatModel> =
538 Arc::new(ScriptedModel::new(vec![ChatMessage::assistant("done")]));
539 let graph = create_react_agent(model, registry()).unwrap();
540 assert!(graph.has_node(AGENT_NODE));
544 }
545
546 struct Echo;
547
548 #[async_trait]
549 impl Tool for Echo {
550 fn name(&self) -> &str {
551 "echo"
552 }
553 fn description(&self) -> &str {
554 "Echoes its input."
555 }
556 fn parameters_schema(&self) -> Value {
557 json!({"type": "object", "properties": {"text": {"type": "string"}}})
558 }
559 async fn call(&self, args: Value) -> Result<Value> {
560 Ok(json!(args.get("text").cloned().unwrap_or(Value::Null)))
561 }
562 }
563
564 fn registry() -> ToolRegistry {
565 let mut r = ToolRegistry::new();
566 r.register(Echo);
567 r
568 }
569
570 #[test]
571 fn graph_topology_is_the_react_loop() {
572 let model: Arc<dyn ChatModel> = Arc::new(ScriptedModel::new(vec![]));
573 let graph = create_react_agent(model, registry()).unwrap();
574
575 assert_eq!(graph.node_count(), 2);
576 assert_eq!(graph.entry_point(), AGENT_NODE);
577 assert!(graph.has_node(AGENT_NODE));
578 assert!(graph.has_node(TOOLS_NODE));
579
580 let agent_edges = graph.outgoing_edges(AGENT_NODE);
582 assert_eq!(agent_edges.len(), 1);
583 assert!(matches!(agent_edges[0], Edge::Conditional { .. }));
584 let tools_edges = graph.outgoing_edges(TOOLS_NODE);
585 assert_eq!(tools_edges.len(), 1);
586 assert!(matches!(
587 tools_edges[0],
588 Edge::Direct { from, to } if from == TOOLS_NODE && to == AGENT_NODE
589 ));
590 }
591
592 #[tokio::test]
593 async fn agent_node_appends_assistant_message_and_sees_schemas() {
594 let model = Arc::new(ScriptedModel::new(vec![ChatMessage::assistant("done")]));
595 let graph = create_react_agent(model.clone(), registry()).unwrap();
596
597 let state = State::from_value(json!({
598 MESSAGES_CHANNEL: [serde_json::to_value(ChatMessage::user("hi")).unwrap()]
599 }))
600 .unwrap();
601 let ctx = NodeContext::new(state, NodeConfig::default());
602 let out = graph.node(AGENT_NODE).unwrap().run(ctx).await.unwrap();
603
604 let appended = out.updates.get(MESSAGES_CHANNEL).unwrap();
605 let msg: ChatMessage = serde_json::from_value(appended.clone()).unwrap();
606 assert_eq!(msg.content.as_deref(), Some("done"));
607
608 assert_eq!(model.seen_tool_schemas.lock().unwrap().as_slice(), &[1]);
610 }
611
612 #[tokio::test]
613 async fn tools_node_executes_pending_calls_in_order() {
614 let model: Arc<dyn ChatModel> = Arc::new(ScriptedModel::new(vec![]));
615 let graph = create_react_agent(model, registry()).unwrap();
616
617 let calls = vec![
618 ToolCall::new("c1", "echo", json!({"text": "a"})),
619 ToolCall::new("c2", "echo", json!({"text": "b"})),
620 ];
621 let state = State::from_value(json!({
622 MESSAGES_CHANNEL: [
623 serde_json::to_value(ChatMessage::assistant_tool_calls(calls)).unwrap()
624 ]
625 }))
626 .unwrap();
627 let ctx = NodeContext::new(state, NodeConfig::default());
628 let out = graph.node(TOOLS_NODE).unwrap().run(ctx).await.unwrap();
629
630 let appended = out.updates.get(MESSAGES_CHANNEL).unwrap();
631 let msgs: Vec<ChatMessage> = serde_json::from_value(appended.clone()).unwrap();
632 assert_eq!(msgs.len(), 2);
633 assert_eq!(msgs[0].tool_call_id.as_deref(), Some("c1"));
634 assert_eq!(msgs[0].content.as_deref(), Some("a"));
635 assert_eq!(msgs[1].tool_call_id.as_deref(), Some("c2"));
636 assert_eq!(msgs[1].content.as_deref(), Some("b"));
637 }
638
639 #[tokio::test]
640 async fn router_follows_tool_calls_else_ends() {
641 let model: Arc<dyn ChatModel> = Arc::new(ScriptedModel::new(vec![]));
642 let graph = create_react_agent(model, registry()).unwrap();
643 let edges = graph.outgoing_edges(AGENT_NODE);
644 let router = match edges[0] {
645 Edge::Conditional { router, .. } => router,
646 _ => panic!("expected conditional edge"),
647 };
648
649 let with_calls = State::from_value(json!({
650 MESSAGES_CHANNEL: [serde_json::to_value(ChatMessage::assistant_tool_calls(vec![
651 ToolCall::new("c1", "echo", json!({"text": "x"})),
652 ]))
653 .unwrap()]
654 }))
655 .unwrap();
656 assert_eq!(
657 router(with_calls).await.unwrap(),
658 Route::Node(TOOLS_NODE.to_owned())
659 );
660
661 let final_answer = State::from_value(json!({
662 MESSAGES_CHANNEL: [serde_json::to_value(ChatMessage::assistant("42")).unwrap()]
663 }))
664 .unwrap();
665 assert_eq!(router(final_answer).await.unwrap(), Route::End);
666 }
667
668 #[tokio::test]
672 async fn manual_super_steps_reproduce_the_react_loop() {
673 let model: Arc<dyn ChatModel> = Arc::new(ScriptedModel::new(vec![
674 ChatMessage::assistant_tool_calls(vec![ToolCall::new(
675 "c1",
676 "echo",
677 json!({"text": "hello"}),
678 )]),
679 ChatMessage::assistant("echoed: hello"),
680 ]));
681 let graph = create_react_agent(model, registry()).unwrap();
682 let spec = StateSpec::new().channel(MESSAGES_CHANNEL, Reducer::AddMessages);
683 let mut state = State::from_value(json!({
684 MESSAGES_CHANNEL: [serde_json::to_value(ChatMessage::user("say hello")).unwrap()]
685 }))
686 .unwrap();
687
688 let out = graph
690 .node(AGENT_NODE)
691 .unwrap()
692 .run(NodeContext::new(state.clone(), NodeConfig::default()))
693 .await
694 .unwrap();
695 spec.apply_single(&mut state, AGENT_NODE, out.updates)
696 .unwrap();
697
698 let edges = graph.outgoing_edges(AGENT_NODE);
700 let route = match edges[0] {
701 Edge::Conditional { router, .. } => router(state.clone()).await.unwrap(),
702 _ => unreachable!(),
703 };
704 assert_eq!(route, Route::Node(TOOLS_NODE.to_owned()));
705
706 let out = graph
708 .node(TOOLS_NODE)
709 .unwrap()
710 .run(NodeContext::new(state.clone(), NodeConfig::default()))
711 .await
712 .unwrap();
713 spec.apply_single(&mut state, TOOLS_NODE, out.updates)
714 .unwrap();
715
716 let out = graph
718 .node(AGENT_NODE)
719 .unwrap()
720 .run(NodeContext::new(state.clone(), NodeConfig::default()))
721 .await
722 .unwrap();
723 spec.apply_single(&mut state, AGENT_NODE, out.updates)
724 .unwrap();
725 let route = match edges[0] {
726 Edge::Conditional { router, .. } => router(state.clone()).await.unwrap(),
727 _ => unreachable!(),
728 };
729 assert_eq!(route, Route::End);
730
731 let msgs: Vec<ChatMessage> = state.get_as(MESSAGES_CHANNEL).unwrap().unwrap();
733 assert_eq!(msgs.len(), 4);
734 assert_eq!(msgs[3].content.as_deref(), Some("echoed: hello"));
735 }
736
737 use crate::journal::{Clock, Journal};
740 use crate::replay::ReplaySource;
741
742 fn recording_journal() -> Journal {
743 Journal::new("run-react-test", "thread-react-test", Clock::System)
744 }
745
746 #[test]
747 fn recording_and_replaying_variants_share_the_react_topology() {
748 let model: Arc<dyn ChatModel> = Arc::new(ScriptedModel::new(vec![]));
749 let journal = recording_journal();
750 let source = ReplaySource::new(&journal.snapshot());
751 let recording =
752 create_react_agent_with_recording(model.clone(), registry(), journal.clone()).unwrap();
753 let replaying =
754 create_react_agent_replaying(model.clone(), registry(), source, journal).unwrap();
755
756 for graph in [recording, replaying] {
757 assert_eq!(graph.node_count(), 2);
758 assert_eq!(graph.entry_point(), AGENT_NODE);
759 let agent_edges = graph.outgoing_edges(AGENT_NODE);
760 assert_eq!(agent_edges.len(), 1);
761 assert!(matches!(agent_edges[0], Edge::Conditional { .. }));
762 let tools_edges = graph.outgoing_edges(TOOLS_NODE);
763 assert_eq!(tools_edges.len(), 1);
764 assert!(matches!(
765 tools_edges[0],
766 Edge::Direct { from, to } if from == TOOLS_NODE && to == AGENT_NODE
767 ));
768 }
769 }
770
771 #[tokio::test]
775 async fn recording_nodes_error_without_the_executor_parent_event() {
776 let model: Arc<dyn ChatModel> =
777 Arc::new(ScriptedModel::new(vec![ChatMessage::assistant("done")]));
778 let graph =
779 create_react_agent_with_recording(model, registry(), recording_journal()).unwrap();
780
781 let state = State::from_value(json!({
782 MESSAGES_CHANNEL: [serde_json::to_value(ChatMessage::user("hi")).unwrap()]
783 }))
784 .unwrap();
785 let err = graph
786 .node(AGENT_NODE)
787 .unwrap()
788 .run(NodeContext::new(state, NodeConfig::default()))
789 .await
790 .unwrap_err();
791 let message = err.to_string();
792 assert!(matches!(err, RustyError::Node(_)), "got: {message}");
793 assert!(message.contains(PARENT_EVENT_KEY), "got: {message}");
794
795 let state = State::from_value(json!({
797 MESSAGES_CHANNEL: [serde_json::to_value(ChatMessage::assistant_tool_calls(vec![
798 ToolCall::new("c1", "echo", json!({"text": "x"})),
799 ]))
800 .unwrap()]
801 }))
802 .unwrap();
803 let err = graph
804 .node(TOOLS_NODE)
805 .unwrap()
806 .run(NodeContext::new(state, NodeConfig::default()))
807 .await
808 .unwrap_err();
809 assert!(err.to_string().contains(PARENT_EVENT_KEY), "got: {err}");
810 }
811
812 struct SchemaRecorder {
814 seen: Mutex<Vec<String>>,
815 }
816
817 #[async_trait]
818 impl ChatModel for SchemaRecorder {
819 async fn chat(&self, _messages: &[ChatMessage], tools: &[Value]) -> Result<ChatResponse> {
820 *self.seen.lock().unwrap() = tools
821 .iter()
822 .map(|schema| {
823 schema
824 .pointer("/function/name")
825 .and_then(Value::as_str)
826 .unwrap_or("")
827 .to_owned()
828 })
829 .collect();
830 Ok(ChatResponse {
831 message: ChatMessage::assistant("done"),
832 model: None,
833 usage: None,
834 })
835 }
836 }
837
838 struct Zeta;
839
840 #[async_trait]
841 impl Tool for Zeta {
842 fn name(&self) -> &str {
843 "zeta"
844 }
845 fn description(&self) -> &str {
846 "Alphabetically after echo."
847 }
848 fn parameters_schema(&self) -> Value {
849 json!({"type": "object"})
850 }
851 async fn call(&self, _args: Value) -> Result<Value> {
852 Ok(Value::Null)
853 }
854 }
855
856 #[tokio::test]
861 async fn tool_schemas_reach_the_model_in_canonical_name_order() {
862 let model = Arc::new(SchemaRecorder {
863 seen: Mutex::new(Vec::new()),
864 });
865
866 let mut forward = ToolRegistry::new();
868 forward.register(Echo);
869 forward.register(Zeta);
870 let mut reverse = ToolRegistry::new();
871 reverse.register(Zeta);
872 reverse.register(Echo);
873
874 for registry in [forward, reverse] {
875 let graph = create_react_agent(model.clone(), registry).unwrap();
876 let state = State::from_value(json!({
877 MESSAGES_CHANNEL: [serde_json::to_value(ChatMessage::user("hi")).unwrap()]
878 }))
879 .unwrap();
880 graph
881 .node(AGENT_NODE)
882 .unwrap()
883 .run(NodeContext::new(state, NodeConfig::default()))
884 .await
885 .unwrap();
886 assert_eq!(model.seen.lock().unwrap().as_slice(), ["echo", "zeta"]);
887 }
888 }
889}