-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathvercel-ai-sdk.ts
More file actions
67 lines (54 loc) · 1.86 KB
/
Copy pathvercel-ai-sdk.ts
File metadata and controls
67 lines (54 loc) · 1.86 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
/**
* Vercel AI SDK integration example
* Requires: npm install ai @ai-sdk/openai zod
*/
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';
import {
AgentDiff,
TypeScriptExecutorProxy,
BashExecutorProxy,
createVercelAITool,
} 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 tsTools = createVercelAITool(tsExecutor);
const bashTool = createVercelAITool(bashExecutor);
// Run agent with tools
console.log('\nRunning agent...');
const result = await generateText({
model: openai('gpt-5-mini'),
tools: {
execute_typescript: tsTools,
execute_bash: bashTool,
},
prompt: `Post a message "Hello from AI agent!" to the Slack channel with ID C01ABCD1234.
Use the Slack API at https://slack.com/api/chat.postMessage.
Then list all channels using https://slack.com/api/conversations.list.`,
maxSteps: 5,
});
console.log('\nAgent response:', result.text);
console.log('Steps taken:', result.steps?.length);
// 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);