{"slug": "make-sops-executable-policies-as-deterministic-logic-programs-with-agent-leaves", "title": "Make SOPs executable: policies as deterministic logic programs with agent leaves", "summary": "DeepClause introduced a new skill for its deepclause-pi extension that converts standard operating procedures into executable logic programs written in a DSL called DML, which run inside a WASM build of SWI-Prolog. The approach aims to improve agent reliability by making policies deterministic and ensuring agents always have the right context, addressing challenges highlighted by the HANDBOOK.md benchmark where models struggle with long SOPs and compliance.", "body_md": "**tldr; Building on the self-modifying harness concept we show here how to use [DeepClause](https://github.com/deepclause/deepclause-sdk) to build more reliable agents for outsourcing work defined via SOPs and policies. Instead of taking a big markdown file and putting it into the sytem prompt, we let a coding agent convert policies into small executable logic programs in a DSL called “DML”. The “leaves” of these programs can either be deterministic rules or LLM-driven agent loops. DML programs run safely inside the WASM build of SWI-Prolog.**\n\n*(Text written by a human being)*\n\nOut in the real world, a lot of boring office work that we are trying to automate a way with agents, is ultimately defined in terms of “Standard Operating Procedures”. For example, a company that receives and processes invoices typically has a policy like the following in their SOPs:\n\n```\nAP-04 Invoice Intake & Approval\n1. Incoming invoices arrive in the AP inbox. Extract vendor, invoice number, amount, due date, and PO number.\n2. Duplicate check: if vendor + invoice number already exists in the register, do not process — flag and notify AP.\n3. Approval routing:\n    - under $500 → auto-approve and post to ledger\n    - $500–$5,000 → department manager approval\n    - over $5,000 → manager **and** finance director\n    - over $25,000 → add CFO\n4. PO matching: if a PO exists, invoice amount may not exceed the PO by more than 10%; otherwise hold for review.\n5. Deadline: due in ≤ 3 business days → expedite and flag the payment run.\n6. Never approve an invoice you raised yourself. Never schedule payment before all approvals are recorded.\n```\n\nWhile thinking a bit about what people actual would actually want to do with agents (except for coding and Q&A), I’ve stumbled across [HANDBOOK.md](https://github.com/surge-ai/handbook). It’s a wonderful paper and benchmark. The question behind the benchmark is the following: can we just take 100+ page SOP document, give it to an agent and then let it do all our work for us in compliance with all the policies of the SOP?\n\nAs it turns out, this still appears to be a hard problem. Taking a look at the leader board (as of early September 2026), the benchmark is far from being saturated:\n\nWhile SOTA models still struggle with this and most of us mere mortals (resp. small to medium sized companies) do not have billions of tokens that we can spend trying to optimize prompts etc., we will have to shop around for different solutions. If we are truly serious about outsourcing menial, but somewhat challenging tasks to an LLM-driven agent, that is.\n\nA possible solution to this comes with the new **handbook-dml skill** that ships with the latest [deepclause-pi](https://github.com/deepclause/deepclause-pi) extension. But before we look into this, we can speculate about why exiting models combined with standard harnesses struggle so much with following seemingly straightforward SOPs. The main reasons appear to be:\n\n1. The SOPs in HANDBOOK.md (and in the real world!) are very, very long and contain many details. Hence, it is unsurprising that even modern models won’t be able to always recall the right parts from the context and apply them accordingly.\n2. Also, as the benchmark authors observe in their [paper](https://arxiv.org/abs/2607.25398) :\n  1. “agents let a plausible but unauthorized in-environment request override the standing policy, perform a required check and then act against its result”\n  2. ”report compliance they did not achieve. We release the tasks, environments, and evaluation harness.”\n\nSo, to produce a better solution, it seems apt try to\n\n1. build agents that always have the right context\n2. work much more deterministically.\n\nI believe that the key here is to **view SOPs/handbooks and the policies therein as specifications for programs. Hence, policies become executable code.**\n\nThis is where [DeepClause](https://github.com/deepclause/deepclause-sdk) comes in. Essentially DeepClause is a runtime for “DML” code, the “DeepClause Meta Language”. It is a Prolog-based DSL that can allow us to concisely encode LLM-driven workflows or agents. We can use it to \n\n1. Define completely deterministic tools and workflows that can be called by a harness such as pi\n2. Define sub-agents while precisely controlling context and agent autotnomy. That is we can decide to pack everything into one big agent-loop or wire a bunch of agent-loops and/or prompts together into a bigger workflow (“Graph engineering” :-)\n\nUsing DeepClause, the solution to the handbook problem becomes straightforward.\n\n1. Fire up pi (or whatever coding agent, but pi currently works best)\n2. Install the deepclause-pi extension\n3. Run “/dc” and “/dc-tool enable” to initialize deepclause\n4. Drop your handbook into the session and watch pi build your handbooks policies as executable DML code.\n\nThe output will consist of two parts:\n\n1. A bunch of policy dml files in your .pi/deepclause folder (e.g. one for invoice intake, once for travel reimbursements,…)\n2. A short markdown for your AGENTS.md that instructs the harness on which policy should be used in which case.\n\nA typical policy DML would something like this:\n\nWhat is notable here is the following:\n\n- The relevant context from the SOP document is baked directly into the code, where it is used as contexts for agent-loops (hidden behind the task/N predicate)\n- There is explicit control over which tasks (loops) are allowed to use which tools at what stage in the wokflow.\n\nFinally, some rules and procedures are handled by an agent-loop, while some are handled by good old deterministic code:\n\n**Where to go from here**\n\nTaking all of this together, there is now a higher probability that the combination of outer harness (e.g. pi) plus skill plus RLM-style code (menaing ordinary code or code that can call an LLM/agent again) will not just lead to better overall outcomes, but provide for\n\n- less variance across results per task instances,\n- as well as more traceability and explainability of mission-critical work performed by an agent. This is possible, because the DeepClkause runtime uses a so called “metainterpreter”, this means that every step during DML execution can be traced and logged if needed.\n\nFinally, if you want to to deploy the collection of DML policies in an agent outside of a harness such as pi or Claude, then this would be possible by using the [deepclause-sdk](https://github.com/deepclause/deepclause-sdk/) for TypeScript. That way, a SOP following agent could easily be deployed into a company internal  app. \n\n**A few words on security**\n\nDeepClause DML programs run entirely inside a WASM module. They may access a file system mount from the host, but cannot access arbitrary paths on the host. Anything that gets triggered on the host needs to be wrapped in special predicates that connect the DML code to hooks defined in TypeScript. This can also be used to define the tools for an agent encoded in DML. Every agentic loop inside DML can be restricted to a particular subset of tools.\n\n**That’s it!**\n\nI do hope you enjoyed a somewhat unconventional solution to a modern problem. If you have any questions or would like to know more, please comment here or reach out to me via X (@hilbershelper) or simply open a GitHub issue.", "url": "https://wpnews.pro/news/make-sops-executable-policies-as-deterministic-logic-programs-with-agent-leaves", "canonical_source": "https://deepclause.substack.com/p/make-sops-executable-policies-as", "published_at": "2026-09-07 12:51:17+00:00", "updated_at": "2026-09-07 12:56:39.049570+00:00", "lang": "en", "topics": ["ai-agents", "developer-tools", "ai-research"], "entities": ["DeepClause", "deepclause-pi", "SWI-Prolog", "DML"], "alternates": {"html": "https://wpnews.pro/news/make-sops-executable-policies-as-deterministic-logic-programs-with-agent-leaves", "markdown": "https://wpnews.pro/news/make-sops-executable-policies-as-deterministic-logic-programs-with-agent-leaves.md", "text": "https://wpnews.pro/news/make-sops-executable-policies-as-deterministic-logic-programs-with-agent-leaves.txt", "jsonld": "https://wpnews.pro/news/make-sops-executable-policies-as-deterministic-logic-programs-with-agent-leaves.jsonld"}}