|
1 | 1 | const { Agent, Runner } = require('../src/index'); |
2 | 2 |
|
3 | | -// Set your OpenAI API key |
4 | | -const OPENAI_API_KEY = process.env.OPENAI_API_KEY; |
5 | | - |
6 | | -// Provider configuration |
7 | | -const providerConfig = { |
8 | | - apiKey: OPENAI_API_KEY |
9 | | -}; |
10 | | - |
11 | 3 | async function main() { |
12 | 4 | // Create the Spanish agent with explicit configuration |
13 | 5 | const spanishAgent = new Agent({ |
14 | 6 | name: "Spanish_Agent", // Use underscore for consistency |
15 | | - instructions: "You are a helpful assistant that only speaks Spanish. Always respond in Spanish to any questions or requests.", |
16 | | - model: "gpt-4", |
17 | | - provider: "openai", |
18 | | - providerConfig, |
19 | | - modelSettings: { |
20 | | - temperature: 0.7, |
21 | | - max_tokens: 500 |
22 | | - } |
| 7 | + instructions: "You are a helpful assistant that only speaks Spanish. Always respond in Spanish to any questions or requests." |
23 | 8 | }); |
24 | 9 |
|
25 | 10 | // Create the English agent with explicit configuration |
26 | 11 | const englishAgent = new Agent({ |
27 | 12 | name: "English_Agent", // Use underscore for consistency |
28 | | - instructions: "You are a helpful assistant that only speaks English. Always respond in English to any questions or requests.", |
29 | | - model: "gpt-4", |
30 | | - provider: "openai", |
31 | | - providerConfig, |
32 | | - modelSettings: { |
33 | | - temperature: 0.7, |
34 | | - max_tokens: 500 |
35 | | - } |
| 13 | + instructions: "You are a helpful assistant that only speaks English. Always respond in English to any questions or requests." |
36 | 14 | }); |
37 | 15 |
|
38 | 16 | // Create the triage agent with explicit configuration |
39 | 17 | const triageAgent = new Agent({ |
40 | 18 | name: "Triage_Agent", // Use underscore for consistency |
41 | 19 | instructions: `You are a language triage agent. Your task is to analyze messages and route them to the appropriate language agent. |
42 | | -
|
43 | | -Rules: |
44 | | -1. For Spanish messages -> Use transfer_to_Spanish_Agent |
45 | | -2. For English messages -> Use transfer_to_English_Agent |
46 | | -3. DO NOT respond to the user directly |
47 | | -4. ALWAYS use the appropriate transfer function |
48 | | -5. If you detect Spanish, IMMEDIATELY call transfer_to_Spanish_Agent |
49 | | -6. If you detect English, IMMEDIATELY call transfer_to_English_Agent`, |
50 | | - handoffs: [spanishAgent, englishAgent], |
51 | | - model: "gpt-4", |
52 | | - provider: "openai", |
53 | | - providerConfig, |
54 | | - modelSettings: { |
55 | | - temperature: 0.7, |
56 | | - max_tokens: 500 |
57 | | - } |
| 20 | + Rules: |
| 21 | + 1. For Spanish messages -> Use transfer_to_Spanish_Agent |
| 22 | + 2. For English messages -> Use transfer_to_English_Agent |
| 23 | + 3. DO NOT respond to the user directly |
| 24 | + 4. ALWAYS use the appropriate transfer function |
| 25 | + 5. If you detect Spanish, IMMEDIATELY call transfer_to_Spanish_Agent |
| 26 | + 6. If you detect English, IMMEDIATELY call transfer_to_English_Agent`, |
| 27 | + handoffs: [spanishAgent, englishAgent] |
58 | 28 | }); |
59 | 29 |
|
60 | 30 | try { |
61 | 31 | console.log('Sending message to triage agent...'); |
62 | 32 | const result = await Runner.run(triageAgent, "Hola, ¿cómo estás?", { |
63 | | - maxTurns: 3, // Allow for triage + response |
| 33 | + // maxTurns: 1, // Allow for triage + response |
64 | 34 | context: { debug: true } |
65 | 35 | }); |
66 | | - |
| 36 | + |
67 | 37 | console.log('\nFinal response:', result.finalOutput); |
68 | 38 | console.log('Last agent:', result.lastAgent.name); |
69 | 39 | console.log('\nMessage history:'); |
|
0 commit comments