Examples¶
Quick Start¶
The examples/quickstart.py script demonstrates the core workflow:
- Discover available agents with
detect_agents() - Inspect capabilities with
get_agent_capabilities() - Run a task with
Session.run() - Display the result (status, text, tokens, cost)
# Use auto-detected agent
python examples/quickstart.py
# Specify agent
python examples/quickstart.py --agent codex
# Custom prompt
python examples/quickstart.py --agent opencode --prompt "List files"
Streaming¶
The examples/streaming.py script demonstrates real-time event streaming:
- Connect to an agent via
Session - Stream events with
session.stream() - Handle each event type (text deltas, tool calls, usage, errors)
Event Types Demonstrated¶
| Event | Handling |
|---|---|
session_start |
Print session ID and model |
message_delta |
Print text chunks in real time |
message_end |
Print newline |
tool_use |
Print tool name and input |
tool_result |
Print output preview (OK/ERR) |
usage |
Print token counts and cost |
error |
Print error message |
session_end |
Print end marker |