2020from pydantic import BaseModel , Field
2121
2222import workflowai
23- from workflowai import Model , Run
23+ from workflowai import Model
2424
2525
2626class DelegateInput (BaseModel ):
@@ -80,8 +80,8 @@ class OrchestratorOutput(BaseModel):
8080 default_factory = list ,
8181 )
8282
83-
84- async def worker_agent (agent_input : WorkerInput ) -> Run [ WorkerOutput ] :
83+ @ workflowai . agent ()
84+ async def worker_agent (agent_input : WorkerInput ) -> WorkerOutput :
8585 """
8686 A specialized worker agent that handles specific tasks.
8787
@@ -95,13 +95,13 @@ async def worker_agent(agent_input: WorkerInput) -> Run[WorkerOutput]:
9595
9696async def delegate_task (agent_input : DelegateInput ) -> DelegateOutput :
9797 """Delegate a task to a worker agent with a specific model."""
98- # Create a new worker agent with the specified model
99- worker = workflowai .agent (id = "worker" , model = agent_input .model )(worker_agent )
100- run = await worker (
98+ # Run the worker agent with the specified model
99+ run = await worker_agent .run (
101100 WorkerInput (
102101 task = agent_input .task ,
103102 context = agent_input .context ,
104103 ),
104+ model = agent_input .model ,
105105 )
106106 return DelegateOutput (
107107 response = run .output .response ,
@@ -114,7 +114,7 @@ async def delegate_task(agent_input: DelegateInput) -> DelegateOutput:
114114 model = Model .GPT_4O_LATEST ,
115115 tools = [delegate_task ],
116116)
117- async def orchestrator_agent (agent_input : OrchestratorInput ) -> Run [ OrchestratorOutput ] :
117+ async def orchestrator_agent (agent_input : OrchestratorInput ) -> OrchestratorOutput :
118118 """
119119 You are an expert orchestrator that breaks down complex objectives into smaller tasks
120120 and delegates them to specialized agents. You can use the delegate_task tool to assign
@@ -146,7 +146,7 @@ async def main():
146146 print ("\n Example: Software Architecture Design" )
147147 print ("-" * 50 )
148148
149- result = await orchestrator_agent (
149+ result = await orchestrator_agent . run (
150150 OrchestratorInput (
151151 objective = "Design a scalable microservices architecture for an e-commerce platform" ,
152152 requirements = [
0 commit comments