Skip to content

Commit 6ac00e3

Browse files
declan-scaleclaude
andcommitted
fix(langgraph): sync tutorial span output stores final text, not usage [greptile]
The sync harness_langgraph tutorial set turn_span.output to {"final_output": turn.usage().model_dump()} — token metrics under a key that means the assistant's text, producing misleading AGENT_WORKFLOW trace data versus the async tutorial. Accumulate text deltas during the yield loop (as the 030_langgraph tutorial does) and store {"final_output": final_text, "usage": ...} so the final output is the text and usage stays available under its own key. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8ba11bd commit 6ac00e3

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

  • examples/tutorials/00_sync/harness_langgraph/project

examples/tutorials/00_sync/harness_langgraph/project/acp.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
from agentex.lib.utils.logging import make_logger
3434
from agentex.lib.sdk.fastacp.fastacp import FastACP
3535
from agentex.lib.core.harness.emitter import UnifiedEmitter
36+
from agentex.types.task_message_delta import TextDelta
3637
from agentex.types.task_message_update import TaskMessageUpdate
3738
from agentex.types.task_message_content import TaskMessageContent
3839
from agentex.lib.adk._modules._langgraph_turn import LangGraphTurn
@@ -93,8 +94,14 @@ async def handle_message_send(
9394
parent_span_id=turn_span.id if turn_span else None,
9495
)
9596

97+
final_text = ""
9698
async for event in emitter.yield_turn(turn):
99+
# Accumulate text deltas so the span's final_output is the assistant
100+
# text (matching the async tutorial), not the usage metrics.
101+
delta = getattr(event, "delta", None)
102+
if isinstance(delta, TextDelta) and delta.text_delta:
103+
final_text += delta.text_delta
97104
yield event
98105

99106
if turn_span:
100-
turn_span.output = {"final_output": turn.usage().model_dump()}
107+
turn_span.output = {"final_output": final_text, "usage": turn.usage().model_dump()}

0 commit comments

Comments
 (0)