Skip to content

Commit

Permalink
Walk-throughs
Browse files Browse the repository at this point in the history
Signed-off-by: Mark Sze <[email protected]>
  • Loading branch information
marklysze committed Jan 24, 2025
1 parent 426b7d8 commit 5b6bd07
Show file tree
Hide file tree
Showing 14 changed files with 995 additions and 59 deletions.
119 changes: 107 additions & 12 deletions notebook/tools_dependency_injection.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,18 @@
},
{
"cell_type": "code",
"execution_count": 29,
"execution_count": 1,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"/usr/local/lib/python3.11/site-packages/tqdm/auto.py:21: TqdmWarning: IProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html\n",
" from .autonotebook import tqdm as notebook_tqdm\n"
]
}
],
"source": [
"import os\n",
"from typing import Annotated, Literal\n",
Expand All @@ -71,7 +80,7 @@
},
{
"cell_type": "code",
"execution_count": 30,
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -129,11 +138,19 @@
},
{
"cell_type": "code",
"execution_count": 32,
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"config_list = [{\"model\": \"gpt-4o-mini\", \"api_key\": os.environ[\"OPENAI_API_KEY\"]}]\n"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"config_list = [{\"model\": \"gpt-4o-mini\", \"api_key\": os.environ[\"OPENAI_API_KEY\"]}]\n",
"\n",
"assistant = ConversableAgent(\n",
" name=\"assistant\",\n",
Expand Down Expand Up @@ -294,7 +311,7 @@
},
{
"cell_type": "code",
"execution_count": 38,
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -321,7 +338,7 @@
},
{
"cell_type": "code",
"execution_count": 39,
"execution_count": 6,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -354,7 +371,7 @@
},
{
"cell_type": "code",
"execution_count": 40,
"execution_count": 7,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -373,7 +390,7 @@
},
{
"cell_type": "code",
"execution_count": 41,
"execution_count": 8,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -415,9 +432,87 @@
},
{
"cell_type": "code",
"execution_count": null,
"execution_count": 9,
"metadata": {},
"outputs": [],
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\u001b[33muser_proxy_1\u001b[0m (to chat_manager):\n",
"\n",
"Start by getting the weather for Sydney, Australia, and follow that up by checking if there are tickets for the 'AG2 Live' concert.\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[32m\n",
"Next speaker: weather_agent\n",
"\u001b[0m\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mweather_agent\u001b[0m (to chat_manager):\n",
"\n",
"\u001b[32m***** Suggested tool call (call_4ZWdbwuuojMxGXoxQDPzXpRl): get_weather *****\u001b[0m\n",
"Arguments: \n",
"{\"location\": \"Sydney, Australia\"}\n",
"\u001b[32m****************************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[32m\n",
"Next speaker: user_proxy_1\n",
"\u001b[0m\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING FUNCTION get_weather...\n",
"Call ID: call_4ZWdbwuuojMxGXoxQDPzXpRl\n",
"Input arguments: {'location': 'Sydney, Australia'}\u001b[0m\n",
"Accessing third party Weather System using username ag2weather\n",
"\u001b[33muser_proxy_1\u001b[0m (to chat_manager):\n",
"\n",
"\u001b[32m***** Response from calling tool (call_4ZWdbwuuojMxGXoxQDPzXpRl) *****\u001b[0m\n",
"It's sunny and 40 degrees Celsius in Sydney, Australia.\n",
"\u001b[32m**********************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[32m\n",
"Next speaker: ticket_agent\n",
"\u001b[0m\n",
"\u001b[31m\n",
">>>>>>>> USING AUTO REPLY...\u001b[0m\n",
"\u001b[33mticket_agent\u001b[0m (to chat_manager):\n",
"\n",
"\u001b[32m***** Suggested tool call (call_MQVDpFTDcdNdKxH7LsikfR1z): tickets_available *****\u001b[0m\n",
"Arguments: \n",
"{\"concert_name\":\"AG2 Live\"}\n",
"\u001b[32m**********************************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n",
"\u001b[32m\n",
"Next speaker: user_proxy_1\n",
"\u001b[0m\n",
"\u001b[35m\n",
">>>>>>>> EXECUTING FUNCTION tickets_available...\n",
"Call ID: call_MQVDpFTDcdNdKxH7LsikfR1z\n",
"Input arguments: {'concert_name': 'AG2 Live'}\u001b[0m\n",
"Accessing third party Ticketing System using username ag2tickets\n",
"\u001b[33muser_proxy_1\u001b[0m (to chat_manager):\n",
"\n",
"\u001b[32m***** Response from calling tool (call_MQVDpFTDcdNdKxH7LsikfR1z) *****\u001b[0m\n",
"false\n",
"\u001b[32m**********************************************************************\u001b[0m\n",
"\n",
"--------------------------------------------------------------------------------\n"
]
},
{
"data": {
"text/plain": [
"ChatResult(chat_id=None, chat_history=[{'content': \"Start by getting the weather for Sydney, Australia, and follow that up by checking if there are tickets for the 'AG2 Live' concert.\", 'role': 'assistant', 'name': 'user_proxy_1'}, {'content': 'None', 'tool_calls': [{'id': 'call_4ZWdbwuuojMxGXoxQDPzXpRl', 'function': {'arguments': '{\"location\": \"Sydney, Australia\"}', 'name': 'get_weather'}, 'type': 'function'}], 'name': 'weather_agent', 'role': 'assistant'}, {'content': \"It's sunny and 40 degrees Celsius in Sydney, Australia.\", 'tool_responses': [{'tool_call_id': 'call_4ZWdbwuuojMxGXoxQDPzXpRl', 'role': 'tool', 'content': \"It's sunny and 40 degrees Celsius in Sydney, Australia.\"}], 'role': 'tool', 'name': 'user_proxy_1'}, {'content': 'None', 'tool_calls': [{'id': 'call_MQVDpFTDcdNdKxH7LsikfR1z', 'function': {'arguments': '{\"concert_name\":\"AG2 Live\"}', 'name': 'tickets_available'}, 'type': 'function'}], 'name': 'ticket_agent', 'role': 'assistant'}, {'content': 'false', 'tool_responses': [{'tool_call_id': 'call_MQVDpFTDcdNdKxH7LsikfR1z', 'role': 'tool', 'content': 'false'}], 'role': 'tool', 'name': 'user_proxy_1'}], summary='false', cost={'usage_including_cached_inference': {'total_cost': 0}, 'usage_excluding_cached_inference': {'total_cost': 0}}, human_input=[])"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"groupchat = GroupChat(agents=[user_proxy, weather_agent, ticket_agent], messages=[], max_round=5)\n",
"manager = GroupChatManager(groupchat=groupchat, llm_config={\"config_list\": config_list})\n",
Expand Down Expand Up @@ -454,7 +549,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.11"
"version": "3.11.10"
}
},
"nbformat": 4,
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions website/docs/Use-Cases/walk-throughs/code-execution.md
Original file line number Diff line number Diff line change
Expand Up @@ -401,3 +401,13 @@ The command line code executor does not keep any state in memory between executi
Contrast to the command line code executor, the Jupyter code executor runs all code blocks in the same Jupyter kernel, which keeps the state in memory between executions. See the topic page for [Jupyter Code Executor](/docs/topics/code-execution/jupyter-code-executor).

The choice between command line and Jupyter code executor depends on the nature of the code blocks in agents' conversation. If each code block is a "script" that does not use variables from previous code blocks, the command line code executor is a good choice. If some code blocks contain expensive computations (e.g., training a machine learning model and loading a large amount of data), and you want to keep the state in memory to avoid repeated computations, the Jupyter code executor is a better choice.

### More Code Execution examples
- [Task Solving with Code Generation, Execution, and Debugging](https://docs.ag2.ai/notebooks/agentchat_auto_feedback_from_code_execution)
- [Auto-Generated Agent Chat: Task Solving with Code Gen, Execution, Debugging & Human Feedback](https://docs.ag2.ai/notebooks/agentchat_human_feedback)

### API
- [ConversableAgent.code_execution_config](TODO)
- [LocalCommandLineCodeExecutor](TODO)
- [DockerCommandLineCodeExecutor](TODO)
- [jupyter.JupyterCodeExecutor](TODO)
Loading

0 comments on commit 5b6bd07

Please sign in to comment.