# Local model on Tether QVAC

Run an agent whose model, Qwen3 1.7B Instruct, is served on your own machine by Tether QVAC. The model chooses Abazi's MCP tools; Abazi holds the keys and makes every policy decision.

The model stays on your machine. Tether QVAC serves Qwen3 1.7B Instruct through an OpenAI-compatible API, with outbound network access denied. A small agent program sits between the model and Abazi: it shows the model three slim tools, forwards the model's choices to Abazi's MCP server with the agent credential, and fills in everything the model should not decide. The model chooses what to buy. Abazi decides whether it may, and pays.

## How the pieces sit [#how-the-pieces-sit]

| Piece | Runs where | Holds |
| --- | --- | --- |
| Qwen3 1.7B Instruct (4-bit) | Your machine, served by QVAC, outbound network denied | Nothing: no key, no credential, no limits |
| Agent program | Your machine | The agent credential (`ABAZI_AGENT_KEY`) |
| Abazi MCP server | Abazi | Nothing the agent can extract: it checks the credential and calls the policy engine |
| Policy engine, budget and signer | Abazi | The mandate, the limits, the wallet keys |

```text title="Agent loop"
task ─► model (QVAC, on device) ─► tool choice ─► agent program ─► Abazi MCP server ─► policy ─► pay
              ▲                                        │
              └──────────── tool result ◄──────────────┘
```

Only the agent program's call to Abazi leaves the machine.

## Before you start [#before-you-start]

| You need | Why |
| --- | --- |
| An agent credential (`agk_test_...`) | Created in the [Console](https://app.52-28-238-205.sslip.io) under **Agents > New agent**. Shown once. Replace `YOUR_AGENT_KEY` with it. See [Get an agent credential](/docs/agents#get-an-agent-credential). |
| A signed mandate for that agent | Without one every purchase is denied with <ReasonCode code="MANDATE_MISSING" />. |
| Node.js and npm | To install and run the QVAC command-line tool. |
| Python 3.10 or later | For the agent program, with `mcp` and `httpx`. |
| About 1 GB of disk | The model is downloaded once. |

## Connect [#connect]

<Steps>
<Step>

### Serve the model with QVAC [#serve-the-model-with-qvac]

Install the QVAC command-line tool and give the model an alias, `local-agent`, with tool calling on.

```bash title="Terminal"
npm install @qvac/cli@0.18.0
```

```json title="qvac.config.json"
{
  "serve": {
    "models": {
      "local-agent": {
        "model": "QWEN3_1_7B_INST_Q4",
        "default": true,
        "preload": true,
        "config": { "ctx_size": 8192, "tools": true }
      }
    }
  }
}
```

```bash title="Terminal"
npx qvac serve --openai -p 11434 -c qvac.config.json
```

The first start downloads the model. After that, run the server with outbound network access denied. On macOS, Abazi's reference agent starts it under `sandbox-exec` with a profile that denies every network connection except those that stay on the machine, so the model cannot send your task anywhere.

With `-p 11434`, QVAC's local OpenAI-compatible endpoint is `http://localhost:11434/v1` on your machine.

</Step>
<Step>

### Check the model [#check-the-model]

```bash title="Terminal"
curl -s http://localhost:11434/v1/models
```

The list contains `local-agent`, owned by `qvac`, with `state` `ready` once the model has loaded.

</Step>
<Step>

### Run the agent loop [#run-the-agent-loop]

The program connects to `https://api.52-28-238-205.sslip.io/mcp` with the agent credential, offers the model three tools with the smallest possible inputs, and sends the model's tool calls to Abazi. When the model asks to buy, the program adds the task id, a fresh idempotency key and the wait time itself.

```bash title="Terminal"
pip install mcp httpx
export ABAZI_AGENT_KEY="YOUR_AGENT_KEY"
python local_agent.py
```

```python title="local_agent.py"
import asyncio, json, os, uuid

import httpx
from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client

MCP_URL = "https://api.52-28-238-205.sslip.io/mcp"
QVAC_URL = "http://localhost:11434/v1"  # QVAC's local OpenAI-compatible endpoint
MODEL = "local-agent"
SYSTEM = ("You are a shopping agent with a small budget. Use the tools to find the service the user asks for and "
          "buy it once. Call search_catalog first, then request_purchase with the service_id you found. /no_think")

# The model sees only what it decides: which tool, the search text, the service.
SLIM = {
    "search_catalog": {"type": "object", "properties": {"query": {"type": "string"}}, "required": ["query"]},
    "request_purchase": {"type": "object", "properties": {"service_id": {"type": "string"}}, "required": ["service_id"]},
    "get_spending_status": {"type": "object", "properties": {}},
}


async def call(s, tool, args):
    r = await s.call_tool(tool, args)
    return not r.isError, json.loads("".join(c.text for c in r.content if c.type == "text"))


async def main(task="Buy the forecast service."):
    headers = {"Authorization": f"Bearer {os.environ['ABAZI_AGENT_KEY']}"}
    async with streamablehttp_client(MCP_URL, headers=headers) as (read, write, _), httpx.AsyncClient(timeout=120, headers={"Authorization": "Bearer qvac"}) as llm:
        async with ClientSession(read, write) as s:
            await s.initialize()
            listed = (await s.list_tools()).tools
            tools = [{"type": "function", "function": {"name": t.name, "description": t.description,
                                                       "parameters": SLIM[t.name]}} for t in listed if t.name in SLIM]
            messages = [{"role": "system", "content": SYSTEM}, {"role": "user", "content": task}]
            for _ in range(6):
                r = await llm.post(f"{QVAC_URL}/chat/completions",
                                   json={"model": MODEL, "messages": messages, "tools": tools, "temperature": 0})
                msg = r.json()["choices"][0]["message"]
                calls = msg.get("tool_calls") or []
                if not calls:
                    print("model:", msg.get("content"))
                    return
                messages.append({"role": "assistant", "content": msg.get("content") or "", "tool_calls": calls})
                for tc in calls:
                    name = tc["function"]["name"]
                    args = json.loads(tc["function"].get("arguments") or "{}")
                    print(f"model -> {name}({json.dumps(args)})")
                    if name == "request_purchase":
                        # The program, not the model, owns task id, idempotency and wait time.
                        ok, res = await call(s, name, {"service_id": args.get("service_id"),
                                                       "task_id": f"local-{uuid.uuid4().hex[:8]}",
                                                       "idempotency_key": str(uuid.uuid4()), "wait_seconds": 20})
                        print(json.dumps(res, indent=2))
                        return
                    if name not in SLIM:
                        data = {"error": f"unknown tool {name}"}
                    else:
                        _, data = await call(s, name, {k: v for k, v in args.items() if k in SLIM[name]["properties"]})
                    messages.append({"role": "tool", "tool_call_id": tc.get("id", name), "content": json.dumps(data)})


asyncio.run(main())
```

</Step>
</Steps>

## Verify [#verify]

A good run prints the model's choices, then Abazi's answer:

```text title="Output"
model -> search_catalog({"query": "forecast"})
model -> request_purchase({"service_id": "svc_..."})
{
  "status": "paid",
  "intent_id": "pi_...",
  "decision": "ALLOW",
  "reason_code": "WITHIN_POLICY",
  "receipt_id": "rcpt_...",
  ...
}
```

## What Abazi does with the request [#what-abazi-does-with-the-request]

The model's purchase is an ordinary purchase. Abazi runs the same mandate and policy as for any agent and pays on whichever rail and network the mandate allows and the agent has funded. That includes direct USDT from the agent's spending wallet on Ethereum or Tron, built on Tether's Wallet Development Kit, confirmed on chain before the merchant releases the resource.

| Result | What it means | What the program does |
| --- | --- | --- |
| `paid` | ALLOW. The resource and a `receipt_id` come back. | Call `get_receipt` for the public verification link. |
| `submitted` | ALLOW, still settling. | Poll `get_purchase_status` after `poll_after_ms`. |
| `awaiting_approval` | REQUIRE_APPROVAL, for example <ReasonCode code="ABOVE_AUTO_THRESHOLD" />. The approval link goes to the owner's approvers. | Poll `get_purchase_status` with the same `intent_id`. The link expires after <Limit name="approvalTtl" />. |
| Error `POLICY_DENIED` | DENY, for example <ReasonCode code="HARD_CAP_EXCEEDED" /> or <ReasonCode code="RAIL_NOT_ALLOWED" />. | Report `reason_code` and `next_action`. Never retry with a new key. |

## Why the model gets no wallet [#why-the-model-gets-no-wallet]

A wallet tool in the model's hands would let it send money outside Abazi's reserve, sign and confirm sequence, and outside the receipt chain. Keeping keys in Abazi's signer means a confused or manipulated local model can, at worst, ask for a purchase the mandate then refuses.

## Troubleshooting [#troubleshooting]

| Symptom | Cause and fix |
| --- | --- |
| Tool results carry `AGENT_CREDENTIAL_INVALID` | `ABAZI_AGENT_KEY` is wrong, rotated or revoked (<ReasonCode code="AGENT_CREDENTIAL_INVALID" />). |
| `/models` does not list `local-agent` | The alias in `qvac.config.json` must be `local-agent`, or change `MODEL` to match. Wait for `state` `ready` after the first download. |
| The model answers in text instead of calling a tool | Keep `"tools": true` in the QVAC config and `temperature` at 0. Small models follow a short, direct task best. |
| The purchase stays `awaiting_approval` | A person has not decided yet. Keep polling the same `intent_id`. |
| `IDEMPOTENCY_CONFLICT` | A key was reused with a different request. The program makes a new key per purchase; reuse one only to retry the same purchase. |
| No funded network | Denied with <ReasonCode code="NO_FUNDED_CHAIN" />. The owner funds the agent's spending wallet. |

## Next steps [#next-steps]

<Cards>
  <Card title="Local model guide" href="/docs/guides/local-model-qvac" description="The walkthrough of a local model paying in USDT." />
  <Card title="Supported rails" href="/docs/platform/supported-rails#direct-usdt" description="How direct USDT compares with x402 USDC and cards." />
  <Card title="Any MCP client" href="/docs/agents/any-mcp-client" description="The same MCP connection without a local model." />
  <Card title="All harnesses" href="/docs/agents" description="Compare the other ways to connect." />
</Cards>

