{ "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": [ "
Audit Results:\n",
              "1. Missed Deadlines Due to Client Responses (high)\n",
              "   Projects frequently experience delays of 3-5 days because of late client responses. This not only pushes back \n",
              "project timelines but also affects overall agency efficiency.\n",
              "2. Unclear Ownership of Tasks (medium)\n",
              "   Team members often lack clarity on who is responsible for specific design tasks, leading to confusion and \n",
              "overlapping work efforts.\n",
              "3. Fragmented Communication Channels (medium)\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",
              "4. Bottlenecks in Approval Processes (high)\n",
              "   The approval processes for design tasks are unclear, leading to bottlenecks where projects cannot move forward \n",
              "without the necessary approvals.\n",
              "5. Delays Due to Lack of Comprehensive Documentation (medium)\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",
              "
\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": [ "
### Final Summary of Workflow Audit and Improvements\n",
              "\n",
              "**Key Issues Identified:**\n",
              "1. **Missed Deadlines Due to Client Responses**: Projects experience delays of 3-5 days from late client responses.\n",
              "2. **Unclear Ownership of Tasks**: Team members lack clarity on who is responsible for specific design tasks, \n",
              "causing confusion.\n",
              "3. **Fragmented Communication Channels**: Design tasks communicated through WhatsApp and feedback via email lead to\n",
              "misalignment.\n",
              "4. **Bottlenecks in Approval Processes**: Unclear approval processes halt project progression.\n",
              "5. **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",
              "1. **Project Management Tool**: \n",
              "   - **Completed**: Implemented a centralized project management tool to streamline task assignments and \n",
              "communication.\n",
              "   \n",
              "2. **Roles and Responsibilities**: \n",
              "   - **Completed**: Defined clear roles and responsibilities for each team member regarding design tasks to ensure \n",
              "ownership.\n",
              "   \n",
              "3. **Single Communication Channel**: \n",
              "   - **Completed**: Established a single channel for all project-related communications (Slack) to reduce \n",
              "fragmentation.\n",
              "   \n",
              "4. **Standardized Approval Process**: \n",
              "   - **Completed**: Created a standardized approval process with defined timelines and notifications to eliminate \n",
              "bottlenecks.\n",
              "   \n",
              "5. **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",
              "
\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 }