Commit fd518ff
committed
fix(agent): filter AIMessage state updates from streaming output
LangGraph's stream_mode="messages" emits both AIMessageChunk (incremental
tokens) and AIMessage (final state update) from the agent node. The
_stream_fn was accepting both via isinstance(msg, (AIMessage, AIMessageChunk)),
causing the full accumulated response to be emitted as a final chunk after
all the individual tokens had already been streamed. Clients saw the
complete response duplicated at the end of the SSE stream.
Filter to only AIMessageChunk so the state update is excluded.
Adds a regression test that confirms AIMessage objects are emitted by the
graph stream (the duplicate source) and that filtering to AIMessageChunk
excludes them.
Signed-off-by: Myles Shannon <mshannon@nvidia.com>1 parent ee7ab31 commit fd518ff
2 files changed
Lines changed: 41 additions & 2 deletions
File tree
- packages/nvidia_nat_langchain
- src/nat/plugins/langchain/agent/tool_calling_agent
- tests/agent
Lines changed: 1 addition & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
105 | 104 | | |
106 | 105 | | |
107 | 106 | | |
| |||
219 | 218 | | |
220 | 219 | | |
221 | 220 | | |
222 | | - | |
| 221 | + | |
223 | 222 | | |
224 | 223 | | |
225 | 224 | | |
| |||
Lines changed: 40 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
367 | 367 | | |
368 | 368 | | |
369 | 369 | | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
370 | 410 | | |
371 | 411 | | |
372 | 412 | | |
| |||
0 commit comments