Tools¶
gvn-tools (import name gvn_tools) is a package of ready-made tools for gvn harnesses:
files, a shell, git, the web, Jira, GitHub, and the tools of any MCP server. This page first
shows where they sit in a gvn harness, then how they keep a model inside the limits you set,
one rule at a time, with a small example for each.
- You will learn: where tools plug into a run, how a tool refuses what is outside its limits, how a policy decides which calls need a person, and how to put several tool families together.
- Read first: the tutorials Adding a tool and A policy and approval, which introduces tools, a policy and approval with a hand-written tool.
- Time: about 15 minutes.
Where tools plug in¶
In the quickstart's big picture, tools belong to the
fulfillers box. The agent's state machine never runs anything: when a model reply asks
for a tool, the agent asks the governor for two pieces of work in
turn, and a fulfiller does each one. The policy
fulfiller asks your policy whether the call may run; the tool fulfiller runs the calls
that may. gvn-tools supplies what both of them use:
flowchart LR
agent["<b>Agent</b><br/>a verified state machine"]
governor["<b>Governor</b>"]
subgraph fulfillers ["Fulfillers"]
direction TB
policy_fulfiller["<b>Policy fulfiller</b><br/>cleared, needs approval or forbidden"]
tool_fulfiller["<b>Tool fulfiller</b><br/>runs the calls that may run"]
end
subgraph family ["One tool family, such as files"]
direction TB
rules["<b>rules(tools)</b><br/>the recommended policy for them"]
tools["<b>tools(...)</b><br/>tools built with their limits"]
end
subgraph ports ["Ports: where the I/O happens"]
direction TB
workspace["Workspace"]
commands["Commands"]
http["Http"]
mcp_server["McpServer"]
end
agent -- "request" --> governor
governor -- "1. may this call run?" --> policy_fulfiller
governor -- "2. run it" --> tool_fulfiller
policy_fulfiller -- "asks" --> rules
tool_fulfiller -- "runs" --> tools
tools -- "do their I/O through" --> ports
Read it from the right:
- A port is an interface for one kind of I/O: a directory (
Workspace), running programs (Commands), HTTPS requests (Http), or an MCP server (McpServer). Because the tools go through ports, a test can swap a real port for a fake that answers from a script, as every example on these pages does. - A tool is something an agent may ask to use: an object with a short name, a schema for its
arguments and a
runmethod, an ordinarygvn.harness.tools.Toolas in the tutorial Adding a tool. Each tool here is built with its limits (the directory, programs, hosts or projects it may reach) and refuses anything outside them. - A family is a group of tools over one kind of thing. Each family is a module with two
functions:
tools(...)builds its tools over a port, andrules(...)takes those tools and gives the policy it recommends for them: which calls may run at once, which need a person first, and which are never allowed. - You put the tools of all your families into one
Toolbox(gvn's container of tools, from Adding a tool), which the tool fulfiller runs from and the model fulfiller describes to the model, and merge their rules into one policy for the policy fulfiller. The agent itself holds only the identities of the tools it is offered, never the tool objects: an agent is stored in the journal and must not hold code.
A tool has two names. Its short name, name(), is what the model sees (write_file).
Its identity, identity(), is its namespace, a dot and its short name
(gvn_tools.files.write_file), and is what gvn stores and matches on, so two packages'
tools that share a short name are never confused. You pass tools as objects, never as
names. Tools explains both names and how a run is checked against
the tools it needs.
The families:
- files: read, list, search, write and edit the files of one directory.
- shell: run an allowed program, with arguments, in that directory.
- git: status, diff, log, a branch, a commit and a push, in one repository.
- web: HTTPS requests to the hosts you allow.
- Jira Cloud and GitHub: read and write issues (and, on GitHub, pull requests) in the projects or repositories you allow.
- MCP servers: the tools of any Model Context Protocol server, a standard way for a program to offer tools to models.
Rules shows how to write a policy of your own, and Testing with the tools how to script the fakes.
Installing¶
These examples use the companion gvn-tools package alongside gvn. Files, shell, and Git
use its core dependencies. The http extra supplies the HTTP client for web, Jira Cloud,
and GitHub. The mcp extra supplies the SDK for connecting to MCP servers.
Either command also installs the core gvn package.
Why a separate package¶
The framework decides what should happen next; it never does the work. Tools are the work:
they touch files, run programs and call services. Keeping them out of gvn keeps the
framework free of vendors and of anything with an effect, and an import contract keeps it
that way: gvn never imports gvn_tools, and gvn_tools imports only gvn.harness and
gvn.kernel. You can use gvn without these tools, and write your own the same way.
The safety model, one step at a time¶
Every tool in the package follows the same few rules. The steps below show each rule at work on a small project directory. Each step adds one idea to the step before, and every example runs offline.
Step 1: a tool is built with its limits¶
A tool does not take its limits from the model. You give them when you build the tool: the
directory it may touch, the programs it may run, the hosts, projects or repositories it may
reach. For the file tools, the limit is a Workspace: one directory, resolved once.
Here you make a small project and build the five file tools over it:
import asyncio
import pathlib
import typing
from gvn.harness.tools import Invocation
from gvn_tools import files
from gvn_tools.workspace import Workspace
project = pathlib.Path("project")
project.mkdir()
(project / "README.md").write_text("Hello.\n")
workspace = Workspace(root=project.resolve())
file_tools = files.tools(workspace=workspace)
print([tool.name() for tool in file_tools])
# ['read_file', 'list_files', 'search_files', 'write_file', 'edit_file']
files.tools(...) returns a FileTools, a named tuple: every family except
MCP returns one (ShellTools, GitTools, WebTools, JiraCloudTools,
GithubTools). You pick one tool by its short name as an attribute, and that object is
what you pass wherever a tool is meant: to an agent, to a rule of your own, to an
evaluation check. Its identity is gvn_tools.<family>.<short name>:
write_file = file_tools.write_file
print(write_file.name()) # write_file
print(write_file.identity()) # gvn_tools.files.write_file
It is still a tuple, so you can pass it whole where several tools are expected
(Agent(tools=file_tools)), unpack it, or add it to another family's tuple with +. The
family's rules(...) takes the whole tuple: files.rules(file_tools).
A tool runs with two things: the arguments the model chose, and an Invocation that says
which call this is. In a run, the tool fulfiller makes the invocation; here you make one by
hand. Its key is the call's idempotency key:
the same string every time the same call of the same run is delivered, so a repeat can be
recognised. Its origin names the actor that asked. You meet the key again in step 6.
invocation = Invocation(key="run-1/5#c1", origin="agent")
async def read_readme() -> typing.Any:
return await file_tools.read_file.run(arguments={"path": "README.md"}, invocation=invocation)
print(asyncio.run(read_readme()))
# {'path': 'README.md', 'text': 'Hello.\n', 'truncated': False}
The result is plain JSON. It says whether it was cut short (truncated), because every
result is capped in size.
Step 2: a refusal you can see¶
Now ask for something outside the workspace. The tool raises a ToolFailure, the exception a
tool uses for a failure it understands, instead of reading:
async def try_to_leave() -> None:
try:
await file_tools.read_file.run(arguments={"path": "../etc/passwd"}, invocation=invocation)
except Exception as error:
print(type(error).__name__, error)
asyncio.run(try_to_leave())
# ToolFailure '../etc/passwd' climbs out of the workspace with '..'
In a harness, a raised ToolFailure becomes a failed tool result, and the model reads why. A
refusal, such as this one, is reported as {"error": "tool_rejected", "detail": <the reason>}
and is not retried: asking again would get the same answer. When a tool could not reach its
service, or the service asked to wait, it raises ToolFailure(reason, retryable=True) instead;
the result is then {"error": "tool_unavailable", "detail": <the reason>} (with retry_after,
in seconds, when the service said how long), and the call may be tried again: by the tool
itself, when it was built with a retry (see Retrying below). The
refusal does not depend on any policy: safety lives in the tool. It refuses, by raising,
anything outside its limits, whatever the policy says. The run's
context (trusted data fixed when a run starts, never written by
the model) can narrow the limits further: a "repository", "project" or "hosts" entry
there restricts the tools that read it.
Step 3: a program is a list, never a command line¶
The shell tool takes a program and its arguments as a list (argv) and starts the program
directly. It runs only the programs you allow. The selected program still interprets its
own arguments, including flags.
To keep this page offline, the shell tool runs through FakeCommands, which answers from a
script instead of starting a process (see Testing with the tools):
from gvn_tools import shell
from gvn_tools.fakes import FakeCommands
from gvn_tools.process import Completed
commands = FakeCommands().script(["pytest", "-q"], Completed(code=0, output="3 passed\n"))
shell_tools = shell.tools(workspace=workspace, commands=commands, programs=["pytest", "ruff"])
run_command = shell_tools.run_command
async def run(argv: list[str]) -> None:
try:
print(await run_command.run(arguments={"argv": argv}, invocation=invocation))
except Exception as error:
print(type(error).__name__, error)
asyncio.run(run(["pytest", "-q"]))
# {'exit': 0, 'output': '3 passed\n', 'errors': '', 'truncated': False}
asyncio.run(run(["sh", "-c", "rm -rf /"]))
# ToolFailure 'sh' is not an allowed program; allowed: pytest, ruff
The same idea holds in every family: a name, path or ref that starts with - is refused, so
it can never become a flag, and a model never chooses a host, a project or a credential.
Step 4: a rule you can see deciding¶
The tool decides what is possible. The policy decides something else: which of the
possible calls need a person first. Each family's rules(...) takes the family's tools and
gives its recommended policy for them, a Rules, which answers with one of three verdicts: cleared (run it),
needs_approval (ask a person first) or forbidden (never). merged joins two families'
rules into one policy.
The policy is asked a consultation: the question the agent puts to its policy, holding
the calls of a model reply (each a ToolCall: an id, the tool's short name, as the model
wrote it, and its arguments), the identity of each call's tool, which actor asked
(origin), and the run's context. A rule matches a call by its tool's identity. Merge the
file and shell rules, saying that pytest is quiet: safe to run without asking. Then ask
the policy about a few calls. A tool no family built, drop_database, is stood in for by a
StubTool from gvn's fakes:
from gvn.harness.messages import ToolCall
from gvn.harness.tools import Consultation, Tool
from gvn.kernel.schema import Record
from gvn.testing.fakes import StubTool
policy = files.rules(file_tools).merged(shell.rules(shell_tools, quiet=["pytest"]))
def verdict(tool: Tool, arguments: dict[str, typing.Any]) -> str:
call = ToolCall(call_id="c1", name=tool.name(), arguments=arguments)
consultation = Consultation(calls=[call], identities=[tool.identity()], origin="agent")
return policy.decide(consultation).name()
drop_database = StubTool("drop_database", Record({}))
print(verdict(run_command, {"argv": ["pytest", "-q"]})) # cleared: pytest is quiet
print(verdict(run_command, {"argv": ["ruff", "check", "."]})) # needs_approval: any other program
print(verdict(drop_database, {})) # forbidden: no family's rules name this tool
When a reply holds several calls, the policy fulfiller asks the policy about each on its
own, and a person is asked only about the calls that need one: here, a reply holding the
pytest call and the ruff call would run pytest without asking and wait for a person
only about ruff (see one verdict per call).
Step 5: the tool refuses whatever the policy said¶
The policy clears every file tool. It can, because the tool itself refuses anything outside the workspace. Here the policy clears a read and the tool still refuses it:
print(verdict(file_tools.read_file, {"path": "../etc/passwd"})) # cleared
asyncio.run(try_to_leave())
# ToolFailure '../etc/passwd' climbs out of the workspace with '..'
The tool enforces the limits it was built with. The policy separately decides which calls
to clear, which need approval, and which to forbid. Use each family's rules(...) to apply
its recommended policy.
Step 6: a repeat does no harm¶
Work in gvn is delivered at least once.
After a crash, the same call can arrive twice with the same invocation.key(). File edits
check the resulting content. Edit the README twice under the same key:
async def edit_twice() -> None:
edit = {"path": "README.md", "old": "Hello.", "new": "Hello, world."}
for _ in range(2):
print(await file_tools.edit_file.run(arguments=edit, invocation=invocation))
asyncio.run(edit_twice())
# {'path': 'README.md', 'changed': True}
# {'path': 'README.md', 'changed': False}
The second edit found the change already made and did nothing. The table below explains what each family does on redelivery and what the receiving program or service must supply.
Step 7: programs do not see your secrets¶
A program the model chose should not see the API keys of the process running the harness.
LocalCommands, the real Commands port, passes on only PATH, HOME, LANG,
LC_ALL and TMPDIR (and what you add). The tool adds one variable of its own,
GVN_CALL_KEY, so a program can recognise a repeat. The fake records what a real run would
have passed:
Secrets the tools need, such as a Jira or GitHub token, are constructor arguments, never call
arguments, and are replaced by [REDACTED] in every result and error.
What the steps add up to¶
- Safety lives in the tool: each tool refuses anything outside the limits it was built with (steps 1, 2 and 5).
- The tool validates structured arguments. It controls the allowed programs, hosts, and credentials. The shell tool runs an allowed program directly with arguments that the program can interpret as flags (step 3).
- The policy clears, gates, or forbids each call (step 4).
- A repeated effect depends on its tool family. Use the table below when choosing tools.
- Programs inherit an allowlist of environment variables. Tools that accept credentials, such as Jira Cloud and GitHub, redact them from results and errors (step 7).
- Results are data. Each family documents its output limits and how to recognize when a response was cut. Treat what a file, a program, or a web page says as data. The tools whose results come from outside the deployment (web, GitHub, Jira Cloud, MCP) declare themselves untrusted, so what they return joins the reading agent's exposure.
| Tool family | Repeat behavior and application responsibility |
|---|---|
| Files | Repeating a write or edit can recognize the resulting content. The workspace limits file paths for these tools. |
| Git | A repeated commit can find its key in the branch history. A repeated push uses the remote's current state. |
| GitHub, Jira Cloud | Writes look up a marker. Search visibility, lookup bounds, and concurrent writes affect whether the marker is found. |
| Web, MCP | The remote server must honor the key to deduplicate an effect. |
| Shell | A repeated command can run again. The program receives the key and can choose to honor it. Use OS isolation when running programs that need it. |
Putting families together¶
A harness usually needs several families. Each family's tools(...) returns a named tuple,
so you add them up with + into one Toolbox, and each family's rules(...) returns a
Rules, so you merge them into one policy. This adds the web family to the files and shell tools from the steps
above. FakeHttp answers from a script and reaches nothing:
from gvn.harness.tools import Toolbox
from gvn_tools import web
from gvn_tools.fakes import FakeHttp
from gvn_tools.transport import Response
http = FakeHttp().script(
"GET",
"https://docs.example.com/api",
Response(status=200, headers={"content-type": "text/plain"}, text="API notes"),
)
web_tools = web.tools(http=http, hosts=[".example.com"])
toolbox = Toolbox(tools=file_tools + shell_tools + web_tools)
policy = (
files.rules(file_tools)
.merged(shell.rules(shell_tools, quiet=["pytest"]))
.merged(web.rules(web_tools))
)
for identity in toolbox.identities():
print(identity)
# gvn_tools.files.edit_file
# gvn_tools.files.list_files
# gvn_tools.files.read_file
# gvn_tools.files.search_files
# gvn_tools.files.write_file
# gvn_tools.shell.run_command
# gvn_tools.web.http_get
# gvn_tools.web.http_request
The merged policy answers for every family, and each tool still guards its own limits:
post = {"method": "POST", "url": "https://docs.example.com/x"}
print(verdict(web_tools.http_request, post)) # needs_approval: a request with an effect
async def fetch(url: str) -> None:
try:
result = await web_tools.http_get.run(arguments={"url": url}, invocation=invocation)
print(result["status"], result["text"])
except Exception as error:
print(type(error).__name__, error)
asyncio.run(fetch("https://docs.example.com/api")) # 200 API notes
asyncio.run(fetch("https://evil.test/"))
# ToolFailure host 'evil.test' is not in the allowed hosts ['.example.com']
The coding agent guide puts files, shell and git together under an agent, with approvals and a durable journal.
The families at a glance¶
For lookup: each family's constructor, its tools and what its rules(...) decides by default.
Each family page has the details.
| Family | Constructor | Tools | Default verdicts (rules(...)) |
|---|---|---|---|
| files | files.tools(workspace) |
read_file, list_files, search_files, write_file, edit_file |
all cleared |
| shell | shell.tools(workspace, commands, programs) |
run_command |
needs approval; quiet= programs cleared |
| git | git.tools(workspace, commands) |
git_status, git_diff, git_log, git_create_branch, git_commit, git_push |
all cleared except git_push: needs approval, forbidden for a protected branch |
| web | web.tools(http, hosts) |
http_get, http_request |
http_get cleared, http_request needs approval |
| jira_cloud | jira_cloud.tools(http, base_url, token, projects, email) |
jira_search, jira_get_issue, jira_comment, jira_create_issue, jira_transition |
reads cleared, writes need approval |
| github | github.tools(http, token, repositories) |
github_get_issue, github_list_issues, github_comment, github_create_issue, github_open_pull_request |
reads cleared, writes need approval |
| mcp | mcp.tools(server, catalogue, prefix) |
<prefix>_<tool> for each tool the server listed when you ran mcp.discover(server) |
all need approval, except those you clear; server hints are ignored |
Every constructor except MCP's returns a named tuple whose fields are its tools, in the
order listed; mcp.tools returns a plain tuple, because its tools depend on the server. The
identity of each tool is gvn_tools.<family>.<short name>; an MCP tool's is
gvn_tools.mcp.<prefix>.<prefix>_<tool> unless you set its
namespace. Every family's rules(...) forbids any tool other than
those it was given. For MCP, the catalogue is the list of a server's tools that
mcp.discover(server) fetched and you reviewed (see
MCP servers).
The calls of one model reply run in the order the model gave them, one at a time, so an edit
and the test run that depends on it, asked for in the same reply, happen in that order. Tools
that are pure reads say so (Tool.independent() returns True), and neighbouring calls to
them run together. In this package the independent tools are read_file, list_files,
search_files, git_status, git_diff, git_log, http_get, jira_search,
jira_get_issue, github_get_issue and github_list_issues; each family page marks them.
An MCP tool is independent only when you name it in mcp.tools(..., independent=[...]).
See The order of a reply's tool calls.
Retrying¶
Whether a call that could not reach its service is sent again is a property of each tool,
since the tool controls which failures it can safely retry. Every attempt carries the same
invocation.key(). A tool declares its retry settings with Tool.retry(), a
gvn.harness.ports.Retry or None, and the
tool fulfiller follows it (Retrying a tool call).
Every family whose tools can fail retryably takes retry= (None by default: one attempt) and
gives it only to the tools that are safe to repeat:
| Family | Which tools get retry= |
Why |
|---|---|---|
| git | all six | the one retryable failure is a timed-out git process, and every git tool is safe to repeat |
| web | http_get |
it has no effect; build HttpRequest(..., retry=...) yourself for servers that honour Idempotency-Key |
| jira_cloud | jira_search, jira_get_issue |
a write's repeat check is least sure in the seconds after a lost answer, so writes are tried once |
| github | github_get_issue, github_list_issues |
the same, for comments, issues and pull requests |
| mcp | every tool built | the unanswered listing check never sent the call; an unanswered call is retryable only with a key_argument |
files and shell never fail retryably, so they take no retry: a refusal is final, and a
program that timed out may have run.
The four ports underneath, with their real implementation and the fake that stands in for it in tests:
| Port | Module | Real implementation | Fake |
|---|---|---|---|
Workspace |
gvn_tools.workspace |
a directory, resolved once; raises Outside for a path that leaves it (the file tools report it as a ToolFailure) |
(a temporary directory) |
Commands |
gvn_tools.process |
LocalCommands: asyncio subprocesses, no shell, own process group |
FakeCommands |
Http |
gvn_tools.transport |
LocalHttp: never follows redirects, no environment proxies or .netrc |
FakeHttp |
McpServer |
gvn_tools.protocol |
LocalMcpServer: the official MCP SDK, over stdio or streamable HTTP |
FakeMcpServer |
What the tools enforce and what you add¶
- The tools confine; the container isolates. The tools enforce their limits: paths, programs, hosts, projects and repositories. A program the shell tool may run does whatever that program does, so run the harness inside a container or a VM for isolation of the machine. The family pages say, under Running them safely, what to arrange around each family's tools.
- An MCP call cut off may have run. After a timeout or a lost connection the server may have acted. gvn passes the call's key to the server, and a server that applies it runs a repeat once; see MCP servers.
Recap¶
- A family gives the tools (for the tool fulfiller, through one
Toolbox) and the policy (for the policy fulfiller, merged into oneRules); the tools do their I/O through ports. - A family's
tools(...)returns a named tuple: pick a tool by attribute (file_tools.write_file), pass the whole tuple, or add tuples with+. Itsrules(...)takes that tuple. Each tool's identity isgvn_tools.<family>.<short name>. - A tool is built with its limits and refuses anything outside them, whatever the policy says.
- A policy (
rules(...)) only decides which calls need a person; each call of a reply is judged on its own, and anything not named is forbidden. - Check the family-specific repeat behavior before allowing retries or resuming a run.
Next: the file tools, then the coding agent guide.