LangGraph-driven multi-agent system that turns natural-language problem statements into Answer Set Programming (ASP) code, validates it with MCP tools, and iterates until correct.
This project implements a multi-agent system that can:
- Convert natural language problem descriptions into ASP code
- Execute and validate the generated logic programs
- Iteratively refine solutions based on feedback
- Use MCP (Model Context Protocol) tools for enhanced capabilities
- Orchestrator:
ASPRunnerloads a problem, builds initialASPState, opens an MCP session viaMCPClientManager, compiles the graph, runs it, and exports results. - Agents and control flow:
create_asp_systembuilds two ReAct agents (solver with full MCP access; validator restricted tosolve_modelandadd_item).workflow.should_continueloops solver→validator until validated ormax_iterations. - State:
ASPStatekeys:problem_description,asp_code,messages,validation_history,iteration_count,max_iterations,is_validated,answer_set,statistics. - LLM/MCP:
build_llmconfig via env (Ollama-compatible OpenAI API by default). MCP tools loaded at runtime from a long-lived stdio session.
- Multi-agent architecture: Separate solver and validator agents
- Natural language interface: Describe problems in plain English
- Iterative refinement: Automatically improves solutions based on validation feedback
- MCP integration: Leverages external tools for enhanced problem-solving
- Web Interface: Interactive Streamlit-based UI for testing and experimentation
Install dependencies:
uv sync
uv pip install -e .Install MCP Solver:
# Clone the MCP Solver repository
git clone https://github.com/szeider/mcp-solver.git
cd mcp-solver
uv sync
source .venv/bin/activate
uv pip install -e ".[asp]" # Install asp solver
# Check the installation instructions in the MCP Solver READMESet up environment:
# Chat Model Configuration
PROVIDER=ollama # 'openrouter' or 'ollama'
MODEL_NAME=gpt-oss:20b
PROVIDER_BASE_URL=http://localhost:11434/v1
PROVIDER_API_KEY=ollama
TEMPERATURE=0.0
# Reasoning Configuration (for reasoning models)
# Can be: low, medium, high, true, or false
REASONING_LEVEL=false
# MCP Solver Configuration
MCP_SOLVER_ARGS=--directory,absolute_path_to_folder,run,mcp-solver-asp
MCP_SOLVER_COMMAND=uv
MCP_SOLVER_TRANSPORT=stdio
# Langsmith Configuration
LANGSMITH_API_KEY=kjbxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
LANGSMITH_TRACING=false
# General Configuration
MAX_ITERATIONS=5
LOG_LEVEL=INFO
EXPORT_PATH=resultsRun:
almasp -h
# Single run example:
almasp .\examples\graph_coloring.md- Results exported to
results/...(.jsonand generated.lp). - Logs written to
results/....log.
Run with Docker (no local installs):
cp .env.example .env # optional overrides
# Edit .env if needed:
# MODEL_NAME=gpt-oss:20b
# PROVIDER_BASE_URL=http://host.docker.internal:11434/v1
# PROVIDER_API_KEY=ollama
docker compose up --buildOpen:
Stop:
docker compose downNotes:
- Uses host.docker.internal to reach the host LLM; see “LLM backend (Ollama or OpenRouter)” for setup
- MCP Solver is preinstalled in the image; no host install needed
Run locally (optional, if you installed dependencies):
almasp-webappIf your Ollama server runs on a remote machine (not on the Docker host), you can create an SSH tunnel from inside the container so the app can access it at http://localhost:11434/v1:
ssh -L <11434>:<localhost>:<11434> <user>@<remote_server>- Problem Description: Enter your ASP problem in natural language
- Custom Prompts: Override default solver and validator system prompts
- Live Logging: Watch the agent’s reasoning process in real-time
- Results Viewer: See generated ASP code and JSON results
- Stop Control: Interrupt long-running executions
- Configuration: Adjust model, temperature, iterations, and more
Ollama (local):
- This project uses Ollama as the LLM backend by default. Ensure an Ollama server is running.
- Install Ollama from
https://ollama.comand start the server (on most systems it runs automatically). To start manually:
ollama serve- Pull or choose a local model:
ollama pull gpt-oss:20b- Optionally set the model via
.env:
PROVIDER=ollama
MODEL_NAME=gpt-oss:20b
# PROVIDER_BASE_URL=http://localhost:11434/v1
# PROVIDER_API_KEY=ollamaOpenRouter:
- Set the provider to OpenRouter via environment variables:
# .env or docker-compose environment
PROVIDER=openrouter
MODEL_NAME=openai/gpt-5 # or any model from https://openrouter.ai/models
PROVIDER_BASE_URL=https://openrouter.ai/api/v1
PROVIDER_API_KEY=sk-or-v1-xxxxxxxxxxxxxxxxxxxxxxxx- A small knowledge base about birds, exceptions (penguins, injuries), and derived properties (mobility, feathers). Determine which entities can fly, are mobile, and have feathers, and cite whether each conclusion comes from a default, an exception, or a direct fact.
Run:
almasp .\examples\birds_fly.md- A 4-node graph with specified edges. Find a valid 3-coloring such that adjacent nodes have different colors.
Run:
almasp .\examples\graph_coloring.mdUse the built-in scraper to download LPCP problem descriptions (defaults to years 2020–2025) into the lpcp_problems/ folder:
download-lpcpThis will create a structure like:
lpcp_problems/
lpcp-2020/
problem-1.md
problem-2.md
...
lpcp-2021/
...
After downloading, run the batch executor to solve each problem file. By default it scans lpcp_problems/ and processes problem-1.md and problem-2.md in each year folder:
almasp-batchCommon options:
--root PATH: root folder withlpcp-YYYYsubfolders (default:lpcp_problems)--years 2022,2023: restrict to specific years (comma-separated)--solver-prompt PATH: custom solver system prompt file--validator-prompt PATH: custom validator system prompt file--model NAME: LLM model override (otherwise usesMODEL_NAMEenv or default)--max-iterations N: max solver/validator iterations
Examples:
# Run only for 2022 and 2023
almasp-batch --years 2022,2023
# Use custom prompts
almasp-batch \
--solver-prompt prompts/solver_instructions.md \
--validator-prompt prompts/validator_instructions.md
# Override model and iterations
almasp-batch --model gpt-oss:20b --max-iterations 6Note: Ensure your environment variables (e.g., MODEL_NAME, PROVIDER_BASE_URL, PROVIDER_API_KEY, and MCP settings like MCP_SOLVER_ARGS) are configured as described above before running the batch.
src/almasp/- Core agent implementationexamples/- Sample problems and use casesprompts/- System prompts for different agent rolestests/- Tests
The system uses LangGraph for orchestration, check out the LangGraph docs for more.
# Tests
pytest- Model 404s: the
MODEL_NAMEis not available onPROVIDER_BASE_URL(pull or change the model). - MCP "Connection closed": re-check
MCP_SOLVER_ARGSabsolute path after--directoryand verify mcp-solver install.