File tree Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Expand file tree Collapse file tree 2 files changed +38
-1
lines changed Original file line number Diff line number Diff line change 2020 "start:stream-text" : " tsx stream-text.ts" ,
2121 "start:json-schema-output-type" : " tsx json-schema-output-type.ts" ,
2222 "start:tool-use-behavior" : " tsx tool-use-behavior.ts" ,
23- "start:tools" : " tsx tools.ts"
23+ "start:tools" : " tsx tools.ts" ,
24+ "start:reasoning" : " tsx reasoning.ts"
2425 }
2526}
Original file line number Diff line number Diff line change 1+ import { styleText } from 'node:util' ;
2+ import { Agent , run } from '@openai/agents' ;
3+
4+ const ASSISTANT_PREFIX = styleText ( [ 'bgGreen' , 'black' ] , 'Assistant' ) ;
5+ const THINKING_PREFIX = styleText ( [ 'bgGray' , 'black' ] , 'Thought' ) ;
6+
7+ async function main ( ) {
8+ const agent = new Agent ( {
9+ name : 'Agent' ,
10+ model : 'o3' ,
11+ modelSettings : {
12+ providerData : {
13+ reasoning : {
14+ effort : 'high' ,
15+ summary : 'auto' ,
16+ } ,
17+ } ,
18+ } ,
19+ } ) ;
20+
21+ const result = await run ( agent , 'How many r are in strawberry?' ) ;
22+
23+ for ( const item of result . newItems ) {
24+ if ( item . type === 'reasoning_item' ) {
25+ for ( const entry of item . rawItem . content ) {
26+ if ( entry . type === 'input_text' ) {
27+ console . log ( `${ THINKING_PREFIX } : ${ entry . text } ` ) ;
28+ }
29+ }
30+ }
31+ }
32+
33+ console . log ( `${ ASSISTANT_PREFIX } : ${ result . finalOutput } ` ) ;
34+ }
35+
36+ main ( ) . catch ( console . error ) ;
You can’t perform that action at this time.
0 commit comments