Delegation
The Orchestrator delegates tasks to specialized agents. It plans the work, assigns subtasks based on each agent's role, handles dependencies, and collects results.
Setting up delegation
setup.py
from veska import Agent, Orchestrator
# Create specialized agents
researcher = Agent(
name="researcher",
system_prompt="You research topics and provide detailed findings with sources.",
model="claude-sonnet-4-6",
)
writer = Agent(
name="writer",
system_prompt="You write clear, well-structured content based on research.",
model="claude-sonnet-4-6",
)
reviewer = Agent(
name="reviewer",
system_prompt="You review content for accuracy, clarity, and completeness.",
model="claude-sonnet-4-6",
)
# Create orchestrator with delegation enabled
orchestrator = Orchestrator(
model="claude-sonnet-4-6",
agents=[researcher, writer, reviewer],
allow_delegation=True,
delegation_timeout=300, # 5 minute timeout per agent
)How it works
1The Orchestrator receives a prompt and uses AI to analyze what needs to be done.
2It creates tasks and assigns each task to the best agent based on their system prompt.
3Tasks with dependencies wait. Independent tasks run in parallel.
4Each agent completes its task and returns a result.
5The Orchestrator collects all results and synthesizes the final output.
Running a delegation
run.py
result = orchestrator.run("Write a comprehensive blog post about AI agents")
# The orchestrator automatically:
# 1. Creates a plan: research → write → review
# 2. Assigns "research" task to researcher agent
# 3. Waits for research, then assigns "write" to writer
# 4. Waits for draft, then assigns "review" to reviewer
# 5. Returns the final result
print(result.plan) # The execution plan
print(result.results) # Results from each task
print(result.progress) # {"completed": 3, "total": 3, "percentage": 100}Task dependencies
The Orchestrator's AI automatically determines which tasks depend on others. Independent tasks run in parallel:
parallel.py
# Given the prompt: "Research both AI and ML, then write a comparison"
# The orchestrator might create:
#
# Wave 1 (parallel):
# - Task: "Research AI" → researcher
# - Task: "Research ML" → researcher
#
# Wave 2 (sequential):
# - Task: "Write comparison" → writer (depends on both research tasks)
#
# Wave 3 (sequential):
# - Task: "Review" → reviewer (depends on writing)Dynamic agent registration
dynamic.py
# Add agents after orchestrator creation
editor = Agent(
name="editor",
system_prompt="You polish and edit content for grammar and style.",
model="claude-sonnet-4-6",
)
orchestrator.register_agent("editor", editor)
# Now the orchestrator can delegate to the editor tooWith tools
Give the orchestrator tools that all agents can use:
tools.py
orchestrator = Orchestrator(
model="claude-sonnet-4-6",
agents=[backend_agent, frontend_agent],
tools=["file_manager", "code_runner"], # Pre-built tool sets
allow_delegation=True,
)
# Now agents can create files, run code, etc. during their tasks