Skip to content

Commit 2020757

Browse files
authored
Update lifecycle-example to demonstrate how to acess tool args (#519)
ref: openai/openai-agents-python#1765
1 parent 9b054e2 commit 2020757

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

examples/basic/lifecycle-example.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,18 @@ function attachHooks(agent: Agent<any, any>) {
5959
`### ${eventCounter}: ${agent.name} ended with output ${JSON.stringify(output)}. Usage: ${toPrintableUsage(ctx?.usage)}`,
6060
);
6161
});
62-
agent.on('agent_tool_start', (ctx, tool) => {
62+
agent.on('agent_tool_start', (ctx, tool, { toolCall }) => {
6363
eventCounter++;
64+
const args = toolCall.type === 'function_call' ? toolCall.arguments : '';
6465
console.log(
65-
`### ${eventCounter}: Tool ${tool.name} started. Usage: ${toPrintableUsage(ctx?.usage)}`,
66+
`### ${eventCounter}: Tool ${tool.name} (args: ${args}) started. Usage: ${toPrintableUsage(ctx?.usage)}`,
6667
);
6768
});
68-
agent.on('agent_tool_end', (ctx, tool, result) => {
69+
agent.on('agent_tool_end', (ctx, tool, result, { toolCall }) => {
6970
eventCounter++;
71+
const args = toolCall.type === 'function_call' ? toolCall.arguments : '';
7072
console.log(
71-
`### ${eventCounter}: Tool ${tool.name} ended with result ${JSON.stringify(result)}. Usage: ${toPrintableUsage(ctx?.usage)}`,
73+
`### ${eventCounter}: Tool ${tool.name} (args: ${args}) ended with result ${JSON.stringify(result)}. Usage: ${toPrintableUsage(ctx?.usage)}`,
7274
);
7375
});
7476
agent.on('agent_handoff', (ctx, nextAgent) => {

0 commit comments

Comments
 (0)