Skip to content

Commit 8d2930a

Browse files
chore(examples): add reasoning example (#75)
1 parent 32aec07 commit 8d2930a

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

examples/basic/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
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
}

examples/basic/reasoning.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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);

0 commit comments

Comments
 (0)