|
| 1 | +# Simple Plant Care AI Agent |
| 2 | + |
| 3 | +A simple FastAPI-based plant care AI assistant powered by the OpenAI Agents SDK. Just provide a plant name and get personalized care advice! |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- 🌱 **Simple Plant Care Agent**: Get care advice for any plant by name |
| 8 | +- 🛠️ **One Tool**: Basic plant care database with common houseplants |
| 9 | +- 🚀 **FastAPI Backend**: Modern, fast API with automatic docs |
| 10 | +- 📚 **Interactive API Docs**: Built-in Swagger UI at `/docs` |
| 11 | +- 🎯 **Minimal Dependencies**: Bare bones implementation following OpenAI Agents SDK |
| 12 | + |
| 13 | +## Quick Start |
| 14 | + |
| 15 | +### Prerequisites |
| 16 | + |
| 17 | +- Python 3.11+ |
| 18 | +- OpenAI API key |
| 19 | + |
| 20 | +### Installation |
| 21 | + |
| 22 | +1. **Clone the repository** |
| 23 | + |
| 24 | + ```bash |
| 25 | + git clone <repository-url> |
| 26 | + cd empower-plant-agent-demo |
| 27 | + ``` |
| 28 | + |
| 29 | +2. **Set up environment variables** |
| 30 | + |
| 31 | + ```bash |
| 32 | + export OPENAI_API_KEY=sk-your-api-key-here |
| 33 | + ``` |
| 34 | + |
| 35 | +3. **Install dependencies** |
| 36 | + |
| 37 | + ```bash |
| 38 | + pip install -r requirements.txt |
| 39 | + ``` |
| 40 | + |
| 41 | +4. **Run the application** |
| 42 | + ```bash |
| 43 | + python main.py |
| 44 | + ``` |
| 45 | + |
| 46 | +The API will be available at `http://localhost:8000` with interactive docs at `http://localhost:8000/docs`. |
| 47 | + |
| 48 | +## Usage |
| 49 | + |
| 50 | +### API Endpoint |
| 51 | + |
| 52 | +**POST** `/api/v1/plant-care` |
| 53 | + |
| 54 | +Request body: |
| 55 | + |
| 56 | +```json |
| 57 | +{ |
| 58 | + "plant_name": "pothos" |
| 59 | +} |
| 60 | +``` |
| 61 | + |
| 62 | +Response: |
| 63 | + |
| 64 | +```json |
| 65 | +{ |
| 66 | + "response": "🌱 **Pothos Care Guide**\n\n**Watering**: Water when top inch of soil is dry (every 1-2 weeks)\n**Light**: Bright, indirect light\n**Pro Tip**: Very forgiving plant, great for beginners. Can tolerate low light.\n\n**General Care Reminders**:\n• Check soil moisture before watering\n• Ensure good drainage\n• Watch for signs of overwatering (yellow leaves)\n• Rotate plant occasionally for even growth", |
| 67 | + "agent_name": "PlantCareAgent" |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +### Direct Python Usage |
| 72 | + |
| 73 | +```python |
| 74 | +import asyncio |
| 75 | +from app.agents.simple_plant_agent import process_plant_query |
| 76 | + |
| 77 | +async def main(): |
| 78 | + advice = await process_plant_query("snake plant") |
| 79 | + print(advice) |
| 80 | + |
| 81 | +asyncio.run(main()) |
| 82 | +``` |
| 83 | + |
| 84 | +### Example with curl |
| 85 | + |
| 86 | +```bash |
| 87 | +curl -X POST "http://localhost:8000/api/v1/plant-care" \ |
| 88 | + -H "Content-Type: application/json" \ |
| 89 | + -d '{"plant_name": "monstera"}' |
| 90 | +``` |
| 91 | + |
| 92 | +## Supported Plants |
| 93 | + |
| 94 | +The agent has specific care information for: |
| 95 | + |
| 96 | +- Pothos |
| 97 | +- Snake Plant |
| 98 | +- Monstera |
| 99 | +- Fiddle Leaf Fig |
| 100 | +- Peace Lily |
| 101 | +- Rubber Plant |
| 102 | +- Succulents |
| 103 | + |
| 104 | +For other plants, it provides general care advice and suggests trying the supported plants. |
| 105 | + |
| 106 | +## Project Structure |
| 107 | + |
| 108 | +``` |
| 109 | +app/ |
| 110 | +├── agents/ |
| 111 | +│ └── simple_plant_agent.py # Main agent with OpenAI Agents SDK |
| 112 | +├── tools/ |
| 113 | +│ └── simple_plant_tool.py # Plant care tool/function |
| 114 | +└── api/ |
| 115 | + ├── models.py # Pydantic request/response models |
| 116 | + └── routes.py # FastAPI routes |
| 117 | +
|
| 118 | +main.py # FastAPI application entry point |
| 119 | +simple_example.py # Direct usage example |
| 120 | +config.py # Configuration management |
| 121 | +``` |
| 122 | + |
| 123 | +## Configuration |
| 124 | + |
| 125 | +Set these environment variables: |
| 126 | + |
| 127 | +- `OPENAI_API_KEY`: Your OpenAI API key (required) |
| 128 | +- `light_model`: Model for the agent (default: "gpt-4o-mini") |
| 129 | +- `API_HOST`: API host (default: "0.0.0.0") |
| 130 | +- `PORT`: API port (default: 8000) |
| 131 | + |
| 132 | +## Development |
| 133 | + |
| 134 | +Run the simple example: |
| 135 | + |
| 136 | +```bash |
| 137 | +python simple_example.py |
| 138 | +``` |
| 139 | + |
| 140 | +Check the API docs: |
| 141 | + |
| 142 | +```bash |
| 143 | +python main.py |
| 144 | +# Visit http://localhost:8000/docs |
| 145 | +``` |
| 146 | + |
| 147 | +## OpenAI Agents SDK |
| 148 | + |
| 149 | +This project follows the [OpenAI Agents SDK](https://openai.github.io/openai-agents-python/) patterns: |
| 150 | + |
| 151 | +- **Agent**: Simple plant care assistant with instructions |
| 152 | +- **Tool**: Function tool for plant care advice |
| 153 | +- **Runner**: Handles the agent execution loop |
| 154 | + |
| 155 | +The implementation is minimal and focused, demonstrating the core concepts without complexity. |
0 commit comments