forked from conductor-oss/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path11_streaming.py
More file actions
50 lines (40 loc) · 1.65 KB
/
Copy path11_streaming.py
File metadata and controls
50 lines (40 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# Copyright (c) 2025 Agentspan
# Licensed under the MIT License. See LICENSE file in the project root for details.
"""Streaming — real-time events.
Demonstrates streaming agent execution events. The runtime.stream() method
yields events as the agent executes, allowing real-time monitoring.
Requirements:
- Conductor server with LLM support
- AGENTSPAN_SERVER_URL=http://localhost:8080/api as environment variable
- AGENTSPAN_LLM_MODEL=openai/gpt-4o-mini as environment variable
"""
from conductor.ai.agents import Agent, AgentRuntime
from settings import settings
agent = Agent(
name="haiku_writer",
model=settings.llm_model,
instructions="You are a haiku poet. Write a single haiku.",
)
if __name__ == "__main__":
print("Streaming agent execution:")
print("-" * 40)
with AgentRuntime() as runtime:
result = runtime.run(agent, "Write a haiku about Python programming")
result.print_result()
# Production pattern:
# 1. Deploy once during CI/CD:
# runtime.deploy(agent)
# CLI alternative:
# agentspan deploy --package examples.11_streaming
#
# 2. In a separate long-lived worker process:
# runtime.serve(agent)
# Streaming alternative:
# for event in runtime.stream(agent, "Write a haiku about Python programming"):
# if event.type == "done":
# print(f"\nResult: {event.output}")
# print(f"Workflow: {event.execution_id}")
# elif event.type == "waiting":
# print("[Waiting...]")
# elif event.type == "error":
# print(f"[Error: {event.content}]")