Skip to content

在 nanobot API server 的 streaming 中注入 tool 事件 #3698

@kaka1992

Description

@kaka1992

Problem / Motivation

修改 handle_chat_completions(约 15 行改动),在 _on_stream 旁边加 _on_progress 回调,将 tool 事件以 event:
nanobot.tool.progress 格式写入 SSE 流。与 hermes-agent 的实现模式完全一致。

Proposed Solution

nanobot/api/server.py handle_chat_completions 中新增

async def _on_progress(
text: str, /, tool_hint: bool = False, tool_events=None
):
if tool_events:
for evt in tool_events:
data = json.dumps({
"tool": evt["name"],
"toolCallId": evt["call_id"],
"status": "running" if evt["phase"] == "start" else "completed",
"arguments": evt.get("arguments"),
"result": evt.get("result"),
})
await q.put(f"event: nanobot.tool.progress\ndata: {data}\n\n")

Alternatives Considered

No response

Related Component

Channel (WeChat, Feishu, Telegram, etc.)

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions