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# LLM Agent Builder - Cursor IDE Rules
|
| 2 |
+
|
| 3 |
+
## Project Overview
|
| 4 |
+
This is an LLM Agent Builder project that generates custom AI agents using Anthropic Claude or Hugging Face models. The project consists of:
|
| 5 |
+
- Python backend (FastAPI) for agent generation API
|
| 6 |
+
- React 19 frontend (Vite) for web UI
|
| 7 |
+
- CLI tool for command-line agent generation
|
| 8 |
+
- Docker deployment for Hugging Face Spaces
|
| 9 |
+
|
| 10 |
+
## Tech Stack
|
| 11 |
+
- **Backend**: Python 3.9+, FastAPI, Pydantic, Jinja2
|
| 12 |
+
- **Frontend**: React 19, Vite, Tailwind CSS
|
| 13 |
+
- **LLM Providers**: Anthropic Claude, Hugging Face
|
| 14 |
+
- **Testing**: pytest, mypy
|
| 15 |
+
- **Deployment**: Docker, Hugging Face Spaces
|
| 16 |
+
|
| 17 |
+
## Code Style & Standards
|
| 18 |
+
|
| 19 |
+
### Python
|
| 20 |
+
- Use type hints for all function parameters and return types
|
| 21 |
+
- Follow PEP 8 style guide
|
| 22 |
+
- Use f-strings for string formatting
|
| 23 |
+
- Maximum line length: 120 characters
|
| 24 |
+
- Use descriptive variable names
|
| 25 |
+
- Add docstrings for all public functions and classes
|
| 26 |
+
|
| 27 |
+
### Frontend (React/JavaScript)
|
| 28 |
+
- Use functional components with hooks
|
| 29 |
+
- Use modern React patterns (React 19 features)
|
| 30 |
+
- Prefer named exports over default exports
|
| 31 |
+
- Use Tailwind CSS for styling (custom CSS variables for theming)
|
| 32 |
+
- Follow React best practices (keys, proper state management)
|
| 33 |
+
|
| 34 |
+
### API Design
|
| 35 |
+
- Use RESTful conventions
|
| 36 |
+
- Validate all inputs with Pydantic models
|
| 37 |
+
- Return consistent JSON response formats
|
| 38 |
+
- Include proper HTTP status codes
|
| 39 |
+
- Implement rate limiting for production endpoints
|
| 40 |
+
|
| 41 |
+
## Project Structure
|
| 42 |
+
|
| 43 |
+
```
|
| 44 |
+
llm_agent_builder/ # Core package
|
| 45 |
+
- agent_builder.py # AgentBuilder class
|
| 46 |
+
- cli.py # CLI interface
|
| 47 |
+
- templates/ # Jinja2 templates
|
| 48 |
+
|
| 49 |
+
server/ # FastAPI backend
|
| 50 |
+
- main.py # API endpoints
|
| 51 |
+
- models.py # Pydantic models
|
| 52 |
+
- sandbox.py # Code execution sandbox
|
| 53 |
+
|
| 54 |
+
frontend/ # React frontend
|
| 55 |
+
- src/
|
| 56 |
+
- components/ # React components
|
| 57 |
+
- App.jsx # Main app
|
| 58 |
+
|
| 59 |
+
tests/ # Test suite
|
| 60 |
+
```
|
| 61 |
+
|
| 62 |
+
## Key Patterns
|
| 63 |
+
|
| 64 |
+
### Agent Generation
|
| 65 |
+
- Agents are generated using Jinja2 templates
|
| 66 |
+
- Support for multi-step workflows and tool integration
|
| 67 |
+
- Templates support both Anthropic and Hugging Face providers
|
| 68 |
+
|
| 69 |
+
### Error Handling
|
| 70 |
+
- Use try/except blocks with specific exception types
|
| 71 |
+
- Return meaningful error messages to users
|
| 72 |
+
- Log errors appropriately
|
| 73 |
+
- Fail fast and loud (never swallow exceptions)
|
| 74 |
+
|
| 75 |
+
### Security
|
| 76 |
+
- Validate all user inputs
|
| 77 |
+
- Use environment variables for secrets (never hardcode)
|
| 78 |
+
- Sandbox code execution with resource limits
|
| 79 |
+
- Rate limit API endpoints
|
| 80 |
+
|
| 81 |
+
### Testing
|
| 82 |
+
- Write tests for all business logic
|
| 83 |
+
- Use pytest fixtures for test setup
|
| 84 |
+
- Mock external API calls in tests
|
| 85 |
+
- Aim for high test coverage
|
| 86 |
+
|
| 87 |
+
## Common Tasks
|
| 88 |
+
|
| 89 |
+
### Adding a New Agent Feature
|
| 90 |
+
1. Update `agent_builder.py` with new parameters
|
| 91 |
+
2. Update Jinja2 templates if needed
|
| 92 |
+
3. Update Pydantic models in `server/models.py`
|
| 93 |
+
4. Add API endpoint in `server/main.py`
|
| 94 |
+
5. Update frontend form in `frontend/src/components/AgentForm.jsx`
|
| 95 |
+
6. Add tests in `tests/`
|
| 96 |
+
|
| 97 |
+
### Adding a New CLI Command
|
| 98 |
+
1. Add subcommand in `llm_agent_builder/cli.py`
|
| 99 |
+
2. Update help text and documentation
|
| 100 |
+
3. Add tests in `tests/test_cli.py`
|
| 101 |
+
|
| 102 |
+
### Updating Dependencies
|
| 103 |
+
1. Update `requirements.txt` for Python packages
|
| 104 |
+
2. Update `frontend/package.json` for Node packages
|
| 105 |
+
3. Update `pyproject.toml` if needed
|
| 106 |
+
4. Test thoroughly before committing
|
| 107 |
+
|
| 108 |
+
## Important Notes
|
| 109 |
+
|
| 110 |
+
- Always check if frontend/dist exists before serving static files
|
| 111 |
+
- Git must be installed in Dockerfile for Hugging Face Spaces compatibility
|
| 112 |
+
- Port 7860 is used for Hugging Face Spaces deployment
|
| 113 |
+
- Port 8000 is used for local development
|
| 114 |
+
- API endpoints are rate-limited (20/min generate, 10/min execute)
|
| 115 |
+
|
| 116 |
+
## When Making Changes
|
| 117 |
+
|
| 118 |
+
1. **Always** run tests before committing: `pytest`
|
| 119 |
+
2. **Always** check type hints: `mypy llm_agent_builder server`
|
| 120 |
+
3. **Always** ensure frontend builds: `cd frontend && npm run build`
|
| 121 |
+
4. **Always** test Docker build locally before pushing
|
| 122 |
+
5. **Always** update documentation if adding features
|
| 123 |
+
|
| 124 |
+
## Code Generation Guidelines
|
| 125 |
+
|
| 126 |
+
- Generate code that follows existing patterns
|
| 127 |
+
- Use the same naming conventions as the codebase
|
| 128 |
+
- Include error handling and validation
|
| 129 |
+
- Add appropriate comments for complex logic
|
| 130 |
+
- Ensure compatibility with Python 3.9+
|
| 131 |
+
|
| 132 |
+
## API Endpoints
|
| 133 |
+
|
| 134 |
+
- `POST /api/generate` - Generate a new agent
|
| 135 |
+
- `POST /api/execute` - Execute agent code in sandbox
|
| 136 |
+
- `GET /health` - Health check
|
| 137 |
+
- `GET /healthz` - Kubernetes health check
|
| 138 |
+
- `GET /docs` - API documentation (Swagger UI)
|
| 139 |
+
|
| 140 |
+
## Environment Variables
|
| 141 |
+
|
| 142 |
+
- `ANTHROPIC_API_KEY` - Required for Anthropic models
|
| 143 |
+
- `HUGGINGFACEHUB_API_TOKEN` - Required for Hugging Face models
|
| 144 |
+
- `ANTHROPIC_MODEL` - Optional, defaults to claude-3-5-sonnet-20241022
|
| 145 |
+
|
| 146 |
+
## Deployment
|
| 147 |
+
|
| 148 |
+
- Dockerfile uses multi-stage build
|
| 149 |
+
- Frontend is built in first stage
|
| 150 |
+
- Backend runs on Python 3.10
|
| 151 |
+
- Git must be available for Hugging Face Spaces dev-mode
|
| 152 |
+
|