-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathopenai-agents.ts
More file actions
68 lines (54 loc) · 1.89 KB
/
openai-agents.ts
File metadata and controls
68 lines (54 loc) · 1.89 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
/**
* OpenAI Agents SDK integration example
* Requires: npm install @openai/agents zod
*/
import { Agent } from '@openai/agents';
import {
AgentDiff,
TypeScriptExecutorProxy,
BashExecutorProxy,
createOpenAIAgentsTool,
} from 'agent-diff';
async function main() {
// Initialize Agent Diff client
const client = new AgentDiff();
// Create isolated environment
const env = await client.initEnv({
templateService: 'slack',
templateName: 'slack_default',
impersonateUserId: 'U01AGENBOT9',
});
console.log(`Environment: ${env.environmentId}`);
// Take before snapshot
const run = await client.startRun({ envId: env.environmentId });
// Create code executor tools
const tsExecutor = new TypeScriptExecutorProxy(env.environmentId, client.getBaseUrl(), env.token);
const bashExecutor = new BashExecutorProxy(env.environmentId, client.getBaseUrl(), env.token);
const tsTool = createOpenAIAgentsTool(tsExecutor);
const bashTool = createOpenAIAgentsTool(bashExecutor);
// Create agent
const agent = new Agent({
name: 'Slack Assistant',
instructions: `You are a helpful assistant that can interact with Slack API.
Use execute_typescript or execute_bash tools to make API calls to:
- https://slack.com/api/conversations.list
- https://slack.com/api/chat.postMessage
Authentication is handled automatically.`,
tools: [tsTool, bashTool],
});
// Run agent
console.log('\nRunning agent...');
const result = await agent.run(
'List all Slack channels and post "Hello from OpenAI Agents SDK!" to the general channel (C01ABCD1234)'
);
console.log('\nAgent response:', result.text);
// Get diff
const diff = await client.diffRun({
runId: run.runId,
});
console.log('\nChanges made:');
console.log('- Diff:', JSON.stringify(diff.diff, null, 2));
// Cleanup
await client.deleteEnv(env.environmentId);
}
main().catch(console.error);