MCPcopy Create free account
hub / github.com/deepclause/agentvm / runAgent

Function runAgent

example/vercel-agent.js:11–65  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

9// Note: You need an OPENAI_API_KEY in .env to run this effectively.
10
11async function runAgent() {
12 const vm = new AgentVM({});
13 console.log("Booting VM...");
14 await vm.start();
15 console.log("VM Ready.");
16
17 try {
18 const tools = {
19 execute_shell_command: tool({
20 description: 'Execute a shell command in a sandboxed Linux environment. Use this to run Python scripts, check files, or perform calculations.',
21 parameters: {
22 type: 'object',
23 properties: {
24 command: {
25 type: 'string',
26 description: 'The shell command to execute (e.g., "ls -la", "python3 -c ...")'
27 },
28 },
29 required: ['command'],
30 },
31 execute: async ({ command }) => {
32 console.log(`[Tool] Executing: ${command}`);
33 const res = await vm.exec(command);
34 if (res.exitCode !== 0) {
35 return `Error (Exit ${res.exitCode}): ${res.stderr || res.stdout}`;
36 }
37 return res.stdout;
38 },
39 }),
40 };
41
42 // Example interaction (mocked if no API key)
43 if (process.env.OPENAI_API_KEY) {
44 const result = await generateText({
45 model: openai('gpt-4-turbo'),
46 tools: tools,
47 maxSteps: 5,
48 prompt: 'Calculate the 10th Fibonacci number using Python and tell me the result.',
49 });
50
51 console.log("\nAgent Response:");
52 console.log(result.text);
53 } else {
54 console.log("\n[Simulated Agent Interaction]");
55 console.log("User: List files in current directory.");
56 const output = await tools.execute_shell_command.execute({ command: 'ls -F' });
57 console.log("Tool Output:", JSON.stringify(output));
58 }
59
60 } catch (error) {
61 console.error("Agent Error:", error);
62 } finally {
63 await vm.stop();
64 }
65}
66
67runAgent();

Callers 1

vercel-agent.jsFile · 0.85

Calls 3

startMethod · 0.95
execMethod · 0.95
stopMethod · 0.95

Tested by

no test coverage detected