mirror of
https://github.com/langchain-ai/docs.git
synced 2026-08-27 02:41:59 -04:00
23 lines
705 B
Plaintext
23 lines
705 B
Plaintext
```python
|
|
for chunk in agent.stream(
|
|
{"messages": [{"role": "user", "content": "Plan my vacation"}]},
|
|
stream_mode="updates",
|
|
subgraphs=True,
|
|
version="v2",
|
|
):
|
|
if chunk["type"] == "updates":
|
|
# Check if this event came from a subagent
|
|
is_subagent = any(
|
|
segment.startswith("tools:") for segment in chunk["ns"]
|
|
)
|
|
|
|
if is_subagent:
|
|
# Extract the tool call ID from the namespace
|
|
tool_call_id = next(
|
|
s.split(":")[1] for s in chunk["ns"] if s.startswith("tools:")
|
|
)
|
|
print(f"Subagent {tool_call_id}: {chunk['data']}")
|
|
else:
|
|
print(f"Main agent: {chunk['data']}")
|
|
```
|