{messages.map(message => (
{message.role}: {message.parts.map((part, i) =>
part.type === 'text' ? {part.text} : null
)}
))}
);
}
```
See `examples/007_vercel_streaming.py` for a complete working example.
## Understanding Execution Events
ExecutionEvent objects provide detailed information about the agent's execution:
```python theme={null}
from tyler import EventType
async for event in agent.stream(thread):
if event.type == EventType.LLM_STREAM_CHUNK:
# Text being generated
print(event.data.get("content_chunk", ""), end="", flush=True)
elif event.type == EventType.TOOL_SELECTED:
# Tool is about to be called
print(f"\n🔧 Calling tool: {event.data['tool_name']}")
elif event.type == EventType.MESSAGE_CREATED:
# New message added to thread
msg = event.data["message"]
if msg.role == "tool":
print(f"\n✅ Tool {msg.name} completed")
elif event.type == EventType.EXECUTION_COMPLETE:
# All processing complete
print(f"\n✅ Complete in {event.data['duration_ms']:.0f}ms!")
```
## Thinking Tokens (Reasoning Content)