Update inner tool usage logic to support both regular and function calling

This commit is contained in:
João Moura
2024-03-02 13:54:23 -03:00
parent c523fcdaab
commit 8468445e1d
10 changed files with 208 additions and 142 deletions

View File

@@ -20,24 +20,24 @@ class AgentTools(BaseModel):
func=self.delegate_work,
name="Delegate work to co-worker",
description=self.i18n.tools("delegate_work").format(
coworkers="\n".join([f"- {agent.role}" for agent in self.agents])
coworkers=[f"{agent.role}" for agent in self.agents]
),
),
StructuredTool.from_function(
func=self.ask_question,
name="Ask question to co-worker",
description=self.i18n.tools("ask_question").format(
coworkers="\n".join([f"- {agent.role}" for agent in self.agents])
coworkers=[f"{agent.role}" for agent in self.agents]
),
),
]
def delegate_work(self, coworker: str, task: str, context: str):
"""Useful to delegate a specific task to a coworker."""
"""Useful to delegate a specific task to a coworker passing all necessary context and names."""
return self._execute(coworker, task, context)
def ask_question(self, coworker: str, question: str, context: str):
"""Useful to ask a question, opinion or take from a coworker."""
"""Useful to ask a question, opinion or take from a coworker passing all necessary context and names."""
return self._execute(coworker, question, context)
def _execute(self, agent, task, context):
@@ -59,5 +59,9 @@ class AgentTools(BaseModel):
)
agent = agent[0]
task = Task(description=task, agent=agent)
task = Task(
description=task,
agent=agent,
expected_output="Your best answer to your coworker asking you this, accounting for the context shared.",
)
return agent.execute_task(task, context)