Skip to content

Mandate

agent_gate.mandate

The mandate: what the agent may touch, and the gate's own limits.

A person writes the mandate as TOML. The gate looks for it at $AGENT_GATE_MANDATE, then at .agent_gate/mandate.toml in the working directory or any parent. Without one, the gate asks before every consequential action.

Mandate(source, digest='none', task='', paths=(), hosts=(), git_remotes=(), recipients=(), mcp_tools=(), max_denials=3, retry_similarity=0.85, outward='ask', model=ModelConfig()) dataclass

The task, its targets and the gate's limits.

Parameters:

Name Type Description Default
source Path | None

the mandate file, or None when none was found.

required

found property

True when a mandate file was loaded.

allows_host(host)

True when host is a listed host or a subdomain of one.

Parameters:

Name Type Description Default
host str

a hostname, any case.

required
Source code in src/agent_gate/mandate.py
71
72
73
74
75
76
77
def allows_host(self, host: str) -> bool:
    """True when ``host`` is a listed host or a subdomain of one.

    :param host: a hostname, any case.
    """
    host = host.lower().rstrip(".")
    return any(host == h or host.endswith("." + h) for h in self.hosts)

allows_path(path)

True when path lies under a mandate path.

Parameters:

Name Type Description Default
path Path

an absolute, resolved path.

required
Source code in src/agent_gate/mandate.py
64
65
66
67
68
69
def allows_path(self, path: Path) -> bool:
    """True when ``path`` lies under a mandate path.

    :param path: an absolute, resolved path.
    """
    return any(path == root or root in path.parents for root in self.paths)

allows_recipient(address)

True when address is a listed recipient.

Parameters:

Name Type Description Default
address str

an email address.

required
Source code in src/agent_gate/mandate.py
87
88
89
90
91
92
def allows_recipient(self, address: str) -> bool:
    """True when ``address`` is a listed recipient.

    :param address: an email address.
    """
    return address.lower() in self.recipients

allows_remote(remote)

True when remote (host/owner/repo) is a listed git remote.

Parameters:

Name Type Description Default
remote str

a normalized remote, as :func:agent_gate.rules.normalize_remote returns.

required
Source code in src/agent_gate/mandate.py
79
80
81
82
83
84
85
def allows_remote(self, remote: str) -> bool:
    """True when ``remote`` (``host/owner/repo``) is a listed git remote.

    :param remote: a normalized remote, as :func:`agent_gate.rules.normalize_remote` returns.
    """
    remote = remote.lower()
    return any(remote == r or remote.startswith(r + "/") for r in self.git_remotes)

ModelConfig(enabled=False, backend='anthropic', model='claude-haiku-5-5', effort='low', endpoint='http://localhost:8080/v1', api_key_env='SYNTH_API_KEY', timeout_seconds=20.0) dataclass

Settings for the System 1 model gate.

backend is anthropic (the Claude API) or openai (any OpenAI-compatible server, such as oMLX or Ollama, at endpoint). The openai backend sends the value of the api_key_env variable as a bearer token when it is set.

find_mandate(cwd)

Locate the mandate file for a working directory.

Parameters:

Name Type Description Default
cwd Path

the directory the agent is working in.

required

Returns:

Type Description
Path | None

the mandate path, or None.

Source code in src/agent_gate/mandate.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
def find_mandate(cwd: Path) -> Path | None:
    """Locate the mandate file for a working directory.

    :param cwd: the directory the agent is working in.
    :return: the mandate path, or ``None``.
    """
    env = os.environ.get("AGENT_GATE_MANDATE")
    if env:
        return Path(env).expanduser().resolve()
    for directory in (cwd, *cwd.parents):
        candidate = directory / MANDATE_RELPATH
        if candidate.is_file():
            return candidate.resolve()
    return None

load_mandate(cwd)

Load the mandate that governs cwd.

Relative paths in the file resolve against the project directory, the parent of .agent_gate/.

Parameters:

Name Type Description Default
cwd Path

the directory the agent is working in.

required

Returns:

Type Description
Mandate

the mandate; Mandate(source=None) when there is none.

Source code in src/agent_gate/mandate.py
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
def load_mandate(cwd: Path) -> Mandate:
    """Load the mandate that governs ``cwd``.

    Relative paths in the file resolve against the project directory, the
    parent of ``.agent_gate/``.

    :param cwd: the directory the agent is working in.
    :return: the mandate; ``Mandate(source=None)`` when there is none.
    """
    source = find_mandate(cwd)
    if source is None:
        return Mandate(source=None)
    text = source.read_text(encoding="utf-8")
    data = tomllib.loads(text)
    project = source.parent.parent if source.parent.name == ".agent_gate" else source.parent
    body = data.get("mandate", {})
    limits = data.get("limits", {})
    model = data.get("model", {})
    raw_paths = [*body.get("paths", []), *body.get("scratch", [])]
    return Mandate(
        source=source,
        digest=hashlib.sha256(text.encode()).hexdigest()[:16],
        task=body.get("task", ""),
        paths=tuple(_resolve(p, project) for p in raw_paths),
        hosts=tuple(h.lower().rstrip(".") for h in body.get("hosts", [])),
        git_remotes=tuple(r.lower().rstrip("/") for r in body.get("git_remotes", [])),
        recipients=tuple(r.lower() for r in body.get("recipients", [])),
        mcp_tools=tuple(body.get("mcp_tools", [])),
        max_denials=int(limits.get("max_denials", 3)),
        retry_similarity=float(limits.get("retry_similarity", 0.85)),
        outward=str(limits.get("outward", "ask")),
        model=ModelConfig(
            enabled=bool(model.get("enabled", False)),
            backend=str(model.get("backend", "anthropic")),
            model=str(model.get("model", "claude-haiku-5-5")),
            effort=str(model.get("effort", "low")),
            endpoint=str(model.get("endpoint", "http://localhost:8080/v1")),
            api_key_env=str(model.get("api_key_env", "SYNTH_API_KEY")),
            timeout_seconds=float(model.get("timeout_seconds", 20.0)),
        ),
    )