Spaces:
Sleeping
Sleeping
File size: 22,597 Bytes
1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 fb940c5 1578580 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | {
"cells": [
{
"cell_type": "code",
"execution_count": 84,
"id": "1e01edce",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 84,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"from rich.console import Console\n",
"from dotenv import load_dotenv\n",
"from openai import OpenAI\n",
"import json\n",
"load_dotenv(override=True)"
]
},
{
"cell_type": "code",
"execution_count": 85,
"id": "b8b381a2",
"metadata": {},
"outputs": [],
"source": [
"def show(text):\n",
" try:\n",
" Console().print(text)\n",
" except Exception:\n",
" print(text)"
]
},
{
"cell_type": "code",
"execution_count": 86,
"id": "3db9453d",
"metadata": {},
"outputs": [],
"source": [
"openai = OpenAI()"
]
},
{
"cell_type": "code",
"execution_count": 87,
"id": "790d0b73",
"metadata": {},
"outputs": [],
"source": [
"projects = []\n",
"issues = []"
]
},
{
"cell_type": "code",
"execution_count": 97,
"id": "9d39fa53",
"metadata": {},
"outputs": [],
"source": [
"def audit_project(project_data: str) -> str:\n",
" prompt = f\"\"\" \n",
" You are a workflow audit assistant for creative agencies. Analyze the project workflow in the project data below and identify issues.\n",
"Focus on:\n",
"- missed deadlines\n",
"- unclear ownership\n",
"- fragmented communication\n",
"- bottlenecks\n",
"- delays\n",
"\n",
"Return a JSON list of issues. Each issue should have:\n",
"- title\n",
"- description\n",
"- severity (low, medium, high)\n",
"\n",
"Project data:\n",
"{project_data}\n",
"\"\"\"\n",
" response = openai.chat.completions.create(model=\"gpt-4o-mini\",\n",
" messages=[{\"role\": \"user\", \"content\": prompt}],\n",
" response_format={\"type\": \"json_object\"}\n",
" )\n",
"\n",
" result = json.loads(response.choices[0].message.content)\n",
" \n",
" new_issues = result.get(\"issues\", [])\n",
"\n",
" for issue in new_issues:\n",
" issues.append(issue)\n",
"\n",
" output = \"[bold]Audit Results:[/bold]\\n\"\n",
" for i, issue in enumerate(new_issues, 1):\n",
" output += f\"{i}. [red]{issue['title']}[/red] ({issue['severity']})\\n\"\n",
" output += f\" {issue['description']}\\n\"\n",
"\n",
" show(output)\n",
" return json.dumps(new_issues)"
]
},
{
"cell_type": "code",
"execution_count": 98,
"id": "1f447570",
"metadata": {},
"outputs": [],
"source": [
"audit_project_json = {\n",
" \"name\": \"audit_project\",\n",
" \"description\": \"Analyze a project workflow and identify bottlenecks and issues\",\n",
" \"parameters\": {\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"project_data\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"Full description of the project workflow, tasks, timelines, and communication\"\n",
" }\n",
" },\n",
" \"required\": [\"project_data\"],\n",
" \"additionalProperties\": False\n",
" }\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 99,
"id": "2b23c493",
"metadata": {},
"outputs": [],
"source": [
"audit_project_json = {\n",
" \"name\": \"audit_project\",\n",
" \"description\": \"Analyze a project workflow and identify bottlenecks and issues\",\n",
" \"parameters\": {\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"project_data\": {\n",
" \"type\": \"string\",\n",
" \"description\": \"Full description of the project workflow, tasks, timelines, and communication\"\n",
" }\n",
" },\n",
" \"required\": [\"project_data\"],\n",
" \"additionalProperties\": False\n",
" }\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 100,
"id": "a432b968",
"metadata": {},
"outputs": [],
"source": [
"create_todos_json = {\n",
" \"name\": \"create_todos\",\n",
" \"description\": \"Add new todos from a list of descriptions and return the full list\",\n",
" \"parameters\": {\n",
" \"type\": \"object\",\n",
" \"properties\": {\n",
" \"descriptions\": {\n",
" 'type': 'array',\n",
" 'items': {'type': 'string'},\n",
" 'title': 'Descriptions'\n",
" }\n",
" },\n",
" \"required\": [\"descriptions\"],\n",
" \"additionalProperties\": False\n",
" }\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 101,
"id": "171cb84b",
"metadata": {},
"outputs": [],
"source": [
"mark_complete_json = {\n",
" \"name\": \"mark_complete\",\n",
" \"description\": \"Mark complete the todo at the given position (starting from 1) and return the full list\",\n",
" \"parameters\": {\n",
" 'properties': {\n",
" 'index': {\n",
" 'description': 'The 1-based index of the todo to mark as complete',\n",
" 'title': 'Index',\n",
" 'type': 'integer'\n",
" },\n",
" 'completion_notes': {\n",
" 'description': 'Notes about how you completed the todo in rich console markup',\n",
" 'title': 'Completion Notes',\n",
" 'type': 'string'\n",
" }\n",
" },\n",
" 'required': ['index', 'completion_notes'],\n",
" 'type': 'object',\n",
" 'additionalProperties': False\n",
" }\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 102,
"id": "659c41a1",
"metadata": {},
"outputs": [],
"source": [
"tools = [\n",
" {\"type\": \"function\", \"function\": audit_project_json},\n",
" {\"type\": \"function\", \"function\": create_todos_json},\n",
" {\"type\": \"function\", \"function\": mark_complete_json},\n",
"]"
]
},
{
"cell_type": "code",
"execution_count": 103,
"id": "b78326a2",
"metadata": {},
"outputs": [],
"source": [
"def handle_tool_calls(tool_calls):\n",
" results = []\n",
" for tool_call in tool_calls:\n",
" tool_name = tool_call.function.name\n",
" arguments = json.loads(tool_call.function.arguments)\n",
" tool = globals().get(tool_name)\n",
" result = tool(**arguments) if tool else {}\n",
" results.append({\n",
" \"role\": \"tool\",\n",
" \"content\": json.dumps(result),\n",
" \"tool_call_id\": tool_call.id\n",
" })\n",
" return results"
]
},
{
"cell_type": "code",
"execution_count": 104,
"id": "c0d0afc7",
"metadata": {},
"outputs": [],
"source": [
"def loop(messages):\n",
" done = False\n",
" while not done:\n",
" response = openai.chat.completions.create(model=\"gpt-4o-mini\", messages=messages, tools=tools)\n",
" #finish_reason = response.choices[0].finish_reason\n",
" if response.choices[0].finish_reason == \"tool_calls\":\n",
" message = response.choices[0].message\n",
" tool_calls = message.tool_calls\n",
" results = handle_tool_calls(tool_calls)\n",
" messages.append(message)\n",
" messages.extend(results)\n",
" else:\n",
" done = True\n",
" show(response.choices[0].message.content)"
]
},
{
"cell_type": "code",
"execution_count": 105,
"id": "1b66a52d",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\"><span style=\"font-weight: bold\">Audit Results:</span>\n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>. <span style=\"color: #800000; text-decoration-color: #800000\">Missed Deadlines Due to Client Responses</span> <span style=\"font-weight: bold\">(</span>high<span style=\"font-weight: bold\">)</span>\n",
" Projects frequently experience delays of <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3</span>-<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span> days because of late client responses. This not only pushes back \n",
"project timelines but also affects overall agency efficiency.\n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span>. <span style=\"color: #800000; text-decoration-color: #800000\">Unclear Ownership of Tasks</span> <span style=\"font-weight: bold\">(</span>medium<span style=\"font-weight: bold\">)</span>\n",
" Team members often lack clarity on who is responsible for specific design tasks, leading to confusion and \n",
"overlapping work efforts.\n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3</span>. <span style=\"color: #800000; text-decoration-color: #800000\">Fragmented Communication Channels</span> <span style=\"font-weight: bold\">(</span>medium<span style=\"font-weight: bold\">)</span>\n",
" Design tasks are communicated via WhatsApp, while feedback is given through email, resulting in fragmented \n",
"communication and potential misalignment on project expectations.\n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4</span>. <span style=\"color: #800000; text-decoration-color: #800000\">Bottlenecks in Approval Processes</span> <span style=\"font-weight: bold\">(</span>high<span style=\"font-weight: bold\">)</span>\n",
" The approval processes for design tasks are unclear, leading to bottlenecks where projects cannot move forward \n",
"without the necessary approvals.\n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span>. <span style=\"color: #800000; text-decoration-color: #800000\">Delays Due to Lack of Comprehensive Documentation</span> <span style=\"font-weight: bold\">(</span>medium<span style=\"font-weight: bold\">)</span>\n",
" With files stored in Google Drive and multiple communication channels, the lack of a centralized documentation \n",
"system contributes to delays in project progression.\n",
"\n",
"</pre>\n"
],
"text/plain": [
"\u001b[1mAudit Results:\u001b[0m\n",
"\u001b[1;36m1\u001b[0m. \u001b[31mMissed Deadlines Due to Client Responses\u001b[0m \u001b[1m(\u001b[0mhigh\u001b[1m)\u001b[0m\n",
" Projects frequently experience delays of \u001b[1;36m3\u001b[0m-\u001b[1;36m5\u001b[0m days because of late client responses. This not only pushes back \n",
"project timelines but also affects overall agency efficiency.\n",
"\u001b[1;36m2\u001b[0m. \u001b[31mUnclear Ownership of Tasks\u001b[0m \u001b[1m(\u001b[0mmedium\u001b[1m)\u001b[0m\n",
" Team members often lack clarity on who is responsible for specific design tasks, leading to confusion and \n",
"overlapping work efforts.\n",
"\u001b[1;36m3\u001b[0m. \u001b[31mFragmented Communication Channels\u001b[0m \u001b[1m(\u001b[0mmedium\u001b[1m)\u001b[0m\n",
" Design tasks are communicated via WhatsApp, while feedback is given through email, resulting in fragmented \n",
"communication and potential misalignment on project expectations.\n",
"\u001b[1;36m4\u001b[0m. \u001b[31mBottlenecks in Approval Processes\u001b[0m \u001b[1m(\u001b[0mhigh\u001b[1m)\u001b[0m\n",
" The approval processes for design tasks are unclear, leading to bottlenecks where projects cannot move forward \n",
"without the necessary approvals.\n",
"\u001b[1;36m5\u001b[0m. \u001b[31mDelays Due to Lack of Comprehensive Documentation\u001b[0m \u001b[1m(\u001b[0mmedium\u001b[1m)\u001b[0m\n",
" With files stored in Google Drive and multiple communication channels, the lack of a centralized documentation \n",
"system contributes to delays in project progression.\n",
"\n"
]
},
"metadata": {},
"output_type": "display_data"
},
{
"data": {
"text/html": [
"<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\">### Final Summary of Workflow Audit and Improvements\n",
"\n",
"**Key Issues Identified:**\n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>. **Missed Deadlines Due to Client Responses**: Projects experience delays of <span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3</span>-<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span> days from late client responses.\n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span>. **Unclear Ownership of Tasks**: Team members lack clarity on who is responsible for specific design tasks, \n",
"causing confusion.\n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3</span>. **Fragmented Communication Channels**: Design tasks communicated through WhatsApp and feedback via email lead to\n",
"misalignment.\n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4</span>. **Bottlenecks in Approval Processes**: Unclear approval processes halt project progression.\n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span>. **Delays from Lack of Comprehensive Documentation**: Storing files in Google Drive without a centralized \n",
"documentation system contributes to delays.\n",
"\n",
"**Action Plan:**\n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">1</span>. **Project Management Tool**: \n",
" - **Completed**: Implemented a centralized project management tool to streamline task assignments and \n",
"communication.\n",
" \n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">2</span>. **Roles and Responsibilities**: \n",
" - **Completed**: Defined clear roles and responsibilities for each team member regarding design tasks to ensure \n",
"ownership.\n",
" \n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">3</span>. **Single Communication Channel**: \n",
" - **Completed**: Established a single channel for all project-related communications <span style=\"font-weight: bold\">(</span>Slack<span style=\"font-weight: bold\">)</span> to reduce \n",
"fragmentation.\n",
" \n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">4</span>. **Standardized Approval Process**: \n",
" - **Completed**: Created a standardized approval process with defined timelines and notifications to eliminate \n",
"bottlenecks.\n",
" \n",
"<span style=\"color: #008080; text-decoration-color: #008080; font-weight: bold\">5</span>. **Comprehensive Documentation System**: \n",
" - **Completed**: Developed a comprehensive documentation system that includes project files, deadlines, and \n",
"communication summaries for easy access.\n",
"\n",
"With these measures in place, the workflow of your creative agency should now be more efficient, reducing delays \n",
"and improving clarity on project ownership.\n",
"</pre>\n"
],
"text/plain": [
"### Final Summary of Workflow Audit and Improvements\n",
"\n",
"**Key Issues Identified:**\n",
"\u001b[1;36m1\u001b[0m. **Missed Deadlines Due to Client Responses**: Projects experience delays of \u001b[1;36m3\u001b[0m-\u001b[1;36m5\u001b[0m days from late client responses.\n",
"\u001b[1;36m2\u001b[0m. **Unclear Ownership of Tasks**: Team members lack clarity on who is responsible for specific design tasks, \n",
"causing confusion.\n",
"\u001b[1;36m3\u001b[0m. **Fragmented Communication Channels**: Design tasks communicated through WhatsApp and feedback via email lead to\n",
"misalignment.\n",
"\u001b[1;36m4\u001b[0m. **Bottlenecks in Approval Processes**: Unclear approval processes halt project progression.\n",
"\u001b[1;36m5\u001b[0m. **Delays from Lack of Comprehensive Documentation**: Storing files in Google Drive without a centralized \n",
"documentation system contributes to delays.\n",
"\n",
"**Action Plan:**\n",
"\u001b[1;36m1\u001b[0m. **Project Management Tool**: \n",
" - **Completed**: Implemented a centralized project management tool to streamline task assignments and \n",
"communication.\n",
" \n",
"\u001b[1;36m2\u001b[0m. **Roles and Responsibilities**: \n",
" - **Completed**: Defined clear roles and responsibilities for each team member regarding design tasks to ensure \n",
"ownership.\n",
" \n",
"\u001b[1;36m3\u001b[0m. **Single Communication Channel**: \n",
" - **Completed**: Established a single channel for all project-related communications \u001b[1m(\u001b[0mSlack\u001b[1m)\u001b[0m to reduce \n",
"fragmentation.\n",
" \n",
"\u001b[1;36m4\u001b[0m. **Standardized Approval Process**: \n",
" - **Completed**: Created a standardized approval process with defined timelines and notifications to eliminate \n",
"bottlenecks.\n",
" \n",
"\u001b[1;36m5\u001b[0m. **Comprehensive Documentation System**: \n",
" - **Completed**: Developed a comprehensive documentation system that includes project files, deadlines, and \n",
"communication summaries for easy access.\n",
"\n",
"With these measures in place, the workflow of your creative agency should now be more efficient, reducing delays \n",
"and improving clarity on project ownership.\n"
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"system_message = \"\"\"\n",
"You are a Workflow Rescue agent.\n",
"\n",
"Your job is to:\n",
"1. Audit the project workflow using the audit tool\n",
"2. Identify key issues\n",
"3. Create a plan using todos to fix them\n",
"4. Mark steps complete as you simulate execution\n",
"5. Present a clear final summary\n",
"\n",
"Always use tools to think and act.\n",
"Do not skip the audit step.\n",
"\"\"\"\n",
"\n",
"user_message = \"\"\"\n",
"We run a small creative agency.\n",
"\n",
"Design tasks come through WhatsApp, feedback comes via email,\n",
"files are in Google Drive, and approvals are unclear.\n",
"\n",
"Projects often delay by 3-5 days because clients respond late\n",
"and team members are unsure who owns what.\n",
"\"\"\"\n",
"\n",
"\n",
"messages = [\n",
" {\"role\": \"system\", \"content\": system_message},\n",
" {\"role\": \"user\", \"content\": user_message}\n",
"]\n",
"\n",
"loop(messages)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8b048fc5",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": ".venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
|