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

If you use this framework in your research, please cite the paper:

Thompson, M. (2025). Managing the Stochastic: Foundations of Learning in Neuro-Symbolic Systems for Software Engineering. arXiv preprint arXiv:2512.20660.

@article{thompson2025managing,
  title={Managing the Stochastic: Foundations of Learning in Neuro-Symbolic Systems for Software Engineering},
  author={Thompson, Matthew},
  journal={arXiv preprint arXiv:2512.20660},
  year={2025},
  url={[https://arxiv.org/abs/2512.20660](https://arxiv.org/abs/2512.20660)}
}

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-1.1.0.tar.gz (33.3 kB view details)

Uploaded Source

Built Distribution

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

atomicguard-1.1.0-py3-none-any.whl (42.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: atomicguard-1.1.0.tar.gz
  • Upload date:
  • Size: 33.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for atomicguard-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c90c8429f0f9ad78d9ad726d09bbdacaf2857e05c248ac273bc3f881f929c07c
MD5 c8e903d670c160ae0c31dbfbe4243e1f
BLAKE2b-256 4ebfa07702910d639f4f48c0a0b11ccaf4f385edaa22886346972fdeda9dfa97

See more details on using hashes here.

Provenance

The following attestation bundles were made for atomicguard-1.1.0.tar.gz:

Publisher: release.yml on thompsonson/atomicguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: atomicguard-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 42.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for atomicguard-1.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ad08845a250b0e9d76d3b97802bf4c0d1e581b78e9814916714a9f5d1f3df8c
MD5 eab37cf19c74aaa21ecf3f3d157c3fa3
BLAKE2b-256 366a7b87b107e6cfb68cf39bcb66fc16b1e5dd72fa4d96d80e19d2ebb778205e

See more details on using hashes here.

Provenance

The following attestation bundles were made for atomicguard-1.1.0-py3-none-any.whl:

Publisher: release.yml on thompsonson/atomicguard

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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