From 143bca8a8b7b03a78bd69c3a0cf9179761fd8035 Mon Sep 17 00:00:00 2001 From: Shivering Ocelot Date: Tue, 1 Sep 2026 22:19:43 -0500 Subject: [PATCH] fix(backend): handle reasoning event correctly --- backend/src/agent.py | 16 +++++++++++++++- backend/src/inference.py | 2 +- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/backend/src/agent.py b/backend/src/agent.py index befe887..9cf34d6 100644 --- a/backend/src/agent.py +++ b/backend/src/agent.py @@ -115,7 +115,21 @@ class Agent: '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) return run diff --git a/backend/src/inference.py b/backend/src/inference.py index e548f19..26834f1 100644 --- a/backend/src/inference.py +++ b/backend/src/inference.py @@ -318,7 +318,7 @@ async def openrouter_chat_completion(app, messages, model, tools=[], opts={}, ag if name == 'reasoning': if reasoning_stream == None: reasoning_stream = Stream(app) - agent_run.emit_event('output', reasoning_stream) + agent_run.emit_event('reasoning', reasoning_stream) reasoning_stream.feed(value) if name == 'tool-call': agent_run.emit_event('tool-call', value)