Skip to content

Connect your agent

TypeScript SDK

Ask AgentFox about each message, answer and tool call from a TypeScript or JavaScript agent. The SDK is a thin client for the gateway's guard API, with no runtime dependencies.

Before you start

  • Node 18 or newer, Deno, Bun, a browser or an edge runtime: it uses the global fetch.
  • Your gateway's URL and a key: the server and key from your setup card, or a local gateway (agentfox serve, on http://127.0.0.1:8080).
  • There is no auto() for TypeScript: you call the SDK where your agent reads input, answers and runs tools.
  1. Install it

    bash
    npm install @agentfox/sdk

    The source is sdk/typescript in the repository. If npm still serves an older version than the repository, install from there.

  2. Check what goes in and what comes out

    agent.ts
    import { AgentFox } from "@agentfox/sdk";
    
    const fox = new AgentFox({
      baseUrl: process.env.AGENTFOX_URL!,
      apiKey: process.env.AGENTFOX_API_KEY,
      agent: "support-triage", // your agent's name
    });
    
    const input = await fox.guardInput(userText, { sessionId });
    if (input.stopped) return input.userMessage ?? "Sorry, I can't help with that.";
    
    const answer = await callYourModel(userText);
    
    const output = await fox.guardOutput(answer, { traceId: input.traceId ?? undefined });
    if (output.stopped) return output.userMessage ?? "Sorry, I can't help with that.";
    return output.content ?? answer; // the redacted text when the verdict redacts

    Each call returns a result with verdict (what happened; gate on it), effectiveVerdict (what the policy says, which differs while a rule is in Watch), stopped, userMessage, approvalId and rulesFired.

  3. Check each tool call before it runs

    ts
    const refund = fox.wrapTool(
      async (args: { order_id: string; amount: number }) => payments.refund(args),
      { tool: "payments.refund", provenance: { order_id: "user" } },
    );
    await refund({ order_id: "o_123", amount: 40 });

    provenance says where each argument came from, so a value copied out of a web page is treated differently from one the user typed. A refused call throws PolicyViolation; a call held for a person throws ApprovalRequired with an approvalId. fox.waitForApproval(id) waits for the decision; retry with guardToolCall(tool, args, provenance, { approvalId }) and an approved call goes through once. Pass onBlock to return a value instead of throwing. fox.guardToolCall() is the same check without the wrapper.

    Until the agent is granted the tool (its Access tab, or agentfox permit grant <agent> payments.refund --yes), the call is refused by default-deny.