import type { HookBus } from './index.js'; export default (hooks: HookBus) => { // hooks.on('agent:start', async (data) => { // console.log('🚀 ~ agent:start ~ data:', data); // }); // hooks.on('step:before', async (data) => { // console.log('🚀 ~ step:before ~ data:', data); // }); hooks.on('tool:before', async (data) => { const { toolCall: tc, agentName } = data; const prefix = agentName ? `[${agentName}] ` : ''; console.log(` ${prefix}[工具调用] ${tc.function.name}(${tc.function.arguments})`); }); hooks.on('tool:after', async (data) => { const { toolCall: tc, result, agentName } = data; const prefix = agentName ? `[${agentName}] ` : ''; console.log(` ${prefix}[工具] ${tc.function.name}(${tc.function.arguments}) -> ${result}`); }); hooks.on('agent:end', async (data) => { const { reply } = data; // reply 可能是字符串(Agent.run 返回值)或 OpenAI message 对象 const content = typeof reply === 'string' ? reply : reply.content; console.log('助手:', content); }); }