File tree Expand file tree Collapse file tree 1 file changed +11
-7
lines changed
integration-tests/cloudflare-workers/worker/src Expand file tree Collapse file tree 1 file changed +11
-7
lines changed Original file line number Diff line number Diff line change @@ -23,6 +23,7 @@ import {
2323 run ,
2424 setDefaultOpenAIKey ,
2525 setTraceProcessors ,
26+ withTrace ,
2627} from '@openai/agents' ;
2728
2829export 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 } ) ;
You can’t perform that action at this time.
0 commit comments