feat: inference generates messages, simplify inference run events, fix encoding bug

This commit is contained in:
Shivering Ocelot committed 2026-10-03 11:46:16 -05:00
1 parent ee323fe660
commit 868e9b0545
5 files changed
+258 -309

No files matched your search

+19 -38
View File
@@ -144,13 +144,28 @@ class Agent:
},
)
async def on_output_event(stream):
print("[agent] run output " + repr(stream))
async def on_inference(msg):
kwargs = {'content': msg.content}
if msg.role == 'assistant':
# kind and subkind are default
pass
elif msg.role == 'reasoning':
kwargs['kind'] = "log"
kwargs['subkind'] = "reasoning"
elif msg.role == 'tool':
kwargs['kind'] = "log"
kwargs['subkind'] = "tool-call"
kwargs['content'] = repr(msg.content)
else:
# Unknown message
kwargs['kind'] = "log"
new_message = await self.app.send_chat_message(
sender=self.id,
chat_id=message.chat_id,
thread_id=message.thread_id,
content=stream,
**kwargs
)
run.emit_event('chat-message', {
'messageId': new_message['id'],
@@ -158,41 +173,7 @@ class Agent:
'threadId': message.thread_id,
})
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,
kind="log",
subkind="reasoning",
)
run.emit_event('chat-message', {
'messageId': new_message['id'],
'chatId': message.chat_id,
'threadId': message.thread_id,
})
async def on_toolcall_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,
kind="log",
subkind="tool-call",
)
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 run.on_async('output', on_output_event)
await run.on_async('tool-call', on_toolcall_event)
await run.on_async('inference', on_inference)
await self.run(run)
return run