Skip to content

Conversation

@lewashby
Copy link

@lewashby lewashby commented Jul 2, 2025

Overview

This PR introduces two major enhancements to the MCP Solver framework:

  1. Integration of Answer Set Programming (ASP) with Clingo
  2. Support for Groq as an LLM provider

These changes expand the solver’s capabilities, improve flexibility for end-users, and modernize the LLM integration layer.

1. ASP/Clingo Integration

  • New ASP Module:

Added a dedicated asp module under src/mcp_solver/asp/ for handling ASP-based problem solving.

  • Clingo Backend:

Implemented Clingo as the primary ASP solver, including environment setup, model management, real-time syntax and grounding validation, and solution extraction.

  • Testing:

Added test setups and example problems for ASP in the tests/problems/asp/ directory.

2. Groq LLM Provider Integration

  • LLM Factory Update:

Extended the LLM factory to support Groq as an additional provider, alongside existing options.

Additional Notes

  • Documentation:

Updated relevant documentation and instructions for both ASP/Clingo and Groq integration.

  • Backward Compatibility:

All existing solvers and LLM providers remain supported; these changes are additive.

  • Testing:

New and updated tests ensure coverage for the new features.

lewashby added 16 commits June 30, 2025 11:10
- Added new ASP module for clingo integration, including model management and error handling.
- Implemented basic templates for ASP rules and facts generation.
- Introduced test setup for validating ASP functionality.
- Updated pyproject.toml to include clingo as a dependency and added a new script for test setup.
- Added instructions and review prompts for ASP usage.
- Implemented a custom exception for model validation errors.
- Enhanced the ASPModelManager with incremental validation for adding, deleting, and replacing items.
- Updated test setup to verify ASP mode installation and functionality, including configuration checks and clingo dependency validation.
- Improved basic templates for generating ASP facts and rules.
- Updated the ASP module to include a docstring for clarity.
- Integrated ASPModelManager into the server logic for handling ASP mode.
- Added conditional logging for ASP mode usage in the server.
- Updated mode folder handling to include ASP.
- Updated the ASP instructions to provide a comprehensive quick start guide, detailing model structure, operations, and best practices.
- Enhanced the ASP solution review template to include structured guidelines for evaluating correctness and optimality.
- Added ASP-related commands in the server to support model management, including item addition, deletion, and fetching current content.
- Introduced ASP problem directory and updated test configuration to include ASP-related paths.
- Enhanced the unified test runner documentation to reflect ASP integration.
- Added ASP-specific solver configuration for handling commands and results.
- Created a new example problem for ASP to demonstrate usage and expected output.
- Included mcp-solver-asp in the pyproject.toml to support the new ASP solver integration.
- Introduced ASP as a new solver mode in the client configuration.
- Updated argument parsing to include ASP mode in the command line options.
- Enhanced server logic to handle ASP mode, including logging and description retrieval.
- Modified test setup to recognize ASP as a valid solver type.
- Introduced a new markdown file detailing the simple path coloring problem for ASP.
- Included problem description, ASP encoding, and expected output format to aid in understanding and testing.
… coloring example

- Revised the problem description for clarity.
- Updated INSTALL.md to include Groq as a supported platform with its corresponding API key.
- Modified client.py to recognize Groq in the model code argument parsing.
- Enhanced llm_factory.py to integrate ChatGroq for model handling.
- Updated test_setup.py to include langchain_groq as a dependency in the test environment.
- Added necessary changes to pyproject.toml to include langchain-groq as a required package.
- Updated README.md to include usage instructions for the new ASP mode in the run-test command.
- Removed clingo from the main dependencies and added it to a new optional 'asp' section in pyproject.toml.
- Updated the README.md to include detailed information about the new ASP mode, its features, and usage instructions.
- Updated version in pyproject.toml to 3.4.0.
- Added new features to CHANGELOG, including full integration of Answer Set Programming (ASP) via clingo API and Groq LLM provider integration.
- Added "asp" to the PromptMode type definition in prompt_loader.py.
- Updated test_setup.py to include ASP prompts for testing.
- Created a new markdown file for the University Course Scheduling problem in ASP format.
- Revised the simple path coloring problem description for clarity.
@lewashby
Copy link
Author

lewashby commented Jul 4, 2025

Hello @szeider, I’ve submitted a pull request with some proposed changes related to your paper. I’d appreciate it if you could take a look when you have the time. Thank you!

lewashby added 2 commits July 25, 2025 15:53
- Added a new error handling module for ASP, providing structured error reporting and context-aware messages.
- Integrated enhanced error handling into the ASPModelManager for improved validation and solving processes.
- Introduced a solution module to standardize the extraction and formatting of ASP solver results.
- Updated installation documentation to include the new ASP setup command.
- Expanded test coverage for ASP error handling and model management functionalities.
@szeider
Copy link
Owner

szeider commented Aug 24, 2025

Pull Request #7 Change Request

Thank you for this excellent contribution adding ASP/Clingo support! The integration is well-architected and follows the existing patterns nicely. Before merging, please address the following items:

Required Changes

  1. Remove Groq LLM Integration
    Please remove all Groq-related changes to keep this PR focused on ASP/Clingo support only. This includes:

    • Remove langchain-groq from dependencies in pyproject.toml
    • Remove Groq references from src/mcp_solver/client/llm_factory.py
    • Remove GR/GQ platform code references from INSTALL.md and README.md
    • Remove Groq from CHANGELOG.md entry

    You're welcome to submit Groq support as a separate PR later, which would allow proper testing and review.

  2. Fix syntax warning in src/mcp_solver/asp/error_handling.py:45

    # Current (causes SyntaxWarning):
    enhanced_message += f"\n\Here are more error details:\n{context}"
    
    # Please change to:
    enhanced_message += f"\nHere are more error details:\n{context}"
  3. Test Problems Requirement
    Please replace the existing problems and provide exactly 6 ASP-specific problems in tests/problems/asp/ that showcase ASP's unique strengths:

    Remove current problems (too similar to existing solver problems):

    • simple_path_coloring.md - We already have graph coloring problems
    • university_course_scheduling.md - We already have scheduling problems

    Add 6 new ASP-specific problems:

    • test.md - A trivial test problem
    • 5 more problems that demonstrate ASP's unique capabilities (one must be UNSATISFIABLE)

    Suggested ASP-specific problems that other solvers can't handle well:

    • Default reasoning (e.g., "birds fly by default unless they are penguins")
    • Stable models with negation as failure (e.g., "eligible for discount unless explicitly excluded")
    • Recursive aggregates (e.g., company control through recursive ownership)
    • Weak constraints optimization (e.g., preference-based scheduling with :~ syntax)
    • Diagnostic reasoning (e.g., finding minimal fault explanations)
    • Frame problem (e.g., planning with inertia - things stay the same unless changed)
    • UNSAT example: Contradictory default rules or unstable program

    These problems should demonstrate features unique to ASP that are difficult or impossible to express in MiniZinc, PySAT, or Z3.

    Important Note: When adding problems with advanced ASP constructs (weak constraints :~, aggregates, defaults, etc.), please also update the prompts/asp/instructions.md file to include guidance and examples for these constructs. This will help the LLM agent effectively handle these advanced ASP features.

  4. Code Quality
    Please run the following before final submission:

    uv run ruff format .
    uv run ruff check --fix .

    This will ensure consistent formatting and fix any linting issues.

Notes

  • Once Groq is removed, this becomes a clean, single-feature PR for ASP/Clingo support
  • The ASP implementation itself is excellent and ready to merge after these changes
  • Consider submitting Groq support as a separate PR if desired

Thanks again for this valuable contribution to the project!

Applied automatic formatting to the codebase using `uv run ruff format .`
No functional changes were made, only style adjustments.
- Removed references to Groq from CHANGELOG, INSTALL.md, and README.md.
- Updated client.py and llm_factory.py to exclude Groq from supported platforms and model handling.
- Adjusted dependencies in pyproject.toml and test_setup.py to eliminate langchain_groq.
- Added a "status" key to the error response in format_solution_error for clarity.
- Introduced a "success" flag in the solution export process to ensure consistent server communication.
- Added critical index stability guidelines for error handling in ASP instructions.
- Introduced new problem scenarios for ASP, including birds' flight capabilities, company control relationships, package status contradictions, party invitations, shift assignments, and a trivial test case.
- Removed the outdated simple path coloring problem and university course scheduling scenario from the test suite.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants