unify-agent is an agent harness that learns from use. You give it a task in plain words. A model, the actor, solves it by writing Python, one program per turn, which the harness runs in a sandbox on your machine. With memory on, each finished task is written down, and a background writer turns those records into a library of tested functions and notes that later tasks can ask for and call.
It runs locally with one model-provider key, and keeps everything it learns in
a git repository under ~/.unify. It is research code, published so the design
can be read, run and measured.
You need:
- Linux, or Windows with WSL2. macOS is not supported: every program the agent runs is confined with bubblewrap, which needs Linux, and the harness refuses to run without it.
- bubblewrap, util-linux (for
prlimit) and git. On Debian or Ubuntu:sudo apt install bubblewrap util-linux git. Check that bubblewrap can start a sandbox withbwrap --ro-bind / / true; some distributions (Ubuntu 24.04, for one) restrict the user namespaces it needs. - Python 3.12 and uv.
- One model-provider key:
OPENROUTER_API_KEYfor the default model, orANTHROPIC_API_KEYwith an Anthropic model named inUNIFY_MODEL.
Install layout. unify-agent pins its model client, unillm, to commit
9d85422of unillm'smain, and uv installs it from a unillm checkout beside this one ([tool.uv.sources]inpyproject.toml), at that commit. Clone both as below.
git clone https://github.com/unifyai/unify-agent.git
git clone https://github.com/unifyai/unillm.git
git -C unillm checkout c8f3aa6b2181755c60dc51fed4a1e89657c266dd
cd unify-agent
uv sync --no-devPut your key in a .env file in the checkout (git ignores it), as
OPENROUTER_API_KEY=..., or export it in your shell. Then give the actor a
file and a task:
Memory spends on your key. Memory is on by default, and it makes model calls of its own on your provider key, beside the actor's: the writer, its helpers, the episode-end fork and embeddings. Together they are capped at
UNIFY_MEMORY_CAP_USD, 20.00 USD per run (oneunify act) by default. SetUNIFY_MEMORY=offto make no memory calls at all.
mkdir -p ~/.unify/workspace
cp data.csv ~/.unify/workspace/
.venv/bin/unify act "How many rows does data.csv have, and which columns are mostly empty?"Progress goes to stderr and the answer to stdout. The actor's programs see the
system's read-only directories, their workspace ~/.unify/workspace and a
private /tmp, and can write only the last two. Everything the agent keeps
lives under ~/.unify (UNIFY_HOME); delete that directory to start from
nothing.
With memory on and OPENROUTER_API_KEY set, unify act starts a local lane
relay that holds the key and gives memory's writer, helpers, fork and
embeddings their own lanes, all under that one cap; memory's processes never
hold the key. Memory's search needs embeddings, and the harness never sends the
provider key to a provider for them directly: they go through the relay's
embedding lane, or you compute them in process (install the extra with
uv sync --no-dev --extra local-embeddings and set
UNIFY_LOCAL_EMBEDDINGS=true), or you set UNIFY_EMBED_URL to a proxy lane of
your own on http://127.0.0.1:<port>/.... With none of these, a search that
needs a new embedding is refused.
The actor. Each turn, the model writes one Python program. The harness runs
it in a persistent sandboxed interpreter, so variables carry over from one
program to the next. Shell commands run from Python through subprocess.
Packages a program needs are installed into one shared environment under
~/.unify, from prebuilt wheels only. The actor answers when it is done; with
--persist it then waits for a follow-up in the same sandbox.
Memory is on by default. After each task:
- A capture. A confined copy of the actor's conversation, a fork, is asked
to write down what it did: a small runnable procedure, what it was for, and
which parts of the task it rests on. The fork needs a fork lane, which
unify actstarts with memory on andOPENROUTER_API_KEYset (or a launcher gives). Without one no fork runs and no capture is made;ANTHROPIC_API_KEYalone stores none. - The writer. A background writer reads the captures and failures that
need attention, and keeps a library in a git repository at
~/.unify/memory: tested functions, and notes that link to the functions they use (and back). It states tests for what it writes, and the harness runs them in a sandbox. A gate checks every change and records what it finds as labels on the item. The writer spends under memory's cap. With the lane relay,unify actstops the writer when it ends: a pass in flight gets up to 5 minutes, and what it held stays owed for the next run. A writer service that no run owns exits after 30 idle minutes. - The librarian. At the start of a later task, a librarian agent reads
the library and tells the actor which items fit; the actor can ask it
again with
memory.ask("..."). Each item comes with a recorded example call and can be called directly, asitem(...). The actor decides whether to use it. - A shared run record. The actor, its teammates, the forks, the writer
and the librarian post to one append-only record. They can address one
another (
@writer,@librarian), so a question reaches the agent that can answer it.
docs/memory.md explains the memory in full, and
docs/memory-off.md the harness with memory off.
Memory has one switch, UNIFY_MEMORY:
UNIFY_MEMORY=off: no memory of any kind. Each task costs only the actor's model calls.UNIFY_MEMORY=on, the default (also when unset or empty): memory between tasks. It adds the capture, writer and librarian calls to the actor's.
Everything else is essential configuration only: the provider key, the model
and reasoning effort, the paths, where embeddings come from, and the writer's
spend cap.
CONFIG.md lists every environment variable, one line each.
unify act --persist --jsonl "first request" keeps one session open and speaks
newline-delimited JSON. Progress still goes to stderr.
Lines your program writes to its stdin:
| Line | Effect |
|---|---|
{"message": "..."} |
A follow-up message in the same session. With "request": "new" the driver says it starts a new request (memory then scopes verdicts per request); without it, it is more of the same request. |
{"cancel": true} |
Ends the running turn at once and keeps the session. |
{"quit": true} |
Ends the session. |
{"outcome": {"solved": true, ...}} |
Your verdict on the work, so memory learns what worked. The full form is in unify/outcome.py. |
{"checker": {"label": "pass"}} |
With memory on: a verdict the environment showed the actor during the request, "pass" or "fail", optionally with "text": the verdict's text exactly as the actor was shown it, kept for the writer (the label is the verdict). It may also carry about (an action or item) and episode (an earlier episode's id). A "fail" counts as a failed use of the items the current request used before it (in a persistent session a request starts at the session or at a message marked "request": "new"), so memory.ask does not offer them again in that request or the next; it bears on those items only for trust. One naming an earlier episode is late evidence on that episode, and on its last request's items when it held several requests. |
Lines it writes to stdout, each with a type:
type |
When |
|---|---|
response |
At the end of every turn, with the turn's text in content; "cancelled": true if a cancel ended it. |
record |
An entry in the run record addressed to @user. |
outcome |
The answer to an outcome line: accepted, or a reason if it was refused. |
result |
The session's final result, with run_stats. |
ended |
The last line: the session is over. |
With memory on, other types report memory's progress; ignore types you do not
know. A minimal driver, with unify on the PATH (or .venv/bin/unify):
import json, subprocess
proc = subprocess.Popen(
["unify", "act", "--persist", "--jsonl", "How many rows does data.csv have?"],
stdin=subprocess.PIPE, stdout=subprocess.PIPE, text=True,
)
def send(line: dict) -> None:
proc.stdin.write(json.dumps(line) + "\n")
proc.stdin.flush()
for raw in proc.stdout:
event = json.loads(raw)
if event["type"] == "response":
print(event["content"])
send({"outcome": {"solved": True, "source": "user"}})
send({"quit": True})
elif event["type"] == "ended":
break
proc.wait()import asyncio
import unify
from unify.actor.code_act_actor import CodeActActor
from unify.actor.environments.actor import top_level_environments
async def main() -> None:
unify.init()
actor = CodeActActor(environments=top_level_environments())
handle = await actor.act("How many rows does data.csv have?")
print(await handle.result())
await actor.close()
asyncio.run(main())act() returns a handle with result(), done(), stop(reason), submit(text)
(a follow-up, read at the next turn boundary), cancel_request(),
next_notification(), and next_clarification() with
answer_clarification(call_id, answer). This runs the actor alone: memory is
driven by the unify act session (unify/cli.py), so to use memory from your
program, drive the command as above.
Give the actor your own functions as primitives.<name>. Point
UNIFY_ENV_NAMESPACES at a factory, package.module:factory, importable by the
harness:
from unify.function_manager.primitives.environment import (
EnvironmentMethod,
EnvironmentNamespace,
EnvironmentSurface,
)
def lookup(order_id: str) -> dict:
"""Return the order with this id from the order service."""
...
def surface() -> EnvironmentSurface:
return EnvironmentSurface(
namespaces=(
EnvironmentNamespace(
name="orders",
description="Our order service.",
methods=(
EnvironmentMethod(
name="lookup",
call=lookup,
effect="read", # or "write" or "destructive"
signature="(order_id: str) -> dict",
docstring=lookup.__doc__,
),
),
),
),
)With UNIFY_ENV_NAMESPACES=mytools:surface, the actor's programs call
primitives.orders.lookup("A-17") and its prompt lists the namespace. Your
functions run in the harness process, outside the sandbox and with its access;
arguments and results cross from the sandbox as plain data. A factory that
fails stops the harness at start-up. The details are in
unify/function_manager/primitives/environment.py.
The actor's programs have no network by default. With
UNIFY_WORKSPACE_NETWORK=proxy, their only route out is a proxy you run on
the host at 127.0.0.1:UNIFY_WORKSPACE_PROXY_PORT; HTTP_PROXY and
HTTPS_PROXY point at it inside the sandbox, so your proxy decides what is
reachable. Package installs are separate: they go through the harness's own
proxy, which reaches only the package index (PyPI, or the index your
UV_INDEX settings name).
- Every program the actor writes, every shell command and every subprocess
runs inside bubblewrap. The host root is mounted read-only and only as an
allow-list; the workspace and a private
/tmpare the only writable places.~/.unify, credential directories (~/.ssh,~/.config,~/.awsand others) and.envfiles are hidden. Environment variables that look like credentials are removed, a seccomp filter limits sockets and system calls, and resource limits apply. Without bubblewrap nothing runs. - Model-written code never sees the provider key. Model calls are made by harness code; a program the actor writes reaches a model only by asking the harness.
- Memory's agents run their code in the same kind of box, with no network and an empty environment.
- Your own tools (
primitives.<name>) run outside the sandbox, with the harness's access. They are the openings you choose. - The sandbox limits what injected instructions can reach; it does not stop a model from following them. Review what you feed the agent.
SECURITY.md has the full trust model.
uv sync --group dev
uv run pytest -n auto # the whole suite
uv run pytest -n auto tests/actor # one areaThe tests need no key and make no network calls. Every model reply is
scripted (tests/scripted_model.py), provider calls are refused, and sockets
may connect only to this machine. When no key is set, the root conftest.py
sets a placeholder that is plainly not a secret. Each pytest process runs
inside bubblewrap, so the tests need it too. The tests of the in-process
embedder also need its weights in the Hugging Face cache.
tests/parallel_run.sh tests/runs one tmux session per test file (it needs tmux); seetests/README.md.model_evals/holds checks of a live model. They need a key, spend money and are run by hand.
unify-agent is research code from unify's ongoing work on agents that learn from experience.
Please report security issues privately, not in a public issue; see
SECURITY.md. Contributions: CONTRIBUTING.md.
MIT. See LICENSE.