-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbasic-usage.js
More file actions
56 lines (46 loc) · 1.48 KB
/
Copy pathbasic-usage.js
File metadata and controls
56 lines (46 loc) · 1.48 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
/**
* OpenForge — Basic Usage Example
*
* Shows how to use OpenForge programmatically with OpenAI.
*
* Run:
* OPENAI_API_KEY=sk-xxx node examples/basic-usage.js
*/
const { AgentBuilder } = require('../');
async function main() {
// 1. Create a builder with your AI provider
const builder = new AgentBuilder({
aiProvider: async (messages, model, tools) => {
const { OpenAI } = require('openai');
const client = new OpenAI();
return await client.chat.completions.create({
model: model || 'gpt-4o-mini',
messages,
tools: tools?.length > 0 ? tools : undefined,
});
},
});
// 2. Initialize (discovers agents + tools)
await builder.initialize();
// 3. Create an agent programmatically
const agent = builder.createAgent({
name: 'example-agent',
description: 'A simple example agent',
systemPrompt: 'You are a helpful assistant. Be concise.',
runtime: { model: 'gpt-4o-mini', maxLoops: 3 },
tools: { require: ['builtin:date_time'] },
});
console.log(`Created: ${agent.name}`);
// 4. Run it
const result = await builder.runAgent('example-agent', 'What time is it?');
if (result.success) {
console.log('\n✅ Output:', result.output);
console.log(` Duration: ${result.duration}ms, Loops: ${result.loops}`);
} else {
console.error('❌ Error:', result.error);
}
// 5. Clean up
builder.deleteAgent('example-agent');
await builder.shutdown();
}
main().catch(console.error);