-
Notifications
You must be signed in to change notification settings - Fork 17
Expand file tree
/
Copy path06-model-settings.ts
More file actions
82 lines (71 loc) · 2.63 KB
/
Copy path06-model-settings.ts
File metadata and controls
82 lines (71 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) 2025 Agentspan
// Licensed under the MIT License. See LICENSE file in the project root for details.
/**
* OpenAI Agent with Model Settings -- temperature, max tokens, and more.
*
* Demonstrates:
* - Configuring model settings for fine-tuned LLM behavior
* - Low temperature for deterministic responses
* - High temperature for creative responses
*
* Requirements:
* - AGENTSPAN_SERVER_URL for the Agentspan path
*/
import { Agent, setTracingDisabled } from '@openai/agents';
import { AgentRuntime } from '@io-orkes/conductor-javascript/agents';
setTracingDisabled(true);
// ── Creative agent with high temperature ────────────────────────────
export const creativeAgent = new Agent({
name: 'creative_writer',
instructions:
'You are a creative writing assistant. Write with vivid imagery ' +
'and unexpected metaphors. Be bold and imaginative.',
model: 'gpt-4o-mini',
modelSettings: {
temperature: 0.9,
maxTokens: 500,
},
});
// ── Precise agent with low temperature ──────────────────────────────
export const preciseAgent = new Agent({
name: 'code_reviewer',
instructions:
'You are a precise code reviewer. Analyze code snippets for bugs, ' +
'security issues, and best practices. Be concise and specific.',
model: 'gpt-4o-mini',
modelSettings: {
temperature: 0.1,
maxTokens: 300,
},
});
// ── Run on agentspan ──────────────────────────────────────────────
async function main() {
const runtime = new AgentRuntime();
try {
console.log('--- Creative Agent (temp=0.9) ---');
const creativeResult = await runtime.run(
creativeAgent,
'Write a two-sentence story about a robot learning to paint.',
);
console.log('Status:', creativeResult.status);
creativeResult.printResult();
console.log('\n--- Precise Agent (temp=0.1) ---');
const preciseResult = await runtime.run(
preciseAgent,
'Review this Python code: `data = eval(user_input)`',
);
console.log('Status:', preciseResult.status);
preciseResult.printResult();
// Production pattern:
// 1. Deploy once during CI/CD:
// await runtime.deploy(creativeAgent);
// CLI alternative:
// agentspan deploy --package sdk/typescript/examples/openai --agents creative_writer
//
// 2. In a separate long-lived worker process:
// await runtime.serve(creativeAgent);
} finally {
await runtime.shutdown();
}
}
main().catch(console.error);