Policy and SOP adherence for tool-using agents. polisys turns a company policy (a handbook, an SOP, a rule list) into checks that run while an agent works: rules that stop a wrong tool call, procedures that guide the agent through a case, and obligations that find work the agent never did. It is a library with a hook interface, so it runs next to an agent and does not contain one.
Status: experimental, Apache-2.0. The code is stable and tested (the suite has more than 3,400 tests), and the measured results are on tuning or already-seen task sets only; nothing here is a held-out result. Read Evidence before you quote a number.
| Part | What it gives the agent | Checked by |
|---|---|---|
| Typed rules | A wrong call is stopped before it runs, with a message that says what to do instead. 15 rule types, for example required arguments, allowed values, record state, role permission, thresholds | Code (and Cedar for hard rules). No model call |
| Procedures | The steps, preconditions, exceptions and must-not rules of the SOP section that applies to the case, as tools and a brief | Code, plus a small model for judgement checks |
| Obligations | At the final reply: "these required writes did not happen", with the values the policy prescribes. Never for work that a hook blocked | Code first; the ledger stays silent when unsure |
| Control levels | Strong models get fewer checks than weak ones; one switch sets which checks run | runtime/levels.py |
| Audit | One line per decision: rule, source, evidence, package version, and each failure of a check | audit.jsonl |
Everything is chosen by a profile (one YAML file). Policy switches in the environment do not exist. A profile never holds rules; rules live in the policy package.
Three parties meet in polisys. The enterprise owns the policies and the systems the agent acts on. polisys compiles the policies into a package and turns it into checks. The agent harness (the host that runs the agent loop) calls those checks at its lifecycle hooks. Nothing in polisys contains an agent, and the harness needs nothing from polisys but the hook contract.
Source: docs/diagrams/architecture.svg; docs/diagrams/render.sh makes the PNG copy.
| Party | Owns | Gives to polisys | Gets from polisys |
|---|---|---|---|
| Enterprise | Policies, systems, the answers to open questions | Documents and tool schemas | A package it can read and a list of questions |
| polisys | The package, the profile, the checks, the audit log | Hook objects, tools and a brief | Calls from the harness |
| Harness | The agent loop, the model, the tools | Nine hook calls (before a tool call, before a reply, and so on) | A stop, a note or a follow-up at each hook |
- Compile reads documents into statements and writes the package. Two routes: a Claude skill
(
skill/SKILL.md, the better route in every comparison so far) and an open-model pipeline (compile/builder.py). - Package is one JSON file per policy.
MODEL.mddescribes it;polisys validatechecks it against the tool schemas. - Runtime is
build_runtime. It refuses wiring that can have no effect (a profile that needs a package and has none, a check turned on at a level where it never runs) instead of running without the policy. - Hooks are the only link to an agent. See docs/hooks.md.
python -m venv .venv && . .venv/bin/activate
pip install -e ".[dev]" # add [cedar], [llm] or [documents] as needed, or [all]
# the example is a made-up Facilities Desk policy
cd examples/facilities_desk
polisys convert policy.md -o set.json # document -> statements
polisys pack set.json draft.json -o package.json --harness example --model hand-written \
--tools tools.json --tests tests.json # statements + draft -> one package
polisys validate package.json --tools tools.json # 0 errors, 0 warnings
polisys counts package.json # what the package holds, in numbers
cd ../..
python examples/quickstart.py # enforce the package at tool-call time, no agent and no modelThe quickstart runs two profiles over the same three calls. With baseline (policy off) nothing is added and every call
runs. With rules_only a call with no requester and a call with priority=whenever are stopped, and the message says what
to do instead:
create_ticket({'priority': 'normal'})
-> BLOCKED: POLICY: `create_ticket` was not called.
- missing mandatory field(s) requester. Do instead: look up the value(s) and pass requester; ...
from polisys.package import load_package
from polisys.runtime.profile import load_config
from polisys.runtime import RunContext, build_runtime
cfg = load_config("profile.yaml")
parts = build_runtime(cfg, load_package("package.json"), RunContext(task_id="t1", tool_specs=tool_specs))
agent = MyAgent(tools=tools + parts.tools, hooks=parts.hooks) # parts.hooks follow the hook contractparts also carries the system note, a run replacement for loop-style SOP control, and usage() and records() for cost
and audit. With the CUGA agent pass parts.hooks to CugaAgent(hooks=[...]). For other hosts, and for what a host must
provide, read docs/hooks.md.
If the harness can tell polisys what its hook registry offers, a profile that needs more than the harness has is refused at build time instead of running with a silent gap:
from polisys.hosts.cuga import host_features # or polisys.hooks.host_features_of(your_registry)
ctx = RunContext(task_id="t1", tool_specs=tool_specs, host_features=host_features())With the obligation ledger on, host_features must include tool_blocked; otherwise build_runtime raises. Leaving it out
(None) skips the check.
A profile is plain YAML; see examples/profiles/ and the field list in
runtime/profile.py. An unknown key is an error that names it.
Every model is named in the profile. A name such as openai/gpt-oss-120b goes to any OpenAI-compatible gateway, for
example LiteLLM (OPENAI_BASE_URL, OPENAI_API_KEY); openrouter:<name> goes to OpenRouter (OPENROUTER_API_KEY).
The optional decision-model checks (yes/no questions to Kev-4B) use OpenRouter's systemone endpoint and need
OPENROUTER_API_KEY; they are off unless a profile turns them on.
With the skill (recommended). Give an agent skill/SKILL.md, the policy documents (the original files, not a flattened
text) and tools.json. It writes a draft (rules, procedures, obligations, questions); polisys pack and polisys validate
check it. Decision tests are written by a separate agent that has not seen the rules. validate checks quotes against the
document text, argument names against the tool schemas, value binding for obligations, and conflicts between rules.
With the pipeline. polisys build runs an open model (for example gpt-oss-120b) over the statements, with code for tables
and repairs for the known failures. On the policies where both were measured it did not reach the skill, so treat its output as
a draft to validate, not as a replacement.
Either way, an ambiguity in the text goes into policy_questions for a person to answer; it is not guessed.
Measured in the private evaluation repo on four benchmarks (an IT service desk, written HR/insurance/pharmacy SOPs, Zapier-style workflows, and a conversational telecom/airline/retail benchmark). The honest summary:
- Rules work as a guard. On the IT service policy, rules written by the skill from the policy text alone caught 106 of 182 deny tests with 0 false denies on 147 allowed calls (tuning version; the pipeline reached 102 with 1 false deny).
- Control by agent strength matters. The same checks helped a small open model (gpt-oss-120b: +18.9 and +8.8 points on two sets, both now seen) and did not help a strong one (Gemini 3.8: −5.8, which could be chance, with more guardrails broken).
- The pipeline does not replace the skill on any of the benchmarks measured.
- Obligations do not send yet. In replay on saved runs every source stays at level 1 (record, never send): the best case has 0 false opens and 27.6% recall against a bar of 30%.
- No set is truly held-out any more. Sets that were held out when first run have since been seen and are labelled so.
The runs behind these numbers, their basis (tuning, seen, unseen) and the corrections to earlier claims are kept with the evaluation work, which is not part of this repository. The design the code was built to is docs/design.md.
New to the code? docs/read-this-first.md follows one tool call through these folders.
src/polisys/
package/ the policy model (model.py) and the package file (files.py)
compile/ documents to a package, offline: documents.py, builder.py, handlers/, validate/
sources/ rules found in data during the run: intake/, detectors.py, listing.py
checks/ checks of a tool call: rules/ (typed rules, Cedar in cedar.py), verifier.py, decisions.py, router.py
guidance/ notes the agent sees: work_method.py
finish/ checks at the final reply: requirements_tracker.py, followups.py
runtime/ profile.py (profiles), registry.py (the list of components), assembly.py (build_runtime),
settings_check.py (settings that cannot work), levels.py (control levels and WriteChecks),
trace.py (audit lines), dry_run.py (wiring description without a model)
experimental/ components with no held-out gain yet, by role: the gate, procedures as tools and the guide,
the obligation ledger, tool notes, the SOP loop (docs/components.md has the list and the evidence)
hosts/ glue for agent frameworks (langchain.py, cuga.py)
hooks.py the hook contract
llm.py small-model clients
tool_kind.py which tools read and which write, from their names
values.py how values are compared: folded text, numbers, dates, conditions
skill/SKILL.md the compile skill for an agent
_aliases.py old module paths of the flat layout; they still import
tests/ the suite (offline; models are scripted)
examples/ a made-up policy, two profiles and a quickstart
docs/ design, hook contract, components
pip install -e ".[dev,cedar,llm]"
pytest -q # offline, no model calls; a few tests need the extras or the CUGA agent and skip without them
ruff check .Tests that read PDFs skip without docling. Eight tests run a real CUGA agent loop. They need the loop helper of the agent's
hook tests (tests/unit/hooks/test_agent_loop.py of cuga-agent) and the agent's own dependencies, so run them in the agent's
environment with CUGA_REPO set to a cuga-agent checkout; without it they skip and say why:
CUGA_REPO=~/dev/cuga-agent pytest -q tests/test_levels.py tests/test_obligations.py tests/test_producers.pypolisys is the policy layer of the CUGA agent project, extracted into its own repository on 2026-11-05 from the
policy/stable-v1 tag of the agent's policy/stable branch (it was cuga.policy_layer). History was not carried over: the
original history is entangled with the agent's. polisys.hooks is a structural copy of cuga.backend.hooks; keep the two
in step until the agent depends on this package.
Licensed under the Apache License 2.0, see LICENSE, the same licence as the CUGA agent. Do not add benchmark policy text or task data to this repo: the tests use made-up policies only.