Analyze, optimize, and enhance your AI agent configurations with AI-powered insights
- π― Overview
- β¨ Key Features
- ποΈ Architecture
- π οΈ Technology Stack
- π Quick Start
- π Usage Guide
- π§ Development
- π API Documentation
- π€ Contributing
- π License
ContextOptimizer is an intelligent context engineering assistant designed specifically for Multi-Agent Systems (MAS). It addresses the critical challenge of optimizing System Prompts and tool return information to ensure clear, coherent, and efficient context flow between agents.
Multi-Agent Systems often suffer from:
- Context Logic Breakdown: Unclear communication between agents
- Suboptimal System Prompts: Vague instructions leading to poor performance
- Inconsistent Tool Information: Unstructured data causing confusion
- Manual Optimization: Time-consuming trial-and-error approach
ContextOptimizer provides:
- Automated Analysis: AI-powered evaluation of agent configurations
- Intelligent Optimization: Data-driven recommendations for improvement
- Coordinated Enhancement: Simultaneous optimization of prompts and tools
- Actionable Insights: Ready-to-implement solutions
- Automatically identify context breakage issues in multi-agent conversations
- 5-dimensional evaluation system (Prompt Clarity, Context Flow, Tool Integration, Error Handling, Performance)
- Priority-based issue classification with detailed impact analysis
- Simultaneous optimization of system prompts and tool return formats
- Three optimization levels: Conservative, Balanced, Aggressive
- Focus area customization for targeted improvements
- Ready-to-use optimized agent configurations
- Detailed implementation guides with expected improvements
- Export functionality for seamless integration
- Learn from successful optimization patterns
- Apply proven strategies to new configurations
- Continuous improvement through AI feedback
graph TB
subgraph "Frontend (Next.js)"
A[Upload Interface] --> B[Analysis Dashboard]
B --> C[Optimization Results]
C --> D[Export & Download]
end
subgraph "Backend (FastAPI)"
E[API Gateway] --> F[Session Management]
F --> G[File Processing]
G --> H[Context Evaluator]
H --> I[Context Optimizer]
end
subgraph "AI Services"
J[OpenAI API]
K[Anthropic API]
end
subgraph "Storage"
L[Local File System]
M[Session Data]
N[Analysis Results]
end
A --> E
I --> J
I --> K
F --> L
H --> M
I --> N
- Framework: FastAPI 0.110+ (Python 3.12+)
- AI Integration: OpenAI API, Anthropic API
- Data Processing: Pydantic for validation, JSON for storage
- Session Management: File-based with UUID tracking
- Testing: Pytest with async support
- Framework: Next.js 15.3+ with React 19
- UI Components: Tailwind CSS + Headless UI
- Type Safety: TypeScript 5.7+
- State Management: React hooks with local state
- Build Tools: Turbopack for fast development
- Deployment: Docker containerization
- Development: Hot reload for both frontend and backend
- Storage: Local file system with structured directories
- Logging: Structured logging with configurable levels
- Python 3.12+ with pip or uv
- Node.js 18+ with npm
- OpenAI API Key (required for AI analysis)
- Docker (optional, for containerized deployment)
# 1. Clone the repository
git clone https://github.com/lml2468/ContextOptimizer.git
cd ContextOptimizer
# 2. Set up environment variables
cp .env.example .env
# Edit .env with your OpenAI API key
# 3. Build and run with Docker Compose
docker-compose up -d
# 4. Access the application
# Frontend: http://localhost:3000
# Backend API: http://localhost:8000
# 1. Clone the repository
git clone https://github.com/lml2468/ContextOptimizer.git
cd ContextOptimizer
# 2. Set up backend
cd backend
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
pip install uv
uv pip install -e .
# 3. Set up frontend
cd ../frontend
npm install
# 4. Set up environment variables
cp .env.example .env
# Edit .env with your OpenAI API key
# 5. Start development servers
# Terminal 1 (Backend)
cd backend
python start_backend.py
# Terminal 2 (Frontend)
cd frontend
npm run dev
# 6. Access the application
# Frontend: http://localhost:3000
# Backend API: http://localhost:8000
# Use the provided development script
chmod +x scripts/dev.sh
./scripts/dev.sh setup # Setup both environments
./scripts/dev.sh dev # Start both servers
Prepare two JSON files:
agents_config.json - Agent configurations:
[
{
"agent_id": "supervisor",
"agent_name": "Supervisor Agent",
"version": "1.0",
"system_prompt": "You are a supervisor agent...",
"tools": [
{
"name": "planning",
"description": "Create and manage execution plans"
}
]
}
]
messages_dataset.json - Conversation history:
{
"messages": [
{
"content": "Hello, I need help with...",
"type": "human",
"name": "user"
},
{
"content": "I'll help you with that...",
"type": "ai",
"name": "supervisor"
}
]
}
- Upload Files: Navigate to the sessions page and upload your JSON files
- Start Analysis: Click "Start Analysis" to begin the AI-powered evaluation
- Review Results: Examine the 5-dimensional analysis report with priority issues
- Generate Optimization: Click "Generate Optimization" from the analysis page
- Review Recommendations: Examine optimized system prompts and tool formats
- Apply Changes: Copy optimized configurations to your system
- Download Reports: Export complete analysis and optimization reports
- Update Agent Configs: Replace system prompts with optimized versions
- Standardize Tool Formats: Implement recommended tool return structures
- Monitor Performance: Track improvements in agent coordination
- Iterate: Re-analyze and optimize as your system evolves
ContextOptimizer/
βββ backend/ # FastAPI backend
β βββ app/
β β βββ api/ # API routes
β β βββ core/ # Business logic
β β βββ models/ # Data models
β β βββ services/ # Service layer
β β βββ utils/ # Utilities
β βββ tests/ # Test files
β βββ test_data/ # Sample data
βββ frontend/ # Next.js frontend
β βββ src/
β β βββ app/ # App router pages
β β βββ components/ # React components
β β βββ types/ # TypeScript types
β β βββ utils/ # Utility functions
β βββ public/ # Static assets
βββ scripts/ # Development scripts
βββ docker-compose.yml # Docker configuration
βββ Dockerfile # Container definition
# Backend tests
cd backend
source venv/bin/activate
python -m pytest tests/ -v
# Frontend type checking
cd frontend
npm run type-check
# Frontend linting
npm run lint
# Setup development environment
./scripts/dev.sh setup
# Start both servers
./scripts/dev.sh dev
# Run tests
./scripts/dev.sh test
# Build for production
./scripts/dev.sh build
# Clean development files
./scripts/dev.sh clean
Once the backend is running, access the interactive API documentation:
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
POST /api/v1/upload
- Upload agent configuration and message filesPOST /api/v1/analyze
- Start context analysisGET /api/v1/session/{session_id}/evaluation
- Get analysis resultsPOST /api/v1/optimize/{session_id}
- Generate optimization recommendationsGET /api/v1/sessions
- List all analysis sessions
We welcome contributions from the community! Here's how you can help:
- Check existing issues to avoid duplicates
- Use the bug report template
- Include detailed reproduction steps
- Provide system information and logs
- Search existing feature requests
- Use the feature request template
- Explain the use case and benefits
- Provide mockups or examples if applicable
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature
- Follow coding standards: Use Black for Python, ESLint for TypeScript
- Write tests: Ensure good test coverage
- Update documentation: Include relevant documentation updates
- Commit with conventional commits:
feat: add amazing feature
- Push to your fork:
git push origin feature/amazing-feature
- Open a Pull Request: Use the PR template
- Code Style: Follow PEP 8 for Python, ESLint/Prettier for TypeScript
- Testing: Write unit tests for new features
- Documentation: Update README and API docs as needed
- Performance: Consider performance implications of changes
- Security: Follow security best practices
This project is licensed under the MIT License - see the LICENSE file for details.
- OpenAI for providing powerful language models
- FastAPI for the excellent Python web framework
- Next.js for the robust React framework
- Tailwind CSS for beautiful, responsive design
- The open-source community for inspiration and tools
- GitHub Issues: For bug reports and feature requests
- Discussions: For questions and community support
- Documentation: Check the docs for detailed guides
Made with β€οΈ by the ContextOptimizer Team
β Star us on GitHub if this project helped you!