Sub-agent runs

Link a sub-agent's run to the run that started it, and VariantGate weighs them as one family: the trifecta guard reads them all, every request answers to the plans above it, and a stop reaches the runs below.

Many agents hand part of a task to a sub-agent: a research helper that reads the web, a coder that edits one folder, a writer that drafts the reply. Each sub-agent usually works under a run id of its own. That splits what one task did across several runs, and the checks that follow a run see only part of it. The parent reads the customer record, the research sub-agent opens a web page someone else wrote, and the parent then sends an email: no single run holds the lethal trifecta, so nothing holds the email.

Linking fixes that. The agent links the sub-agent’s run below its own, and VariantGate weighs the runs as one family: the trifecta guard reads every run of it, every request answers to the run plans above it, and stopping a run stops the runs below it.

Allow rules cover all three actions, so without the guard every request is approved at once.

support-bot · run ticket-4812

  1. 3. Email the ticket notes to help-desk@outside.example (email.send, sends out)

    Waiting for a person · allowed: false. The allow rule for email.send does not count while this run, with any sub-agent runs linked to it, holds all three.

    • Private data: request 1: crm.read
    • Untrusted content: request 2: web.fetch
    • Sends out: this request: email.send

The agent sends the link with its own key, once per sub-agent run, before the sub-agent makes its first request. Both runs belong to the same key.

curl -X PUT https://api.variantgate.com/v1/runs/ticket-4411.research/parent \
  -H "Authorization: Bearer gl_YOUR_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "parent": "ticket-4411" }'

The answer says where the run now sits:

{
  "run": "ticket-4411.research",
  "parent": "ticket-4411",
  "root": "ticket-4411",
  "depth": 1,
  "family": 2
}
root
The top run of the family.
depth
How many runs sit above this one.
family
How many runs the family holds, this one included.
201
The run was linked.
200
The run already had this parent; nothing changed. Safe to send again after a retry.
409 run_linked
The run already has another parent. A link cannot be changed or removed once made.
422
The link would make a loop, the family would be more than 5 runs deep or hold more than 100 runs, or a run id has characters other than letters, digits, . _ : -

With the SDKs:

import { ApprovalClient } from "@variantgate/agent";

const research = new ApprovalClient({
  agent: "support-bot",
  apiUrl: process.env.VARIANTGATE_API_URL ?? "https://api.variantgate.com",
  key: process.env.VARIANTGATE_KEY ?? "",
  run: "ticket-4411.research",
});

// Before the sub-agent makes its first request.
await research.linkRun("ticket-4411.research", "ticket-4411");
from variantgate import ApprovalClient

research = ApprovalClient("support-bot", run="ticket-4411.research")

# Before the sub-agent makes its first request.
research.link_run("ticket-4411.research", "ticket-4411")

What the family changes

  • The trifecta guard reads every run of the family as one run. What a sub-agent read counts for its parent, its siblings and the runs below it.
  • A request answers to its own run’s plan and to every plan above it. A sub-agent’s own plan can only narrow what the parent planned: a step the parent did not name still waits for a person.
  • A step of a plan counts the requests of its own run and of every run below it, so two sub-agents cannot each send the one email the parent planned.
  • Stopping a run stops every run below it: what waits is denied, and what they ask later is refused with run_stopped. A run linked below a stopped run is refused too.
  • People see a run’s parent and its sub-agent runs on the run page, and the run whose plan a request was off.

A worked example

With allow rules for every action and the trifecta guard on, the parent reads the customer record and hands research to a sub-agent:

POST /v1/requests  {"action": "crm.read",  "run": "ticket-4411", ...}           -> approved by a rule
PUT  /v1/runs/ticket-4411.research/parent  {"parent": "ticket-4411"}  -> 201
POST /v1/requests  {"action": "web.fetch", "run": "ticket-4411.research", ...}  -> approved by a rule
POST /v1/requests  {"action": "email.send", "run": "ticket-4411", ...}          -> pending: trifecta guard

Without the link, the email would have been approved by its rule. When a sub-agent asks for something the parent’s plan does not name, people see which run’s plan it was off:

"off_plan": {
  "reason": "not_in_plan",
  "goal": "Answer ticket 4411",
  "planned": [
    { "action": "crm.read" },
    { "action": "kb.*" },
    { "action": "email.send", "max": 1 }
  ],
  "plan_run": "ticket-4411"
}

What it never does

  • It never approves a request, and never sets allowed to true.
  • It never lets an agent move or remove a link, so nothing a sub-agent reads can take it out of the family.
  • It never joins runs of two keys: a run belongs to the key that asked.

Sub-agent runs work on every plan, Free included, and need no setting: a link only ever makes the workspace more cautious. Make the link in code, where the parent starts the sub-agent, not in a tool call the model fills in.

During a deploy

While two versions of the API run side by side during a deploy, one from before sub-agent runs answers 404 to a link and ignores links, so a request that instance takes is weighed as if its run stood alone. Do not count on links until every instance runs this version. The SDKs’ linkRun and link_run answer null (None in Python) when they meet such an instance.