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

Function run_agent

example/vercel_agent.py:69–154  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

67 self.process = None
68
69def run_agent():
70 vm = AgentVMClient()
71 try:
72 vm.start()
73
74 # Define tools
75 tools = [
76 {
77 "type": "function",
78 "function": {
79 "name": "execute_shell_command",
80 "description": "Execute a shell command in a sandboxed Linux environment. Use this to run Python scripts, check files, or perform calculations.",
81 "parameters": {
82 "type": "object",
83 "properties": {
84 "command": {
85 "type": "string",
86 "description": "The shell command to execute (e.g., \"ls -la\", \"python3 -c ...\")"
87 }
88 },
89 "required": ["command"]
90 }
91 }
92 }
93 ]
94
95 # Check for API Key
96 api_key = os.environ.get("OPENAI_API_KEY")
97
98 if api_key:
99 client = OpenAI(api_key=api_key)
100 messages = [
101 {"role": "user", "content": "Calculate the 10th Fibonacci number using Python and tell me the result."}
102 ]
103
104 MAX_STEPS = 5
105 step = 0
106
107 while step < MAX_STEPS:
108 step += 1
109 response = client.chat.completions.create(
110 model="gpt-4-turbo",
111 messages=messages,
112 tools=tools,
113 tool_choice="auto"
114 )
115
116 message = response.choices[0].message
117 messages.append(message)
118
119 if not message.tool_calls:
120 print("\nAgent Response:")
121 print(message.content)
122 break
123
124 for tool_call in message.tool_calls:
125 if tool_call.function.name == "execute_shell_command":
126 args = json.loads(tool_call.function.arguments)

Callers 1

vercel_agent.pyFile · 0.85

Calls 4

startMethod · 0.95
execMethod · 0.95
stopMethod · 0.95
AgentVMClientClass · 0.85

Tested by

no test coverage detected