Streaming
Demonstrates streaming agent responses token by token.
1"""2Streaming3=============================45Demonstrates streaming agent responses token by token.6"""78from kern.agent import Agent9from kern.models.openai import OpenAIResponses1011# ---------------------------------------------------------------------------12# Create Agent13# ---------------------------------------------------------------------------14agent = Agent(15 model=OpenAIResponses(id="gpt-5.2"),16 markdown=True,17)1819# ---------------------------------------------------------------------------20# Run Agent21# ---------------------------------------------------------------------------22if __name__ == "__main__":23 # Stream the response token by token24 agent.print_response(25 "Explain the difference between concurrency and parallelism.",26 stream=True,27 )Run the Example
1# Clone and setup repo2git clone https://github.com/kern-ai/kern.git3cd kern/cookbook/02_agents/02_input_output45# Create and activate virtual environment6./scripts/demo_setup.sh7source .venvs/demo/bin/activate89python streaming.py