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
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,6 @@ Use Context Compiler in your host application first:
```python
from context_compiler import (
create_engine,
get_error_message,
is_error,
is_update,
)
Expand All @@ -148,7 +147,7 @@ user_input = "set premise current project uses uv"
decision = engine.step(user_input)

if is_error(decision):
show_to_user(get_error_message(decision))
show_to_user(decision["message"])
elif is_update(decision):
messages = build_messages(engine.state, user_input)
render(call_llm(messages))
Expand Down
4 changes: 2 additions & 2 deletions docs/api-reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ Helper functions:
Typical use:

```python
from context_compiler import get_error_message, is_error, is_update
from context_compiler import is_error, is_update

decision = engine.step(user_input)

if is_error(decision):
show_to_user(get_error_message(decision))
show_to_user(decision["message"])
elif is_update(decision):
apply_runtime_rules()
```
Expand Down
4 changes: 2 additions & 2 deletions examples/03_ambiguity_with_error.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from _util import print_decision_summary, print_state_summary

from context_compiler import create_engine, get_error_message, is_error
from context_compiler import create_engine, is_error


def fake_llm(user_input: str) -> str:
Expand All @@ -25,7 +25,7 @@ def main() -> None:

if is_error(decision2):
print("Host behavior: error returned, do NOT call LLM.")
print(f"Error message: {get_error_message(decision2)}")
print(f"Error message: {decision2['message']}")
else:
fake_llm("use peanuts")
print()
Expand Down
6 changes: 2 additions & 4 deletions examples/05_llm_integration_pattern.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
Engine,
State,
create_engine,
get_decision_state,
get_error_message,
is_error,
is_no_directive,
is_update,
Expand Down Expand Up @@ -35,10 +33,10 @@ def handle_turn(engine_input: str, engine: Engine) -> None:
fake_llm(None, engine_input)
elif is_update(decision):
print("Host action: update -> call fake_llm() with compiled state")
fake_llm(get_decision_state(decision), engine_input)
fake_llm(decision["state"], engine_input)
elif is_error(decision):
print("Host action: error -> show prompt, DO NOT call LLM")
print("error message:", get_error_message(decision))
print("error message:", decision["message"])
print()


Expand Down
9 changes: 3 additions & 6 deletions examples/_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
from context_compiler import (
POLICY_PROHIBIT,
POLICY_USE,
get_decision_state,
get_error_message,
is_error,
is_update,
)
Expand Down Expand Up @@ -39,15 +37,14 @@ def print_state_summary(state: Any, label: str = "state") -> None:
def print_decision_summary(decision: Any) -> None:
if is_update(decision):
print("result: updated")
state = get_decision_state(decision)
assert isinstance(state, dict)
state = decision["state"]
print_state_summary(state, "compiled state")
return

if is_error(decision):
print("result: error")
prompt = get_error_message(decision)
if isinstance(prompt, str) and prompt:
prompt = decision["message"]
if prompt:
print("error message:")
for line in prompt.splitlines():
print(f"- {line}")
Expand Down