Skip to main content

A Knowledge-grounded framework for Autonomous Program Synthesis and Optimization

Project description

Kapso

A Knowledge-grounded framework for Autonomous Program Synthesis and Optimization

Learn more · Join Discord · Website

PyPI Discord GitHub commit activity Y Combinator X25

If you like this project, please support us by giving it a star ⭐

Early Access: Sign up for Leeroopedia and the hosted version of Kapso : Leeroopedia is a centralized ML & Data knowledge wiki with best practices and expert-level implementation patterns, written by Kapso and human experts.

Kapso Framework Architecture


News

  • Moltbook Agents 🦞: Build AI agents that optimize other agents and debate on Moltbook! Get started →

  • Technical Report: Our technical report is now available! Read the paper

  • #1 on MLE-Bench: KAPSO achieved top ranking among open-source systems on Kaggle ML competitions (MLE Benchmark).

    MLE-Bench Results
  • #1 on ALE-Bench: KAPSO achieved top ranking on long-horizon algorithmic discovery problems (ALE Benchmark).

    ALE-Bench Results

What is KAPSO?

KAPSO combines iterative experimentation with a knowledge base of best practices and tricks to discover code improvements.

It automates the cycle of designing, testing, and refining algorithms, eventually adapting the optimized solution for deployment on your chosen infrastructure.

The Four Pillars

Pillar Method Description
Evolve .evolve() Run iterative experiments to build software for a goal. Uses tree search, coding agents, and KG context to generate and refine solutions.
Learn .learn() Ingest knowledge from repositories, past solutions, or research results. Extracts patterns and best practices into the Knowledge Graph.
Research .research() Run deep web research to gather ideas and implementation references. Returns structured findings you can feed into the knowledge base or use as context for evolving solutions.
Deploy .deploy() Turn a solution into running software. Supports local execution, Docker containers, or cloud platforms like Modal.

🚀 Quickstart

Installation

From PyPI (recommended)

pip install leeroo-kapso

From source (for development or to access wiki knowledge data)

git clone https://github.com/leeroo-ai/kapso.git
cd kapso

# Pull Git LFS files (wiki knowledge data)
git lfs install
git lfs pull

# Create conda environment (recommended)
conda create -n kapso python=3.12
conda activate kapso

# Install in development mode
pip install -e .

Set Up API Keys

Create .env in project root:

OPENAI_API_KEY=your-openai-api-key
GOOGLE_API_KEY=your-google-api-key       # For Gemini
ANTHROPIC_API_KEY=your-anthropic-api-key # For Claude Code

Basic Usage

from kapso import Kapso, Source, DeployStrategy

# Initialize Kapso
# If you have a Knowledge Graph, pass kg_index; otherwise just use Kapso()
kapso = Kapso(kg_index="data/indexes/legal_contracts.index")

# Research: Gather domain-specific techniques from the web
# mode: "idea" | "implementation" | "study" (can pass multiple as list)
# depth: "light" | "deep" (default: "deep")

findings = kapso.research(
    "RLHF and DPO fine-tuning for legal contract analysis",
    mode=["idea", "implementation"],
    depth="deep",
)

# Learn: Ingest knowledge from repositories and research into the KG
kapso.learn(
    Source.Repo("https://github.com/huggingface/trl"),
    *findings.ideas,           # List[Source.Idea]
    *findings.implementations, # List[Source.Implementation]
    wiki_dir="data/wikis",
)

# Evolve: Build a solution through experimentation
# Use research results as context via to_string()
solution = kapso.evolve(
    goal="Fine-tune Llama-3.1-8B for legal clause risk classification, target F1 > 0.85",
    data_dir="./data/cuad_dataset", 
    output_path="./models/legal_risk_v1",
    context=[findings.to_string()],
)

# Deploy: Turn solution into running deployed_program
deployed_program = kapso.deploy(solution, strategy=DeployStrategy.MODAL)
deployed_program.stop()

For detailed integration steps, see the Quickstart and Installation guides.

Examples

Example Description
CUDA Optimization Optimize CUDA kernels for GPU performance
PyTorch Optimization Optimize PyTorch operations for speedup
ML Model Development Improve ML model accuracy on tabular data
Prompt Engineering Optimize prompts for better LLM performance
Agentic Scaffold Optimize agentic AI workflows

Supported Benchmarks

Benchmark Description
MLE-Bench Kaggle ML competitions — tabular, image, text, audio problems
ALE-Bench AtCoder algorithmic optimization — C++ solution generation

📚 Documentation & Support

Contributing

We welcome contributions! Please see our Contributing Guide for details on how to get started.

Citation

If you use Kapso in your research, please cite:

@misc{nadaf2026kapsoknowledgegroundedframeworkautonomous,
      title={KAPSO: A Knowledge-grounded framework for Autonomous Program Synthesis and Optimization}, 
      author={Alireza Nadafian and Alireza Mohammadshahi and Majid Yazdani},
      year={2026},
      eprint={2601.21526},
      archivePrefix={arXiv},
      primaryClass={cs.AI},
      url={https://arxiv.org/abs/2601.21526}, 
}

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

leeroo_kapso-0.1.2.tar.gz (403.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

leeroo_kapso-0.1.2-py3-none-any.whl (431.1 kB view details)

Uploaded Python 3

File details

Details for the file leeroo_kapso-0.1.2.tar.gz.

File metadata

  • Download URL: leeroo_kapso-0.1.2.tar.gz
  • Upload date:
  • Size: 403.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for leeroo_kapso-0.1.2.tar.gz
Algorithm Hash digest
SHA256 885db4bd0c4f674e6219b94aff5f8f152dcdc6429b35a56bc7e82937d6ea2cf4
MD5 ebe47c7598bb6f95c661f4d4cba79d07
BLAKE2b-256 973db7ccdba08ff8339147a651b7f79fcc11b7d91c2a6058b0590928d3d79c70

See more details on using hashes here.

File details

Details for the file leeroo_kapso-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: leeroo_kapso-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 431.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.19

File hashes

Hashes for leeroo_kapso-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 79423b347369968c751cbfa6c0597697b0b9d21463145d65e7ad3f51571a7661
MD5 763a3733abd8276ebbca19957b945b25
BLAKE2b-256 71d08fe6e6f150287b732ce37a2389c110e1b6713922caa5deca5ecaedf74527

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page