fix(backend): handle reasoning event correctly
This commit is contained in:
1 parent
11b5c4e69f
commit
143bca8a8b
2 files changed
+16
-2
No files matched your search
+15
-1
@@ -115,7 +115,21 @@ class Agent:
|
|||||||
'threadId': message.thread_id,
|
'threadId': message.thread_id,
|
||||||
})
|
})
|
||||||
|
|
||||||
await run.on_async('output', on_output_event)
|
async def on_reasoning_event(stream):
|
||||||
|
print("[agent] run output " + repr(stream))
|
||||||
|
new_message = await self.app.send_chat_message(
|
||||||
|
sender=self.id,
|
||||||
|
chat_id=message.chat_id,
|
||||||
|
thread_id=message.thread_id,
|
||||||
|
content=stream,
|
||||||
|
)
|
||||||
|
run.emit_event('chat-message', {
|
||||||
|
'messageId': new_message['id'],
|
||||||
|
'chatId': message.chat_id,
|
||||||
|
'threadId': message.thread_id,
|
||||||
|
})
|
||||||
|
|
||||||
|
await run.on_async('reasoning', on_reasoning_event)
|
||||||
|
|
||||||
await self.run(run)
|
await self.run(run)
|
||||||
return run
|
return run
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ async def openrouter_chat_completion(app, messages, model, tools=[], opts={}, ag
|
|||||||
if name == 'reasoning':
|
if name == 'reasoning':
|
||||||
if reasoning_stream == None:
|
if reasoning_stream == None:
|
||||||
reasoning_stream = Stream(app)
|
reasoning_stream = Stream(app)
|
||||||
agent_run.emit_event('output', reasoning_stream)
|
agent_run.emit_event('reasoning', reasoning_stream)
|
||||||
reasoning_stream.feed(value)
|
reasoning_stream.feed(value)
|
||||||
if name == 'tool-call':
|
if name == 'tool-call':
|
||||||
agent_run.emit_event('tool-call', value)
|
agent_run.emit_event('tool-call', value)
|
||||||
|
|||||||
Reference in new issue
Block a user