1
Create the agent
agent_streaming.py
2
Install dependencies
3
Export your API key
4
Run
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
Stream agent responses token by token in real time.
Create the agent
from definable.agent import Agent
agent = Agent(
model="gpt-4o",
instructions="You are a storyteller. Write vivid, engaging stories.",
)
# Sync streaming
for event in agent.run_stream("Tell me a story about a robot discovering art."):
if event.event == "RunContent" and event.content:
print(event.content, end="", flush=True)
elif event.event == "ToolCallStarted":
print(f"\n> Calling {event.tool.tool_name}...")
elif event.event == "RunCompleted":
print(f"\n\nTokens: {event.metrics.total_tokens}")
Install dependencies
pip install definable
uv pip install definable
poetry add definable
Export your API key
export OPENAI_API_KEY=sk-***
setx OPENAI_API_KEY sk-***
Run
python agent_streaming.py
import asyncio
from definable.agent import Agent
agent = Agent(model="gpt-4o", instructions="You are a helpful assistant.")
async def main():
async for event in agent.arun_stream("Explain quantum computing."):
if event.event == "RunContent" and event.content:
print(event.content, end="", flush=True)
asyncio.run(main())