2026-07-10 17:21:38 +08:00

30 lines
1.1 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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);
});
}