|
16 | 16 | " \n",
|
17 | 17 | "In addition to AutoGen, this notebook also requires eventlet and Gurobipy. The eventlet package is used in this notebook to constrain code execution with a timeout, and the gurobipy package is a mathematical optimization software library for solving mixed-integer linear and quadratic optimization problems. \n",
|
18 | 18 | "\n",
|
| 19 | + "````{=mdx}\n", |
| 20 | + ":::info Requirements\n", |
| 21 | + "Some extra dependencies are needed for this notebook, which can be installed via pip:\n", |
| 22 | + "\n", |
19 | 23 | "```bash\n",
|
20 | 24 | "pip install pyautogen eventlet gurobipy\n",
|
21 | 25 | "```\n",
|
| 26 | + "\n", |
| 27 | + "For more information, please refer to the [installation guide](/docs/installation/).\n", |
| 28 | + ":::\n", |
| 29 | + "````\n", |
22 | 30 | "\n"
|
23 | 31 | ]
|
24 | 32 | },
|
|
54 | 62 | "cell_type": "markdown",
|
55 | 63 | "metadata": {},
|
56 | 64 | "source": [
|
57 |
| - "# OptiGuide with Nested Chat\n", |
| 65 | + "````{=mdx}\n", |
| 66 | + ":::tip\n", |
| 67 | + "Learn more about configuring LLMs for agents [here](/docs/topics/llm_configuration).\n", |
| 68 | + ":::\n", |
| 69 | + "````\n", |
58 | 70 | "\n",
|
59 | 71 | "Intended agent orchestration in OptiGuide."
|
60 | 72 | ]
|
|
67 | 79 | "\n",
|
68 | 80 | "\n",
|
69 | 81 | "\n",
|
70 |
| - "### Step 0. Prepare Helper Functions\n", |
| 82 | + "## Step 0. Prepare Helper Functions\n", |
71 | 83 | "The code cell below includes several helper functions to be used by agents. The helper functions are adopted directly from [OptiGuide](https://github.com/microsoft/OptiGuide).\n",
|
72 | 84 | "\n",
|
73 |
| - "#### Utility Functions\n", |
| 85 | + "### Utility Functions\n", |
74 | 86 | "Several utility functions (replace, insert_code, run_with_exec) are defined to manipulate and execute the source code dynamically:\n",
|
75 | 87 | "\n",
|
76 |
| - "- **replace(src_code, old_code, new_code) -> str:**<br>Replaces a specified block of code within the source code with new code. This is essential for updating the code dynamically based on chatbot and user interactions.\n", |
| 88 | + "- **replace(src_code, old_code, new_code) -> str:**<br/>Replaces a specified block of code within the source code with new code. This is essential for updating the code dynamically based on chatbot and user interactions.\n", |
77 | 89 | "\n",
|
78 |
| - "- **insert_code(src_code, new_lines) -> str:**<br>Determines where to insert new lines of code based on specific markers in the source code. It's used to seamlessly integrate generated code snippets.\n", |
| 90 | + "- **insert_code(src_code, new_lines) -> str:**<br/>Determines where to insert new lines of code based on specific markers in the source code. It's used to seamlessly integrate generated code snippets.\n", |
79 | 91 | "\n",
|
80 |
| - "- **run_with_exec(src_code) -> Union[str, Exception]:**<br>Executes the modified source code within a controlled environment, capturing and returning the output or any errors that occur. This function is crucial for testing the feasibility and correctness of the generated code solutions.\n", |
| 92 | + "- **run_with_exec(src_code) -> Union[str, Exception]:**<br/>Executes the modified source code within a controlled environment, capturing and returning the output or any errors that occur. This function is crucial for testing the feasibility and correctness of the generated code solutions.\n", |
81 | 93 | "\n",
|
82 |
| - "#### Functions External Code Retrieval\n", |
| 94 | + "### Functions External Code Retrieval\n", |
83 | 95 | "The cell also includes logic to retrieve example source code from a remote repository using the requests library. This example code serves as a base for the chatbot to work with, allowing users to see real-life applications of the concepts discussed.\n",
|
84 | 96 | "\n",
|
85 | 97 | "The retrieved code is then displayed, showing both the beginning and the end of the source code to give a glimpse of its structure and content."
|
|
201 | 213 | "\n",
|
202 | 214 | "This cell introduces the Writer and OptiGuide agent classes and their instances to manage the interaction between the user, the chatbot, and the optimization solver. This streamlines the process of generating, evaluating, and integrating code solutions for supply chain optimization problems.\n",
|
203 | 215 | "\n",
|
204 |
| - "#### Classes Defined\n", |
| 216 | + "### Classes Defined\n", |
205 | 217 | "\n",
|
206 | 218 | "- **`OptiGuide`**: Inherits from `autogen.AssistantAgent` and serves as the main class for handling the supply chain optimization logic. It maintains state information like the source code, debugging attempts left, success status, and user chat history. Key methods include `set_success` and `update_debug_times`, which are used to update the agent's state based on the outcomes of interactions.\n",
|
207 | 219 | "\n",
|
208 | 220 | "- **`Writer`**: Also inherits from `autogen.AssistantAgent`, this class is tailored to manage the generation and explanation of Python code solutions. It keeps track of the source code and example Q&A to assist in generating responses to user queries.\n",
|
209 | 221 | "\n",
|
210 |
| - "#### Agent Instances\n", |
| 222 | + "### Agent Instances\n", |
211 | 223 | "\n",
|
212 | 224 | "- **`writer`**, **`safeguard`**, and **`optiguide_commander`**: Instances of the classes defined above, each configured with specific roles in the code generation and evaluation process. These agents work together to ensure that the user's questions are answered with safe, optimized, and understandable Python code solutions.\n",
|
213 | 225 | "\n",
|
|
402 | 414 | "cell_type": "markdown",
|
403 | 415 | "metadata": {},
|
404 | 416 | "source": [
|
405 |
| - "### Step 2. Orchestrate Nested Chats \n", |
| 417 | + "## Step 2. Orchestrate Nested Chats \n", |
406 | 418 | "\n",
|
407 | 419 | "These three agent instances are orchestrated in the following way with the `writer` and `safeguard` nested into the `commander` agent as the inner monologue.\n",
|
408 | 420 | "\n",
|
|
507 | 519 | "cell_type": "markdown",
|
508 | 520 | "metadata": {},
|
509 | 521 | "source": [
|
510 |
| - "#### Let the agents talk" |
| 522 | + "### Let the agents talk" |
511 | 523 | ]
|
512 | 524 | },
|
513 | 525 | {
|
|
1073 | 1085 | "cell_type": "markdown",
|
1074 | 1086 | "metadata": {},
|
1075 | 1087 | "source": [
|
1076 |
| - "#### Get Final Results from the Returned ChatResult Object " |
| 1088 | + "### Get Final Results from the Returned ChatResult Object " |
1077 | 1089 | ]
|
1078 | 1090 | },
|
1079 | 1091 | {
|
|
1103 | 1115 | }
|
1104 | 1116 | ],
|
1105 | 1117 | "metadata": {
|
| 1118 | + "extra_files_to_copy": [ |
| 1119 | + "optiGuide_new_design.png" |
| 1120 | + ], |
| 1121 | + "front_matter": { |
| 1122 | + "description": "This is a nested chat re-implementation of OptiGuide which is an LLM-based supply chain optimization framework.", |
| 1123 | + "tags": [ |
| 1124 | + "nested chat" |
| 1125 | + ] |
| 1126 | + }, |
1106 | 1127 | "kernelspec": {
|
1107 | 1128 | "display_name": "Python 3",
|
1108 | 1129 | "language": "python",
|
|
0 commit comments