MCPcopy Create free account
hub / github.com/HKUDS/AutoAgent / examples

Function examples

autoagent/agents/system_agent/programming_agent.py:11–57  ·  view source on GitHub ↗
(context_variables)

Source from the content-addressed store, hash-verified

9from typing import Union
10from inspect import signature
11def examples(context_variables):
12 working_dir = context_variables.get("working_dir", None)
13 examples_list = []
14 examples_list.extend(make_message('user', "Create a list of numbers from 1 to 10, and display them in a web page at port 5000."))
15 examples_list.extend(make_message('assistant', "I should first use create_file to write the python code into a file named 'app.py' for starting a web server"))
16 examples_list.extend(make_tool_message(create_file, {'path': f"/{working_dir}/app.py",
17 'content': """
18from flask import Flask
19app = Flask(__name__)
20
21@app.route('/')
22def index():
23 numbers = list(range(1, 11))
24 return str(numbers)
25
26if __name__ == '__main__':
27 app.run(port=5000)"""}, f"File created at: /{working_dir}/app.py"))
28 examples_list.extend(make_message('assistant', 'I have created a Python file `app.py` that will display a list of numbers from 1 to 10 when you run it. Let me run the Python file for you using `run_python`'))
29 examples_list.extend(make_tool_message(run_python, {'code_path': f"/{working_dir}/app.py"}, f"""
30Traceback (most recent call last):
31 File "/{working_dir}/app.py", line 2, in <module>
32 from flask import Flask
33ModuleNotFoundError: No module named 'flask'"""))
34 examples_list.extend(make_message('assistant', "It seems that Flask is not installed. Let me install Flask for you using `execute_command` by the command: pip install flask"))
35 examples_list.extend(make_tool_message(execute_command, {'command': 'pip install flask'}, """Defaulting to user installation because normal site-packages is not writeable
36Collecting flask
37 Using cached flask-3.0.3-py3-none-any.whl (101 kB)
38Collecting blinker>=1.6.2
39 Using cached blinker-1.7.0-py3-none-any.whl (13 kB)
40Collecting Werkzeug>=3.0.0
41 Using cached werkzeug-3.0.2-py3-none-any.whl (226 kB)
42Collecting click>=8.1.3
43 Using cached click-8.1.7-py3-none-any.whl (97 kB)
44Collecting itsdangerous>=2.1.2
45 Using cached itsdangerous-2.2.0-py3-none-any.whl (16 kB)
46Requirement already satisfied: Jinja2>=3.1.2 in /home/openhands/.local/lib/python3.10/site-packages (from flask) (3.1.3)
47Requirement already satisfied: MarkupSafe>=2.0 in /home/openhands/.local/lib/python3.10/site-packages (from Jinja2>=3.1.2->flask) (2.1.5)
48Installing collected packages: Werkzeug, itsdangerous, click, blinker, flask
49Successfully installed Werkzeug-3.0.2 blinker-1.7.0 click-8.1.7 flask-3.0.3 itsdangerous-2.2.0"""))
50 examples_list.extend(make_message('assistant', "Now that Flask is installed, let me run the Python file again using `run_python`"))
51 examples_list.extend(make_tool_message(run_python, {'code_path': f"/{working_dir}/app.py"}, """* Serving Flask app 'app'
52 * Debug mode: off
53WARNING: This is a development server. Do not use it in a production deployment. Use a production WSGI server instead.
54 * Running on http://127.0.0.1:5000
55Press CTRL+C to quit"""))
56 examples_list.extend(make_message('assistant', """The server is running on port 5000 with PID 124. You can access the list of numbers by visiting http://127.0.0.1:5000. Your task is completed."""))
57 return examples_list
58
59@register_agent(name= "Coding Agent", func_name="get_coding_agent")
60@register_plugin_agent(name= "Coding Agent", func_name="get_coding_agent")

Callers

nothing calls this directly

Calls 3

make_messageFunction · 0.90
make_tool_messageFunction · 0.90
getMethod · 0.80

Tested by

no test coverage detected