-
Notifications
You must be signed in to change notification settings - Fork 854
/
Copy pathagent_hooks.js
36 lines (29 loc) · 1.17 KB
/
agent_hooks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import { AgentHooks } from 'openai-agents';
class CustomAgentHooks extends AgentHooks {
constructor(displayName) {
super();
this.eventCounter = 0;
this.displayName = displayName;
}
async on_start(context, agent) {
this.eventCounter += 1;
console.log(`### (${this.displayName}) ${this.eventCounter}: Agent ${agent.name} started`);
}
async on_end(context, agent, output) {
this.eventCounter += 1;
console.log(`### (${this.displayName}) ${this.eventCounter}: Agent ${agent.name} ended with output ${output}`);
}
async on_handoff(context, agent, source) {
this.eventCounter += 1;
console.log(`### (${this.displayName}) ${this.eventCounter}: Agent ${source.name} handed off to ${agent.name}`);
}
async on_tool_start(context, agent, tool) {
this.eventCounter += 1;
console.log(`### (${this.displayName}) ${this.eventCounter}: Agent ${agent.name} started tool ${tool.name}`);
}
async on_tool_end(context, agent, tool, result) {
this.eventCounter += 1;
console.log(`### (${this.displayName}) ${this.eventCounter}: Agent ${agent.name} ended tool ${tool.name} with result ${result}`);
}
}
export default CustomAgentHooks;