diff --git a/README.md b/README.md index 21bfe10..9d946db 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Once a directive is accepted, it becomes authoritative for the remainder of the User sets a constraint once: ```text -User: don't use docker +User: don't use peanuts ``` State becomes: @@ -30,7 +30,7 @@ State becomes: "focus.primary": null }, "policies": { - "prohibit": ["docker"] + "prohibit": ["peanuts"] }, "version": 1 } @@ -39,7 +39,7 @@ State becomes: Later in the conversation: ```text -User: how should I deploy my service? +User: how should I make this curry? ``` The host supplies the authoritative state to the model so the constraint persists across turns. @@ -201,7 +201,7 @@ The same input sequence always produces the same state. Hard negative directive: ```text -User: don't use docker +User: don't use peanuts ``` Result: @@ -209,7 +209,7 @@ Result: ```json { "policies": { - "prohibit": ["docker"] + "prohibit": ["peanuts"] } } ``` @@ -217,31 +217,31 @@ Result: Fact configuration: ```text -User: I'm using MacBook M3 +User: use vegetarian curry ``` State update: ```text -facts.focus.primary = "MacBook M3" +facts.focus.primary = "vegetarian curry" ``` Correction: ```text -User: actually MacBook M2 +User: actually vegan curry ``` Result: ```text -facts.focus.primary = "MacBook M2" +facts.focus.primary = "vegan curry" ``` Ambiguous mutation: ```text -User: no use docker +User: no use peanuts ``` Compiler response: @@ -265,8 +265,8 @@ Before: ```json { - "facts": {"focus.primary": "oracle"}, - "policies": {"prohibit": ["stored procedures"]}, + "facts": {"focus.primary": "vegetarian curry"}, + "policies": {"prohibit": ["peanuts"]}, "version": 1 } ``` @@ -275,7 +275,7 @@ After `reset policies`: ```json { - "facts": {"focus.primary": "oracle"}, + "facts": {"focus.primary": "vegetarian curry"}, "policies": {"prohibit": []}, "version": 1 } diff --git a/examples/01_persistent_guardrails.py b/examples/01_persistent_guardrails.py index e4b087e..26a0f3b 100644 --- a/examples/01_persistent_guardrails.py +++ b/examples/01_persistent_guardrails.py @@ -20,16 +20,16 @@ def build_prompt(state: State, user_input: str) -> str: def main() -> None: engine = create_engine() - print("User: don't use docker") - decision1 = engine.step("don't use docker") + print("User: don't use peanuts") + decision1 = engine.step("don't use peanuts") print("Decision:") print_json(decision1) print("State after turn 1:") print_json(engine.state) print() - print("User: how should I deploy my service?") - decision2 = engine.step("how should I deploy my service?") + print("User: how should I make this curry?") + decision2 = engine.step("how should I make this curry?") print("Decision:") print_json(decision2) print("State after turn 2:") @@ -37,7 +37,7 @@ def main() -> None: print() print("Host prompt construction with persisted policy:") - prompt = build_prompt(engine.state, "how should I deploy my service?") + prompt = build_prompt(engine.state, "how should I make this curry?") print(prompt) diff --git a/examples/02_configuration_and_correction.py b/examples/02_configuration_and_correction.py index e060924..01bdf79 100644 --- a/examples/02_configuration_and_correction.py +++ b/examples/02_configuration_and_correction.py @@ -8,16 +8,16 @@ def main() -> None: engine = create_engine() - print("User: I'm using MacBook M3") - decision1 = engine.step("I'm using MacBook M3") + print("User: use vegetarian curry") + decision1 = engine.step("use vegetarian curry") print("Decision:") print_json(decision1) print("State:") print_json(engine.state) print() - print("User: actually MacBook M2") - decision2 = engine.step("actually MacBook M2") + print("User: actually vegan curry") + decision2 = engine.step("actually vegan curry") print("Decision:") print_json(decision2) print("State (last write wins):") diff --git a/examples/03_ambiguity_with_clarification.py b/examples/03_ambiguity_with_clarification.py index 6e60457..0b67180 100644 --- a/examples/03_ambiguity_with_clarification.py +++ b/examples/03_ambiguity_with_clarification.py @@ -13,8 +13,8 @@ def fake_llm(user_input: str) -> str: def main() -> None: engine = create_engine() - print("User: no use docker") - decision1 = engine.step("no use docker") + print("User: no use peanuts") + decision1 = engine.step("no use peanuts") print("Decision:") print_json(decision1) print() @@ -23,7 +23,7 @@ def main() -> None: print("Host behavior: clarification pending, do NOT call LLM.") print(f"Prompt to user: {decision1['prompt_to_user']}") else: - fake_llm("no use docker") + fake_llm("no use peanuts") print() print("User: yes") diff --git a/examples/05_llm_integration_pattern.py b/examples/05_llm_integration_pattern.py index 641fffb..0c5580e 100644 --- a/examples/05_llm_integration_pattern.py +++ b/examples/05_llm_integration_pattern.py @@ -34,8 +34,8 @@ def main() -> None: engine = create_engine() handle_turn("hello there", engine) - handle_turn("don't use docker", engine) - handle_turn("no use kubernetes", engine) + handle_turn("don't use peanuts", engine) + handle_turn("no use shellfish", engine) handle_turn("yes", engine) diff --git a/tests/test_examples.py b/tests/test_examples.py index 0088b2d..991b73f 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -26,7 +26,7 @@ def _canonical_json(obj: object) -> str: def test_persistent_guardrails_example_output() -> None: output = _run_example("01_persistent_guardrails.py") - assert "User: don't use docker" in output + assert "User: don't use peanuts" in output assert ( _canonical_json( { @@ -34,7 +34,7 @@ def test_persistent_guardrails_example_output() -> None: "prompt_to_user": None, "state": { "facts": {"focus.primary": None}, - "policies": {"prohibit": ["docker"]}, + "policies": {"prohibit": ["peanuts"]}, "version": 1, }, } @@ -46,28 +46,28 @@ def test_persistent_guardrails_example_output() -> None: _canonical_json( { "facts": {"focus.primary": None}, - "policies": {"prohibit": ["docker"]}, + "policies": {"prohibit": ["peanuts"]}, "version": 1, } ) in output ) assert "Compiled context:" in output - assert "- policies.prohibit: docker" in output - assert "User: how should I deploy my service?" in output + assert "- policies.prohibit: peanuts" in output + assert "User: how should I make this curry?" in output def test_configuration_and_correction_example_output() -> None: output = _run_example("02_configuration_and_correction.py") - assert "User: I'm using MacBook M3" in output + assert "User: use vegetarian curry" in output assert ( _canonical_json( { "kind": "update", "prompt_to_user": None, "state": { - "facts": {"focus.primary": "MacBook M3"}, + "facts": {"focus.primary": "vegetarian curry"}, "policies": {"prohibit": []}, "version": 1, }, @@ -78,21 +78,21 @@ def test_configuration_and_correction_example_output() -> None: assert ( _canonical_json( { - "facts": {"focus.primary": "MacBook M3"}, + "facts": {"focus.primary": "vegetarian curry"}, "policies": {"prohibit": []}, "version": 1, } ) in output ) - assert "User: actually MacBook M2" in output + assert "User: actually vegan curry" in output assert ( _canonical_json( { "kind": "update", "prompt_to_user": None, "state": { - "facts": {"focus.primary": "MacBook M2"}, + "facts": {"focus.primary": "vegan curry"}, "policies": {"prohibit": []}, "version": 1, }, @@ -103,7 +103,7 @@ def test_configuration_and_correction_example_output() -> None: assert ( _canonical_json( { - "facts": {"focus.primary": "MacBook M2"}, + "facts": {"focus.primary": "vegan curry"}, "policies": {"prohibit": []}, "version": 1, } @@ -116,19 +116,19 @@ def test_configuration_and_correction_example_output() -> None: def test_ambiguity_with_clarification_example_output() -> None: output = _run_example("03_ambiguity_with_clarification.py") - assert "User: no use docker" in output + assert "User: no use peanuts" in output assert ( _canonical_json( { "kind": "clarify", - "prompt_to_user": "Did you mean to prohibit 'docker'?", + "prompt_to_user": "Did you mean to prohibit 'peanuts'?", "state": None, } ) in output ) assert "do NOT call LLM" in output - assert "Prompt to user: Did you mean to prohibit 'docker'?" in output + assert "Prompt to user: Did you mean to prohibit 'peanuts'?" in output assert "User: yes" in output assert ( _canonical_json( @@ -137,7 +137,7 @@ def test_ambiguity_with_clarification_example_output() -> None: "prompt_to_user": None, "state": { "facts": {"focus.primary": None}, - "policies": {"prohibit": ["docker"]}, + "policies": {"prohibit": ["peanuts"]}, "version": 1, }, } @@ -148,7 +148,7 @@ def test_ambiguity_with_clarification_example_output() -> None: _canonical_json( { "facts": {"focus.primary": None}, - "policies": {"prohibit": ["docker"]}, + "policies": {"prohibit": ["peanuts"]}, "version": 1, } ) @@ -193,14 +193,14 @@ def test_tool_governance_denylist_example_output() -> None: def test_llm_integration_pattern_example_output() -> None: output = _run_example("05_llm_integration_pattern.py") - docker_state = { + peanuts_state = { "facts": {"focus.primary": None}, - "policies": {"prohibit": ["docker"]}, + "policies": {"prohibit": ["peanuts"]}, "version": 1, } - docker_kubernetes_state = { + peanuts_shellfish_state = { "facts": {"focus.primary": None}, - "policies": {"prohibit": ["docker", "kubernetes"]}, + "policies": {"prohibit": ["peanuts", "shellfish"]}, "version": 1, } @@ -208,25 +208,25 @@ def test_llm_integration_pattern_example_output() -> None: assert _canonical_json({"kind": "passthrough", "prompt_to_user": None, "state": None}) in output assert "Host action: passthrough -> call fake_llm() without state" in output assert "state: null" in output - assert "User: don't use docker" in output + assert "User: don't use peanuts" in output assert ( _canonical_json( { "kind": "update", "prompt_to_user": None, - "state": docker_state, + "state": peanuts_state, } ) in output ) assert "Host action: update -> call fake_llm() with compiled state" in output - assert f"state: {_canonical_json(docker_state)}" in output - assert "User: no use kubernetes" in output + assert f"state: {_canonical_json(peanuts_state)}" in output + assert "User: no use shellfish" in output assert ( _canonical_json( { "kind": "clarify", - "prompt_to_user": "Did you mean to prohibit 'kubernetes'?", + "prompt_to_user": "Did you mean to prohibit 'shellfish'?", "state": None, } ) @@ -234,15 +234,15 @@ def test_llm_integration_pattern_example_output() -> None: ) assert "Host action: clarify -> show prompt, DO NOT call LLM" in output assert "User: yes" in output - assert "prompt_to_user: Did you mean to prohibit 'kubernetes'?" in output + assert "prompt_to_user: Did you mean to prohibit 'shellfish'?" in output assert ( _canonical_json( { "kind": "update", "prompt_to_user": None, - "state": docker_kubernetes_state, + "state": peanuts_shellfish_state, } ) in output ) - assert f"state: {_canonical_json(docker_kubernetes_state)}" in output + assert f"state: {_canonical_json(peanuts_shellfish_state)}" in output