Skip to main content

Documentation Index

Fetch the complete documentation index at: https://docs.ai-stats.phaseo.app/llms.txt

Use this file to discover all available pages before exploring further.

Use this recipe when you want more than a one-shot text request:
  • multi-step tool loops
  • local runtime tools
  • resumable runs
  • a single gateway-backed entrypoint for agent work

1. Install the SDKs

npm install @ai-stats/sdk @ai-stats/agent-sdk

2. Define one small runtime tool

Keep the first tool deterministic and easy to inspect.
import { defineTool } from "@ai-stats/agent-sdk";

export const lookupDocs = defineTool({
  id: "lookup-docs",
  description: "Look up internal docs by slug.",
  async execute(input: { slug: string }) {
    return {
      slug: input.slug,
      url: `https://docs.ai-stats.phaseo.app/v1/${input.slug}`,
    };
  },
});

3. Create the agent

import { createAgent } from "@ai-stats/agent-sdk";
import { lookupDocs } from "./tools";

export const supportDocsAgent = createAgent({
  id: "support-docs-agent",
  model: "ai-stats/free",
  instructions: "Use tools when helpful and finish with a concise answer.",
  tools: [lookupDocs],
});

4. Use the gateway-backed adapter

import {
  createGatewayAgentClient,
} from "@ai-stats/agent-sdk";
import { supportDocsAgent } from "./agent";

const result = await supportDocsAgent.run({
  input: "Find the docs page for presets and explain when to use them.",
  client: createGatewayAgentClient({
    clientOptions: {
      apiKey: process.env.AI_STATS_API_KEY!,
    },
  }),
});

console.log(result.output);

5. What persists between steps

Each completed step updates returned run state with:
  • the run id
  • the message history
  • any returned tool calls
  • any local tool results
  • the final output when the run completes
If you want resumability across requests or processes, persist that returned value in your own application and pass it back into continueRun() later.

6. When to keep the first version simple

  • one agent per workflow
  • application-owned serialization before any cross-request resume flow
  • a small tool list before generic tool registries
  • one log line per run with the run id and gateway request id

7. When to move beyond this recipe

Move past the first durable loop when you need:
  • approval pauses
  • application-owned persistence for returned run state
  • multiple agent definitions with shared runtime tools
At that point, keep the same gateway-backed adapter and evolve the store and orchestration around it.
Last modified on May 19, 2026