
Producing Outputs
Formatting the final result for the user.
Producing Outputs
When the graph hits END, graph.invoke() returns the Final State Snapshot.
Identifying the Result
Usually, the state contains a lot of noise (intermediate tool calls, scratchpad thoughts).
result = graph.invoke(inputs)
# The result is the Full State Dict
# {'messages': [Human, AI, Tool, AI], 'scratchpad': 'thought...'}
# Extract what you show the user
final_msg = result["messages"][-1]
print(f"Agent Replied: {final_msg.content}")
Streaming Outputs
For chat apps, use streaming to show progress:
for event in graph.stream(inputs):
# event contains the output of the node that just finished
print(event)