Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,26 @@ else:
render(call_llm(user_input))
```

Controller quick example:

```python
from context_compiler import create_engine, preview, state_diff, step

engine = create_engine()

before = engine.state
dry_run = preview(engine, "prohibit peanuts")
print(dry_run["would_mutate"]) # True
planned_change = state_diff(before, dry_run["state_after"])
print(planned_change["changed"]) # True

after_preview = engine.state
print(state_diff(before, after_preview)["changed"]) # False (preview does not mutate state)

applied = step(engine, "prohibit peanuts")
print(applied["decision"]["kind"]) # update
```

## Installation

Requirements:
Expand Down
30 changes: 30 additions & 0 deletions examples/08_controller_preview_diff.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Example 8: controller preview + state diff + apply flow."""

from _util import print_decision_summary, print_state_summary

from context_compiler import create_engine, preview, state_diff, step


def main() -> None:
engine = create_engine()

state_before = engine.state
print_state_summary(state_before, "state before preview")

print("\nPreview: prohibit peanuts")
preview_result = preview(engine, "prohibit peanuts")
print("would_mutate:", preview_result["would_mutate"])
print_decision_summary(preview_result["decision"])

state_after_preview = engine.state
diff_after_preview = state_diff(state_before, state_after_preview)
print("state changed after preview:", diff_after_preview["changed"])

print("\nApply: prohibit peanuts")
step_result = step(engine, "prohibit peanuts")
print_decision_summary(step_result["decision"])
print_state_summary(step_result["state"], "state after step")


if __name__ == "__main__":
main()
6 changes: 6 additions & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,9 @@ Shows `compile_transcript(messages)` from a fresh engine and `engine.apply_trans

Demonstrates explicit single-policy correction without `reset policies`.
Shows `prohibit peanuts` -> `remove policy peanuts` -> `use peanuts`.

## 08_controller_preview_diff.py

Shows controller-layer dry-run behavior with `preview(engine, user_input)`.
Shows structural state inspection with `state_diff(state_before, state_after)`.
Shows `step(engine, user_input)` after preview to apply the same input.
2 changes: 1 addition & 1 deletion examples/integrations/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export OPENAI_API_KEY=...
export PROVIDER=openai
```

Checkpoint continuation in these integration examples requires `context-compiler>=0.6.14`.
Checkpoint continuation in these integration examples requires `context-compiler>=0.7.0`.

### Run

Expand Down