Commit 222becbc by sunqi02

feat(agent_hub): 增加 IM 发送钩子的日志记录

1 parent 10dd61d6
......@@ -26,6 +26,7 @@ async def _im_post_reasoning_hook(
*, im_service, account_mapping, room_id, user_id, bot_id_mapping,
):
"""AgentScope native hook: 推理完成后通过 IM 发送 thinking 文本。"""
logger.info(f"[Hook 触发] agent={self.name} 时机=post_reasoning")
bot_id = (bot_id_mapping.get(self.name) or account_mapping.get(self.name))
if not bot_id:
return None
......@@ -39,9 +40,10 @@ async def _im_post_reasoning_hook(
content = "\n".join(content_parts) if content_parts else None
if not content:
return None
logger.info(f"[Hook 发送 IM] agent={self.name} bot_id={bot_id} content={content[:50]}...")
await im_service.send_message(
bot_id=bot_id, content=content,
contact_id=room_id, at_list=user_id,
contact_id=room_id, at_list="",
)
......@@ -50,6 +52,7 @@ async def _im_pre_acting_hook(
*, im_service, account_mapping, room_id, user_id, bot_id_mapping,
):
"""AgentScope native hook: 工具调用前通过 IM 发送即将执行的工具信息。"""
logger.info(f"[Hook 触发] agent={self.name} 时机=pre_acting")
bot_id = (bot_id_mapping.get(self.name) or account_mapping.get(self.name))
if not bot_id:
return None
......@@ -57,9 +60,10 @@ async def _im_pre_acting_hook(
if not tool_call:
return None
content = str(tool_call)
logger.info(f"[Hook 发送 IM] agent={self.name} bot_id={bot_id} tool_call={tool_call}")
await im_service.send_message(
bot_id=bot_id, content=content,
contact_id=room_id, at_list=user_id,
contact_id=room_id, at_list="",
)
......@@ -181,6 +185,7 @@ class AgentHub:
bot_id_mapping: Optional[Dict[str, str]],
):
"""为 Agent 实例注册 IM 发送 hook。"""
logger.info(f"[Hook 注册] agent={agent.name} 时机=post_reasoning")
route_ctx = dict(
im_service=self.im_service,
account_mapping=self.agent_to_account,
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!