mirror of
https://github.com/langchain-ai/docs.git
synced 2026-08-27 02:41:59 -04:00
20 lines
606 B
Plaintext
20 lines
606 B
Plaintext
```python
|
|
question = "Which genre on average has the longest tracks?"
|
|
|
|
stream = agent.stream_events(
|
|
{"messages": [{"role": "user", "content": question}]},
|
|
version="v3",
|
|
)
|
|
for kind, item in stream.interleave("messages", "tool_calls"):
|
|
if kind == "messages":
|
|
for token in item.text:
|
|
print(token, end="", flush=True)
|
|
elif kind == "tool_calls":
|
|
print(f"\nTool call: {item.tool_name}({item.input})")
|
|
for delta in item.output_deltas:
|
|
print(delta, end="", flush=True)
|
|
print(f"\nTool result: {item.output}")
|
|
|
|
final_state = stream.output
|
|
```
|