forked from conductor-oss/python-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16_random_strategy.py
More file actions
72 lines (60 loc) · 2.11 KB
/
Copy path16_random_strategy.py
File metadata and controls
72 lines (60 loc) · 2.11 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# Copyright (c) 2025 Agentspan
# Licensed under the MIT License. See LICENSE file in the project root for details.
"""Random Strategy — random agent selection each turn.
Demonstrates the ``strategy="random"`` pattern where a random sub-agent
is selected each iteration. Unlike round-robin (fixed rotation), random
selection adds variety — useful for brainstorming or diverse perspectives.
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, Strategy
from settings import settings
creative = Agent(
name="creative",
model=settings.llm_model,
instructions=(
"You are a creative thinker. Suggest innovative, unconventional ideas. "
"Keep your response to 2-3 sentences."
),
)
practical = Agent(
name="practical",
model=settings.llm_model,
instructions=(
"You are a practical thinker. Focus on feasibility and cost-effectiveness. "
"Keep your response to 2-3 sentences."
),
)
critical = Agent(
name="critical",
model=settings.llm_model,
instructions=(
"You are a critical thinker. Identify risks and potential issues. "
"Keep your response to 2-3 sentences."
),
)
# Random selection: each turn, one of the three agents is picked at random
brainstorm = Agent(
name="brainstorm",
model=settings.llm_model,
agents=[creative, practical, critical],
strategy=Strategy.RANDOM,
max_turns=6,
)
if __name__ == "__main__":
with AgentRuntime() as runtime:
result = runtime.run(
brainstorm,
"How should we approach building an AI-powered customer service platform?",
)
result.print_result()
# Production pattern:
# 1. Deploy once during CI/CD:
# runtime.deploy(brainstorm)
# CLI alternative:
# agentspan deploy --package examples.16_random_strategy
#
# 2. In a separate long-lived worker process:
# runtime.serve(brainstorm)