Fix agent tool support, fix many other bugs
This commit is contained in:
1 parent
2b44dcebf4
commit
6c5140fb92
5 files changed
+79
-56
No files matched your search
@@ -24,11 +24,14 @@ class ExpertAgent(Agent):
|
||||
async def run(self, run):
|
||||
opts = {}
|
||||
|
||||
using_tools = False
|
||||
# Is this roon using *Agent's* tools, as opposed to run tools
|
||||
using_agent_tools = False
|
||||
if 'tools' not in run.input:
|
||||
# Agent tools will fully replace run tools if none are present,
|
||||
# otherwise they won't be used
|
||||
if self.tools:
|
||||
run.input['tools'] = self.tools
|
||||
using_tools = True
|
||||
using_agent_tools = True
|
||||
|
||||
if self.config.get("temperature") is not None:
|
||||
opts["temperature"] = self.config["temperature"]
|
||||
@@ -52,12 +55,11 @@ class ExpertAgent(Agent):
|
||||
output_stream = stream
|
||||
run.on('output', on_output)
|
||||
run.on('inference-end', lambda event: inference_end.set())
|
||||
run.on('tool-call', lambda tc: tool_calls.append(tc))
|
||||
run.on('tool-call', lambda tc: print(f"[expert] tool call: {tc}") or tool_calls.append(tc))
|
||||
|
||||
while True:
|
||||
# Reset data
|
||||
inference_end.clear()
|
||||
tool_calls = []
|
||||
output_stream = None
|
||||
|
||||
# Call inference, passing the run to get events out
|
||||
@@ -73,8 +75,10 @@ class ExpertAgent(Agent):
|
||||
await inference_end.wait()
|
||||
|
||||
messages.append(inference.LlamaMessage('assistant', output_stream and await output_stream.content_wait() or ""))
|
||||
print(f"[expert] collected tool calls: {len(tool_calls)}, using? {using_agent_tools}")
|
||||
|
||||
if using_tools and tool_calls:
|
||||
if using_agent_tools and tool_calls:
|
||||
print("Will execute tool calls")
|
||||
for tc in tool_calls:
|
||||
tool = next(t for t in self.tools if t.name == tc.tool_name)
|
||||
if not tool:
|
||||
@@ -82,7 +86,11 @@ class ExpertAgent(Agent):
|
||||
continue
|
||||
tc.result = await tool.execute_async(**tc.arguments)
|
||||
messages.append(inference.LlamaMessage('tool', tc))
|
||||
tool_calls = []
|
||||
# Buffer time to let openrouter rest?
|
||||
await asyncio.sleep(2)
|
||||
else:
|
||||
print("No tool calls to execute, finish")
|
||||
break
|
||||
|
||||
run.close()
|
||||
Reference in new issue
Block a user