Skip to content

About

No description, website, or topics provided.

Resources

Contributing

Stars

9 stars

Watchers

2 watching

Forks

Repository files navigation

Rules as Programs

Instead of hoping your agent follows the rules, let the rules check your agent.

You give your coding agent rules. It still ignores them.

Rules as Programs gives those rules a life of their own. Each rule becomes a function that checks the agent's work as it runs. The agent doesn't have to remember to check the rule, or decide whether to invoke it.

Write a rule in natural language, turn it into a program, and let it check the agent's responses or tool calls. When it flags something, inspect the exact input. If the rule gets it wrong, revise it and test it against saved examples.

Watch the demo · Get started · Write your first rule

See a rule come to life

Suppose your rule is: Never use rsync to sync code; use GitHub instead.

The agent invokes:

rsync -av src/ server:/app/src/

Your rule checks the tool invocation and flags the source-code transfer. The intended workflow is to push the changes to GitHub, then pull them on the other machine. Even if the agent forgets the rule, the rule still checks the command.

RAP reports findings without blocking or changing the agent's work. You review the findings and decide what needs attention.

Get started

You need Python 3.10+ and Codex with lifecycle hooks. macOS has the full menu-bar app and Rule Editor; Linux and Windows provide a reduced tray and CLI.

From your project directory, install RAP and initialize it:

python -m pip install "git+https://github.com/programasweights/rules-as-programs.git" \
  --extra-index-url https://pypi.programasweights.com/simple/
rap init
  1. Restart Codex, open /hooks, and trust the RAP hooks. Trust the project's .codex/ configuration when prompted.
  2. On macOS, open the paw in the menu bar. Choose + Rule, select the input to check, describe your rule, and click Deploy.
  3. Continue working with your agent. Open a finding to inspect it, or use Evaluation History to see checks that returned OK too.

Initialization installs starter rules, the hook, and background components. The first semantic program needs Internet access to compile and download its runtime assets. The extra package index above supplies PAW's local inference dependencies; RAP itself is installed from GitHub.

See Getting started for Linux/Windows setup, troubleshooting, and importing rules from existing prose files.

Give your own rules a life of their own

Choose what a rule observes: an assistant response, a tool invocation, or a tool result. Then describe the check in natural language, with a few examples of what should pass and what should be flagged.

For example, you can write a rule to:

  • Flag rsync commands that synchronize source code.
  • Flag success claims that do not report a check and its result.
  • Check that a response asking for help actually requests the missing decision.

A basic rule checks its selected input, not the entire conversation. You can assign rules to selected projects or share them across projects. For precise conditions, you can also write checks directly in Python.

For a more semantic example, take When claiming a change works, report what you checked. The agent replies:

Implemented the parser and everything works.

The rule flags the unsupported success claim. Open the finding to see exactly what it judged:

Finding Inspector showing a warning on “Implemented the parser and everything works.”

A demonstration rule checking an assistant response in the macOS app.

A response such as “I ran pytest; all 42 tests passed” reports a check and its result. “I changed the parser but could not run the tests” states the limitation. Your specification defines the distinction you want the rule to make.

Learn to write and deploy rules →

Debug the rules, too

Rules can make mistakes. Their inputs and judgments give you something concrete to work with:

  1. Inspect the exact input behind a judgment.
  2. Save it as a validation case with the outcome you expect.
  3. Revise the rule and run the saved cases to check the change.
  4. Deploy the revised rule for future events.

Earlier judgments keep their recorded rule revision, so you can distinguish old findings from the behavior of your current rule.

Review findings and improve a rule →

How it works

Codex hooks deliver events to RAP. A local background process runs the matching rule functions while the agent continues its work. Exact checks use Python; semantic checks use ProgramAsWeights to compile a natural-language specification into a small neural program evaluated locally. RAP records the judgments and displays findings in the app.

Your data: managed checks evaluate observed inputs locally. Compilation sends the rule specification and its embedded examples to PAW; compiled programs are public and persistent. Keep secrets out of specifications. Event records and findings are stored locally in plaintext. Custom Python rules can access files and the network. See Data and privacy.

Documentation

Citation

For the PAW foundation of Rules as Programs, cite Program-as-Weights. Also cite Compile by Training when using the training compiler.

Program-as-Weights: A Programming Paradigm for Fuzzy Functions

NeurIPS 2026 · Preprint

@inproceedings{zhang2026programasweights,
  title = {{Program-as-Weights: A Programming Paradigm for Fuzzy Functions}},
  author = {Zhang, Wentao and Hotsko, Liliana and Kim, Woojeong and Nie, Pengyu and Shieber, Stuart and Deng, Yuntian},
  booktitle = {The Fortieth Annual Conference on Neural Information Processing Systems},
  year = {2026},
  url = {https://arxiv.org/abs/2607.02512}
}

Compile by Training: Turning Natural-Language Specifications into Local Neural Functions

EMNLP 2026 System Demonstrations · Preprint

@inproceedings{deng-etal-2026-compile,
  title = {{Compile by Training: Turning Natural-Language Specifications into Local Neural Functions}},
  author = {Deng, Yuntian and Nie, Pengyu and Shieber, Stuart},
  editor = {Agrawal, Sweta and Abad, Alberto},
  booktitle = {Proceedings of the 2026 Conference on Empirical Methods in Natural Language Processing: System Demonstrations},
  month = oct,
  year = {2026},
  address = {Budapest, Hungary},
  publisher = {Association for Computational Linguistics},
  url = {https://aclanthology.org/2026.emnlp-demos.78/},
  doi = {10.18653/2026.emnlp-demos.78},
  pages = {830--839},
  ISBN = {979-8-89176-461-3}
}

About

No description, website, or topics provided.

Resources

Contributing

Stars

9 stars

Watchers

2 watching

Forks

Releases

Packages

Contributors

Languages