feat(backend): tool support in send agent prompt, regularize inference messages (wip)
This commit is contained in:
1 parent
2ba8096a3c
commit
659b7497fb
6 files changed
+127
-57
No files matched your search
+23
-2
@@ -77,9 +77,30 @@ class Agent:
|
||||
out_stream.close()
|
||||
run.on('output', on_output_event)
|
||||
run.on('done', on_done)
|
||||
await self.run(run)
|
||||
|
||||
return out_stream
|
||||
# Change the output shape based on the presence of tools
|
||||
if 'tools' in kwargs:
|
||||
tool_calls = []
|
||||
tool_names = [t['function']['name'] for t in kwargs['tools'] if isinstance(t, dict)]
|
||||
def on_tool_call(call):
|
||||
print('prompt call', call)
|
||||
if call.tool_name in tool_names:
|
||||
tool_calls.append(call)
|
||||
run.on('tool-call', on_tool_call)
|
||||
await self.run(run)
|
||||
|
||||
# Cannot stream tool calls out, wait for them
|
||||
await out_stream.content_wait()
|
||||
print('tool names' + repr(tool_names))
|
||||
print('tool calls' + repr(tool_calls))
|
||||
return {
|
||||
'output': out_stream,
|
||||
'tool_calls': tool_calls,
|
||||
}
|
||||
else:
|
||||
await self.run(run)
|
||||
return out_stream
|
||||
|
||||
|
||||
async def received_message(self, message):
|
||||
chat = await self.app.get_chat(message.chat_id)
|
||||
|
||||
Reference in new issue
Block a user