|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": null, |
| 6 | + "id": "75d3bee5", |
| 7 | + "metadata": {}, |
| 8 | + "outputs": [], |
| 9 | + "source": [ |
| 10 | + "# We install the necessary libraries directly from the notebook.\n", |
| 11 | + "# The '!' allows us to run shell commands.\n", |
| 12 | + "!pip install openai python-dotenv" |
| 13 | + ] |
| 14 | + }, |
| 15 | + { |
| 16 | + "cell_type": "code", |
| 17 | + "execution_count": null, |
| 18 | + "id": "ee51e92d", |
| 19 | + "metadata": {}, |
| 20 | + "outputs": [], |
| 21 | + "source": [ |
| 22 | + "import os\n", |
| 23 | + "from dotenv import load_dotenv\n", |
| 24 | + "\n", |
| 25 | + "# Import our custom agent class\n", |
| 26 | + "from reflection_pattern_agent.reflection_agent import ReflectionAgent\n", |
| 27 | + "\n", |
| 28 | + "# Load environment variables from the .env file\n", |
| 29 | + "# This is where we securely load our OPENAI_API_KEY\n", |
| 30 | + "load_dotenv()\n", |
| 31 | + "\n", |
| 32 | + "print(\"Libraries and agent class imported successfully.\")" |
| 33 | + ] |
| 34 | + }, |
| 35 | + { |
| 36 | + "cell_type": "code", |
| 37 | + "execution_count": null, |
| 38 | + "id": "9e2757f1", |
| 39 | + "metadata": {}, |
| 40 | + "outputs": [], |
| 41 | + "source": [ |
| 42 | + "# 1. Instantiate the agent\n", |
| 43 | + "# This will automatically pick up the API key from the environment\n", |
| 44 | + "agent = ReflectionAgent()\n", |
| 45 | + "\n", |
| 46 | + "# 2. Define a simple prompt to test the generation\n", |
| 47 | + "test_prompt = \"Write a short, engaging tweet about the importance of MLOps.\"\n", |
| 48 | + "\n", |
| 49 | + "# 3. Call the generate method\n", |
| 50 | + "print(\"--- Calling the generate method... ---\")\n", |
| 51 | + "initial_draft = agent.generate(prompt=test_prompt)\n", |
| 52 | + "\n", |
| 53 | + "# 4. Print the result\n", |
| 54 | + "print(\"\\n--- Initial Draft Generated ---\")\n", |
| 55 | + "print(initial_draft)" |
| 56 | + ] |
| 57 | + }, |
| 58 | + { |
| 59 | + "cell_type": "code", |
| 60 | + "execution_count": null, |
| 61 | + "id": "a42e570b", |
| 62 | + "metadata": {}, |
| 63 | + "outputs": [], |
| 64 | + "source": [ |
| 65 | + "# --- Full Cycle Integration Test ---\n", |
| 66 | + "\n", |
| 67 | + "# 1. Define a more complex task where reflection can make a real difference.\n", |
| 68 | + "complex_prompt = \"\"\"\n", |
| 69 | + "Write a short paragraph for a LinkedIn post announcing a new feature\n", |
| 70 | + "for our project management tool. The feature is an AI-powered assistant\n", |
| 71 | + "that automatically suggests the next task for a user based on their\n", |
| 72 | + "project's progress and priorities. Mention the key benefit:\n", |
| 73 | + "it helps reduce decision fatigue for team leads.\n", |
| 74 | + "\"\"\"\n", |
| 75 | + "\n", |
| 76 | + "# 2. Execute the full run cycle\n", |
| 77 | + "initial_draft, reflections, final_output = agent.run(prompt=complex_prompt)\n", |
| 78 | + "\n", |
| 79 | + "# 3. Analyze the results\n", |
| 80 | + "print(\"\\n\" + \"=\"*50)\n", |
| 81 | + "print(\"INITIAL DRAFT\")\n", |
| 82 | + "print(\"=\"*50)\n", |
| 83 | + "print(initial_draft)\n", |
| 84 | + "\n", |
| 85 | + "print(\"\\n\" + \"=\"*50)\n", |
| 86 | + "print(\"REFLECTIONS\")\n", |
| 87 | + "print(\"=\"*50)\n", |
| 88 | + "# Print reflections as a bulleted list\n", |
| 89 | + "for r in reflections:\n", |
| 90 | + " print(f\"- {r}\")\n", |
| 91 | + "\n", |
| 92 | + "print(\"\\n\" + \"=\"*50)\n", |
| 93 | + "print(\"FINAL REFINED OUTPUT\")\n", |
| 94 | + "print(\"=\"*50)\n", |
| 95 | + "print(final_output)" |
| 96 | + ] |
| 97 | + } |
| 98 | + ], |
| 99 | + "metadata": { |
| 100 | + "kernelspec": { |
| 101 | + "display_name": "reflection_agent", |
| 102 | + "language": "python", |
| 103 | + "name": "python3" |
| 104 | + }, |
| 105 | + "language_info": { |
| 106 | + "codemirror_mode": { |
| 107 | + "name": "ipython", |
| 108 | + "version": 3 |
| 109 | + }, |
| 110 | + "file_extension": ".py", |
| 111 | + "mimetype": "text/x-python", |
| 112 | + "name": "python", |
| 113 | + "nbconvert_exporter": "python", |
| 114 | + "pygments_lexer": "ipython3", |
| 115 | + "version": "3.12.3" |
| 116 | + } |
| 117 | + }, |
| 118 | + "nbformat": 4, |
| 119 | + "nbformat_minor": 5 |
| 120 | +} |
0 commit comments