Adhiraj Singh ← All notes

My Outreach Agent Has Two Tools, and Neither of Them Sends Email

network-agent runs every morning on my laptop. It finds a few professors, university advisors and industry people, researches them, and drafts an email and a tailored CV for each one. Those emails go out under my name, to people whose opinion of me matters.

The project rests on one sentence from the README: nothing is sent without your tap. Writing that in a prompt is easy. What I actually had to work out was where in the code that promise is kept. The model cannot be the thing that keeps it, so I made sure it never has the means to break it.

The model gets a nearly empty process

Every Claude call goes through a single function, claude.ask in agent/claude.py. It runs Claude Code in headless mode, and most of the command line removes things:

cmd = ["claude", "-p", text, "--model", MODEL, "--output-format", "json",
       "--json-schema", json.dumps(schema.model_json_schema()),
       "--mcp-config", f.name, "--strict-mcp-config", "--tools", "",
       "--setting-sources", "project", "--no-session-persistence",
       "--disable-slash-commands", "--max-turns", str(max_turns)]
if tools:
    cmd += ["--allowedTools", "mcp__net__search,mcp__net__fetch"]

--tools "" takes away the built-in tools, so there is no shell, no file reads and no edits. --strict-mcp-config means only the MCP config I pass in gets loaded, not whatever I have set up for my own Claude use. --setting-sources project keeps out my user settings, plugins and hooks. The docstring puts it plainly: "Isolated from the user's personal setup."

That leaves one MCP server, agent/tools.py, and its own docstring calls it "the ONLY tools the daily agent gets: search + fetch." The prompt tells the model the same thing: "You have exactly two tools." The prompt is only describing the setup, though. The command line is what enforces it.

The writing tasks get even less. Research needs the web, but writing an email doesn't, so compose.py calls claude.ask(..., max_turns=3, tools=False). Then the MCP config is an empty {"mcpServers": {}}. The model that writes the email can't search, can't fetch and can't call anything. It returns a subject, a body and a CV selection, and Python takes it from there.

Owning the tools means owning the record

Because I wrote both tools, every call goes through my code. Each search and fetch logs the URLs it returned or opened into a seen_urls table, keyed by run ID:

_log(f"fetch: {final}", seen=[url, final])

After research, verify() in run.py checks each candidate against that table, not against what the model says it saw. The hook URL has to be in it. At least two evidence URLs have to be in it. A LinkedIn URL is dropped silently if it never showed up in search results. For the email address, the code fetches the source page again itself and runs the same regex the tool used:

_, html = fetch_page(c.email_source_url)
...
if c.email not in emails_on_page(html):
    return "email not found on its source page"

The model's answer is a claim, and the tool log is the evidence. I could only build this check because the tools are mine and not some general-purpose browser.

The budget lives in the tool

Tavily's free plan comes with a monthly search quota. The prompt asks the model to be economical ("about 8-12 searches in total"), but the actual limit is enforced in the database before any HTTP request goes out:

def take_search(con) -> bool:
    """Atomically consume one search from today's cap. False when the cap is reached."""
    cap = get_settings(con)["search_monthly_quota"] // 31
    with tx(con):
        if searches_today(con) >= cap:
            return False
        ...

Once the cap is reached, the tool returns a string instead of results: "ERROR: daily search quota reached. Stop searching; finish with what you have." If the model ignores that, it just keeps getting the same string back.

The search depth is pinned the same way. A comment above the request says search_depth=basic costs one credit and advanced costs two, which "would halve the real quota." The model doesn't get to choose.

The fetch tool can't reach my laptop

fetch takes any URL the model hands it, so check_url runs before every request and again on every redirect hop:

for info in infos:
    ip = ipaddress.ip_address(info[4][0])
    if not ip.is_global:
        return "private/internal addresses are not allowed"

The offline tests check that file:///etc/passwd and http://127.0.0.1:8000/ both get rejected. That matters here in particular. The API my phone talks to runs on this same laptop at 127.0.0.1:8787 (install.sh sets that up and uses tailscale serve to expose it), and that API has an approve route. The research model can't make a request to it. Even if it could, fetch sends a plain GET with no bearer token, and approve needs a POST that has one.

LinkedIn gets a hard block in the same function. The README says it is never scraped, and here that rule is a host check, not an instruction in a prompt.

One function sends

Gmail access uses the gmail.compose and gmail.readonly scopes. I should be honest that compose is enough to send mail. The OAuth grant doesn't stop sending. My code does.

outbox.approve has this docstring: "Approve & send. The ONLY code path that sends email." It is the only place that calls gmail.send_draft, and the only route to it is POST /outreach/{oid}/approve on the API, which checks a bearer token with secrets.compare_digest. The daily run creates drafts and never approves them.

Inside approve, the outreach row moves from draft_ready to sending in one transaction before Gmail is called. That makes a second tap on the same draft fail with a Conflict:

if not o or o["status"] != "draft_ready":
    raise Conflict(f"outreach {oid} is {o['status'] if o else 'missing'}, not draft_ready")
...
con.execute("UPDATE outreach SET status='sending' WHERE id=?", (oid,))

If the Gmail call throws, the status goes back to draft_ready and the error is passed up to the app. Before sending, it also pushes my edits from the app into the Gmail draft (update_draft), so what goes out is what I last looked at, not the model's original text.

Follow-ups and reply suggestions follow the same rule. check_replies runs every 30 minutes, and draft_followups creates a single draft after seven days without a reply. Both end at add_draft, and neither one sends anything.

What the model never touches

A few things are kept out of the model's hands completely. compose.signed() appends the signature in Python, and check() rejects any draft that contains its own sign-off. Every link in a draft has to match an allow-list built from my profile plus that person's hook URL. The CV is assembled from bullet IDs, and an unknown ID raises TailoringError. In that case the code falls back to the master CV, because, as the comment says, a bad CV selection should "never block the email."

What this costs

With so little to work with, the model can't fix problems by itself. If a draft fails validation, it gets exactly one retry with the error fed back. After that, the person stays in researched and gets picked up on the next run. If the model hits Claude's usage limit, the controller writes down which tasks are done and schedules one retry with systemd-run. The model can't open a page, try a different tool or decide to go further. When it doesn't have enough, the right result is "No one met the bar today," and the code treats that as a normal outcome, not an error.

I'm fine with that. The project exists to send a handful of careful emails a day to people I'd like to hear back from. Sending a worse email faster doesn't help with that, and an email I never approved would be worse than missing a day.