A multi-agent AI system that collaboratively solves competitive programming problems using iterative refinement with brute-force validation.
Multi-Agent Programming Problem Solver was originally developed as a starter kit for Meta Hacker Cup and similar competitive programming contests. It demonstrates a sample strategy that contestants can experiment with and build upon.
The system employs three specialized AI agents working in concert:
- TesterAgent generates small test cases
- BruteAgent creates a correct but inefficient solution
- OptimalAgent iteratively develops an efficient solution, validated against the brute force output
This approach ensures correctness through differential testing while achieving optimal time complexity through AI-guided iteration.
- Python 3.8 or higher
- pip package manager
git clone <repository-url>
cd temp-agentspip install -r requirements.txtThis installs:
langchain- Multi-agent frameworklangchain-google-genai- Google Gemini integration (FREE tier)pyyaml- Configuration management
Google Gemini (FREE)
- Visit: https://aistudio.google.com/app/apikey
- Click "Create API Key"
- Copy the generated key (starts with
AIza...)
Edit config.yaml:
api_keys:
# Google Gemini API Key - FREE TIER AVAILABLE!
google: "AIza...your-google-api-key"The system uses FREE Google Gemini models. Default configuration:
models:
tester_agent: "google:gemini-2.5-flash"
brute_agent: "google:gemini-2.5-flash"
optimal_agent: "google:gemini-2.5-flash"Check https://ai.google.dev/gemini-api/docs/rate-limits for latest rate limits and free-tier quota.
google:gemini-2.5-flash- Fast, efficient (250 free requests/day)google:gemini-2.5-flash-lite- Faster, cheaper (1000 free requests/day)google:gemini-2.5-pro- Most capable (100 free requests/day)
execution:
max_optimal_attempts: 5 # Maximum retry attempts
timeout_seconds: 30 # Code execution timeoutoutput:
workspace_dir: "./workspace" # Output directory
preserve_intermediate: true # Keep all generated filesCreate or edit PROBLEM.txt with your problem statement:
Given an array of integers, find the maximum sum of any contiguous subarray.
Input Format:
- First line: n (size of array)
- Second line: n space-separated integers
Output Format:
- Single integer: maximum subarray sum
Constraints:
- 1 <= n <= 10^5
- -10^4 <= array[i] <= 10^4
Example:
Input:
5
-2 1 -3 4 -1
Output:
4
Explanation: The subarray [4] has the maximum sum of 4.
python main.pyWhat Happens:
- Loads Problem - Reads
PROBLEM.txt - Generates Test Cases - TesterAgent creates 3-5 small test inputs
- Creates Brute Force - BruteAgent generates a correct O(nΒ²-nΒ³) solution
- Executes Brute Force - Saves expected outputs
- Optimizes Solution - OptimalAgent attempts efficient O(n) solution
- Validates & Retries - Compares outputs, retries with feedback if needed
- Saves Results - Generates
workspace/results.jsonfor the viewer
Live Progress Indicators:
β Generating test cases with TesterAgent... (00:03)
β Generating brute force solution with BruteAgent... (00:05)
β Ή Generating optimal solution (attempt 1/5)... (00:04)
python -m http.server 8000Then open: http://localhost:8000/viewer.html
(HTTP server needed to avoid CORS restrictions)
All files saved to workspace/ (configurable):
workspace/
βββ small_inputs.txt # Generated test cases
βββ small_outputs.txt # Expected outputs (from brute force)
βββ brute.py # Brute force solution
βββ optimal_attempt_1.py # First attempt at optimal solution
βββ optimal_attempt_1_output.txt # Output from first attempt
βββ optimal_attempt_2.py # Second attempt (if needed)
βββ optimal_attempt_2_output.txt
βββ ... # Up to 10 attempts
βββ optimal.py # Final solution
βββ results.json # Complete metadata for viewer
temp-agents/
βββ PROBLEM.txt # Your problem statement (REQUIRED)
βββ config.yaml # Configuration file
βββ main.py # Entry point
βββ orchestrator.py # Multi-agent coordinator
βββ viewer.html # Web-based results viewer
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ QUICKSTART.md # Quick reference guide
βββ LICENSE # MIT License
βββ agents/
β βββ __init__.py
β βββ tester_agent.py # Test case generator
β βββ brute_agent.py # Brute force solution generator
β βββ optimal_agent.py # Optimal solution generator
βββ utils/
β βββ __init__.py
β βββ executor.py # Code execution utility
β βββ comparator.py # Output comparison utility
β βββ progress.py # Live progress indicators
βββ workspace/ # Generated files (gitignored)
βββ ...
Contributions are welcome! This is a starter kit meant to be extended and improved. Ideas on how you can extend it is given in the section below.
- Add WebSearchAgent - Allow models to search and learn algorithm approaches on the fly while solving problems
- Enhance prompts - Include problem-specific hints (DP, greedy, graph) and complexity targets in agent system prompts
- Create specialized agents - Add DebugAgent (analyzes failures), ValidatorAgent (checks logic), or ComplexityAgent (estimates time/space)
- Provide runtime feedback - Feed execution time, memory usage, and stack traces to OptimalAgent for faster iteration
- Parallel solution generation - Create multiple approaches (DP, greedy, binary search) simultaneously and pick the fastest correct one
- Problem-specific models - Detect problem type and choose appropriate models (lighter for practice, stronger for competition)
- Add support for more programming languages - Extend beyond Python to support C++, Java, Rust, etc.
- Implement parallel test execution - Run multiple test cases simultaneously for faster validation
- Add complexity analysis display - Show time/space complexity analysis in the viewer
- Support for interactive problems - Handle problems requiring interaction with a judge
- Multi-file solutions - Support projects with multiple modules and dependencies
- Custom test case input - Allow users to provide their own test cases
MIT License
Copyright (c) 2025 Nikita Agarwal, Nalin Abrol, Manas Kumar Verma, Nikhil Tadigopulla, Vivek Verma
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
- LangChain - Multi-agent framework
- Google - Free Gemini API access
- FlamesBlue - Beautiful web viewer
- KaTeX - LaTeX rendering
- Prism.js - Syntax highlighting
- Meta - Inspiration from Hacker Cup
- Google Gemini API: https://ai.google.dev/
- LangChain Documentation: https://python.langchain.com/
- Meta Hacker Cup: https://www.facebook.com/codingcompetitions/hacker-cup
- FlamesBlue: https://www.flamesblue.com
Built with β€οΈ for the competitive programming community
Starter kit for Meta Hacker Cup and similar competitions
Thanks to FlamesBlue for building the beautiful web viewer!
