Skip to main content

A Dual-State Agent Framework for reliable LLM code generation with guard-validated loops

Project description

AtomicGuard

CI codecov PyPI version Python versions License: MIT

A Dual-State Agent Framework for reliable LLM code generation.

New to AtomicGuard? Start with the Getting Started Guide.

Paper: Managing the Stochastic: Foundations of Learning in Neuro-Symbolic Systems for Software Engineering (Thompson, 2025)

Overview

AtomicGuard implements guard-validated generation loops that dramatically improve LLM reliability. The core abstraction is the Atomic Action Pair ⟨agen, G⟩ — coupling each generation action with a validation guard.

Key results (Yi-Coder 9B, n=50):

Task Baseline Guarded Improvement
Template 35% 90% +55pp
Password 82% 98% +16pp
LRU Cache 94% 100% +6pp

Installation

# From PyPI
pip install atomicguard

# From source
git clone https://github.com/thompsonson/atomicguard.git
cd atomicguard
uv venv && source .venv/bin/activate
uv pip install -e ".[dev,test]"

Quick Start

from atomicguard import (
    OllamaGenerator, SyntaxGuard, TestGuard,
    CompositeGuard, ActionPair, DualStateAgent,
    InMemoryArtifactDAG
)

# Setup
generator = OllamaGenerator(model="qwen2.5-coder:7b")
guard = CompositeGuard([SyntaxGuard(), TestGuard("assert add(2, 3) == 5")])
action_pair = ActionPair(generator=generator, guard=guard)
agent = DualStateAgent(action_pair, InMemoryArtifactDAG(), rmax=3)

# Execute
artifact = agent.execute("Write a function that adds two numbers")
print(artifact.content)

See examples/ for more detailed usage, including a mock example that works without an LLM.

Benchmarks

Run the simulation from the paper:

python -m benchmarks.simulation --model yi-coder:9b --trials 50 --task all --output results/results.db --format sqlite

# Generate report
python -m benchmarks.simulation --visualize --output results/results.db --format sqlite

Project Structure

atomicguard/
├── src/atomicguard/     # Core library
├── benchmarks/          # Simulation code
├── docs/design/         # Design documents
├── examples/            # Usage examples
└── results/             # Generated reports & charts

Citation

@article{thompson2025managing,
  title={Managing the Stochastic: Foundations of Learning in Neuro-Symbolic Systems for Software Engineering},
  author={Thompson, Matthew},
  year={2025}
}

License

MIT

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

atomicguard-0.1.0.tar.gz (20.8 kB view details)

Uploaded Source

Built Distribution

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

atomicguard-0.1.0-py3-none-any.whl (26.3 kB view details)

Uploaded Python 3

File details

Details for the file atomicguard-0.1.0.tar.gz.

File metadata

  • Download URL: atomicguard-0.1.0.tar.gz
  • Upload date:
  • Size: 20.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for atomicguard-0.1.0.tar.gz
Algorithm Hash digest
SHA256 5604a1fe4be74f2e3ce7f9383245dd434e7e944438ebb12163ae5293f48411bf
MD5 b1abd931d310a3d38fa18d57475bbaef
BLAKE2b-256 79caa391b7271e443e07216b29e69020678a91a7bc6300aa6dde95a25f68f4ba

See more details on using hashes here.

File details

Details for the file atomicguard-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: atomicguard-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 26.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for atomicguard-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 f22d8662569a9bd6c839a6744f289633e4eb904088819ce81c0a5d0719f3ca39
MD5 fe09abc3f4bdcc9b421664d5f4de54e8
BLAKE2b-256 7eded4927d4bccc489781c70fa726b7b532f040f96f60c2361813a823d14a235

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