Metadata-Version: 2.5
Name: mellea-pratt
Version: 0.1.0
Summary: Guarded {pre, act, post} agent loops for Mellea (simple version).
Requires-Python: >=3.10
Requires-Dist: mellea
Provides-Extra: test
Requires-Dist: pytest; extra == 'test'
Description-Content-Type: text/markdown

# mellea-pratt (simple)

The "act fast" version of `pratt`: an agent loop over guarded actions
`{pre, act, post}`, extending Mellea's Instruct-Validate-Repair to open loops.
No automata compilation / improving search here.

```python
from mellea_pratt import pratt_agent

agent = pratt_agent(actions=[
    {"pre": pre_1, "act": act_1, "post": post_1},
    ...
], state={...}, goal=lambda s: ...)

result = agent.run()   # result.status in {"goal", "deadlock", "max_steps", "error"}
```

## Semantics (shielding, as in Verifiably Safe RL)

Each step:

1. `enabled` = actions whose `pre(state)` is true (an action that failed
   `max_attempts` times since the last successful step is excluded);
2. `policy(enabled, state)` picks one (`first_enabled` default, `random_policy(seed)`,
   or `LLMPolicy(session)` which asks a Mellea session to name an action);
3. `act(state)` runs; it may mutate `state` or return a dict of updates;
4. `post(state)` is checked. On failure (or if `act` raises), `on_post_failure`
   decides: `"rollback"` (default; restore a deep-copy snapshot and count the
   failure), `"raise"` (`PostconditionError`), or `"continue"` (keep the state).

The loop stops when `goal(state)` holds, nothing is enabled (`deadlock`), or
`max_steps` attempts were made.

## State

`State` is a dict with attribute access (`s.x == s["x"]`; use `s["items"]` for
keys that shadow dict methods), plus `s.step`, `s.trace` (list of `TraceEntry`,
including failed attempts) and `s.history` (names of successful actions).

## Conditions

`pre`, `post` and `goal` may be a Python callable `state -> bool`, an English
string, or a `mellea.Requirement`. Strings/Requirements are judged by
`condition_verifier=(condition: str, state) -> bool`; without one a
`MissingVerifierError` is raised. `LLMConditionVerifier(session)` is a
Mellea-backed verifier (lazily starts a session; not needed by tests).

## Run

```
uv pip install -e '.[test]'
pytest
python examples/coding_agent.py
```
