Skip to content

Commit a29ccd1

Browse files
add withtrace to example
1 parent ba39da8 commit a29ccd1

File tree

1 file changed

+11
-7
lines changed
  • integration-tests/cloudflare-workers/worker/src

1 file changed

+11
-7
lines changed

integration-tests/cloudflare-workers/worker/src/index.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import {
2323
run,
2424
setDefaultOpenAIKey,
2525
setTraceProcessors,
26+
withTrace,
2627
} from '@openai/agents';
2728

2829
export default {
@@ -31,14 +32,17 @@ export default {
3132
setDefaultOpenAIKey(env.OPENAI_API_KEY!);
3233
setTraceProcessors([new BatchTraceProcessor(new ConsoleSpanExporter())]);
3334

34-
const agent = new Agent({
35-
name: 'Test Agent',
36-
instructions:
37-
'You will always only respond with "Hello there!". Not more not less.',
38-
});
39-
const result = await run(agent, 'Hey there!');
35+
// Optionally wrap your code into a trace if you want to make multiple runs in a single trace
36+
return await withTrace('Cloudflare Worker', async () => {
37+
const agent = new Agent({
38+
name: 'Test Agent',
39+
instructions:
40+
'You will always only respond with "Hello there!". Not more not less.',
41+
});
42+
const result = await run(agent, 'Hey there!');
4043

41-
return new Response(`[RESPONSE]${result.finalOutput}[/RESPONSE]`);
44+
return new Response(`[RESPONSE]${result.finalOutput}[/RESPONSE]`);
45+
});
4246
} catch (error) {
4347
console.error(error);
4448
return new Response(String(error), { status: 500 });

0 commit comments

Comments
 (0)