Development Setup
This guide covers setting up a development environment for working on Robutler.
Prerequisites
- Python: 3.8 or higher
- Git: Latest version
- OpenAI API Key: For agent functionality
Environment Setup
1. Clone the Repository
# Clone the repository
git clone https://github.com/robutlerai/robutler.git
cd robutler-proxy
# Or clone your fork
git clone https://github.com/YOUR_USERNAME/robutler.git
cd robutler-proxy
2. Python Environment
Using venv (Recommended)
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On Linux/Mac:
source venv/bin/activate
# On Windows:
venv\Scripts\activate
# Upgrade pip
pip install --upgrade pip
3. Install Dependencies
4. Environment Variables
Create a .env file in the project root:
# Required for agent functionality
OPENAI_API_KEY=your-openai-api-key
# Optional Robutler API configuration
WEBAGENTS_API_KEY=rok_your-robutler-api-key
ROBUTLER_API_URL=https://robutler.ai
# Development settings
ROBUTLER_DEBUG=true
Development Tools
Code Formatting and Linting
Black (Code Formatting)
isort (Import Sorting)
flake8 (Linting)
Testing
Running Tests
# Run all tests
pytest
# Run with coverage
pytest --cov=robutler
# Run specific test file
pytest tests/test_agent.py
# Run tests with verbose output
pytest -v
Documentation
Building Documentation
IDE Configuration
VS Code
Recommended extensions: - Python - Black Formatter - isort - Flake8
VS Code settings (.vscode/settings.json):
{
"python.defaultInterpreterPath": "./venv/bin/python",
"python.formatting.provider": "black",
"python.linting.enabled": true,
"python.linting.flake8Enabled": true,
"python.testing.pytestEnabled": true,
"python.testing.pytestArgs": ["tests"],
"editor.formatOnSave": true,
"editor.codeActionsOnSave": {
"source.organizeImports": true
}
}
Running the Development Server
Basic Agent Server
# Create a simple test agent
from webagents.agent import RobutlerAgent
from webagents.server import RobutlerServer
agent = RobutlerAgent(
name="test-agent",
instructions="You are a helpful test assistant.",
credits_per_token=5
)
app = RobutlerServer(agents=[agent])
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="127.0.0.1", port=8000)
Common Development Tasks
Adding a New Tool
- Create the tool function:
from agents import function_tool
from webagents.server import pricing
@function_tool
@pricing(credits_per_call=1000)
def my_new_tool(input_text: str) -> str:
"""Description of what the tool does."""
# Implementation here
return f"Processed: {input_text}"
- Add to agent:
agent = RobutlerAgent(
name="test-agent",
instructions="You have access to custom tools.",
tools=[my_new_tool],
credits_per_token=5
)
- Test the tool:
# Test in development
messages = [{"role": "user", "content": "Use the new tool"}]
response = await agent.run(messages=messages)
print(response)
Adding New API Endpoints
from webagents.server import RobutlerServer
app = RobutlerServer()
@app.agent("/custom-endpoint")
@app.pricing(credits_per_token=10)
async def custom_agent(request):
"""Custom agent endpoint."""
messages = request.messages
# Process messages
return "Custom response"
Testing Changes
# Run tests for specific modules
pytest tests/test_agent.py -v
# Run integration tests
pytest tests/test_integration.py
# Check code formatting
black --check .
isort --check-only .
flake8 robutler/
Debugging
Enable Debug Logging
import logging
logging.basicConfig(level=logging.DEBUG)
# Or set environment variable
export ROBUTLER_DEBUG=true
Common Debug Tasks
# Test agent endpoint
curl -X POST http://localhost:8000/test-agent/chat/completions \
-H "Content-Type: application/json" \
-d '{"model": "test-agent", "messages": [{"role": "user", "content": "Hello"}]}'
# Check available tools
curl http://localhost:8000/test-agent
This covers the essential development setup needed to contribute to Robutler.