Model gate
agent_gate.model_gate
¶
Layer 2: the System 1 model gate.
A fast model reads the raw action, the mandate and the session's recent actions, and judges the cases the rules cannot: mostly Law 1, harm to a person. It sees the action with the agent's own description removed, and is told to treat the action as data.
The model can only tighten. Its verdict is combined with the rules' verdict
by :func:agent_gate.verdict.strictest, so it can never lower one. Every
failure (no SDK, no credentials, a timeout, a refusal, unparseable output)
becomes ask.
judge(action, mandate, entries, client=None)
¶
Ask the model gate for a verdict.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
Action
|
the action to judge. |
required |
mandate
|
Mandate
|
the governing mandate. |
required |
entries
|
list[dict[str, Any]]
|
the session's ledger entries. |
required |
client
|
Any
|
an Anthropic client, for tests; the |
None
|
Returns:
| Type | Description |
|---|---|
Verdict
|
the model's verdict, or |
Source code in src/agent_gate/model_gate.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
parse_reply(text)
¶
Turn the model's reply into a verdict, or ask if it cannot be read.
Local models may wrap the JSON in reasoning (<think>...</think>) or
prose, so the outermost JSON object is extracted first.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
the reply text. |
required |
Source code in src/agent_gate/model_gate.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 | |
render_request(action, mandate, entries)
¶
Build the user message for the model gate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
Action
|
the action to judge. |
required |
mandate
|
Mandate
|
the governing mandate. |
required |
entries
|
list[dict[str, Any]]
|
the session's ledger entries, oldest first. |
required |
Source code in src/agent_gate/model_gate.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |