Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion examples/basic/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"start:stream-text": "tsx stream-text.ts",
"start:json-schema-output-type": "tsx json-schema-output-type.ts",
"start:tool-use-behavior": "tsx tool-use-behavior.ts",
"start:tools": "tsx tools.ts"
"start:tools": "tsx tools.ts",
"start:reasoning": "tsx reasoning.ts"
}
}
36 changes: 36 additions & 0 deletions examples/basic/reasoning.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { styleText } from 'node:util';
import { Agent, run } from '@openai/agents';

const ASSISTANT_PREFIX = styleText(['bgGreen', 'black'], 'Assistant');
const THINKING_PREFIX = styleText(['bgGray', 'black'], 'Thought');

async function main() {
const agent = new Agent({
name: 'Agent',
model: 'o3',
modelSettings: {
providerData: {
reasoning: {
effort: 'high',
summary: 'auto',
},
},
},
});

const result = await run(agent, 'How many r are in strawberry?');

for (const item of result.newItems) {
if (item.type === 'reasoning_item') {
for (const entry of item.rawItem.content) {
if (entry.type === 'input_text') {
console.log(`${THINKING_PREFIX}: ${entry.text}`);
}
}
}
}

console.log(`${ASSISTANT_PREFIX}: ${result.finalOutput}`);
}

main().catch(console.error);