|
4 | 4 |
|
5 | 5 | class {{ cookiecutter.project_metadata.project_name|replace('-', '')|replace('_', '')|capitalize }}Stack: |
6 | 6 |
|
7 | | - def _handoff(self, task_name: str): |
8 | | - """Return a task formatted as a tool for handing off to another agent.""" |
9 | | - task = getattr(self, task_name) |
10 | | - def func(messages: list[str] = []) -> Agent: |
11 | | - return task(messages=messages) |
12 | | - func.__name__ = task_name |
13 | | - return func |
14 | | - |
15 | | - def _get_first_task(self) -> Agent: |
16 | | - """Get the first task.""" |
17 | | - task_name = agentstack.get_all_task_names()[0] |
18 | | - return getattr(self, task_name)() |
19 | | - |
20 | 7 | def run(self, inputs: list[str]): |
21 | 8 | app = Swarm() |
22 | | - response = app.run( |
23 | | - agent=self._get_first_task(), |
24 | | - messages=[], |
25 | | - context_variables=inputs, |
26 | | - debug=agentstack.conf.DEBUG, |
27 | | - ) |
28 | | - |
29 | | - for message in response.messages: |
30 | | - if message.get('tool_calls'): |
31 | | - for tool_call in message['tool_calls']: |
32 | | - agentstack.log.notify(f"Calling tool `{tool_call['function']['name']}`") |
33 | | - agentstack.log.debug(tool_call['function']['arguments']) |
34 | | - elif message.get('role') != 'tool': |
35 | | - agentstack.log.notify(f"{message['role']}:") |
| 9 | + history = [] |
| 10 | + for task in agentstack.get_all_tasks(): |
| 11 | + agentstack.log.notify(f"Running task `{task.name}`") |
| 12 | + response = app.run( |
| 13 | + agent=getattr(self, task.name)(), |
| 14 | + messages=history, |
| 15 | + context_variables=inputs, |
| 16 | + debug=agentstack.conf.DEBUG, |
| 17 | + ) |
| 18 | + for message in response.messages: |
| 19 | + if message.get('role') not in ['user', 'assistant']: |
| 20 | + continue |
| 21 | + if message.get('tool_calls'): |
| 22 | + continue |
| 23 | + history.append(message) |
36 | 24 | agentstack.log.info(message['content']) |
37 | 25 |
|
0 commit comments