Browse documentation

Build

Persistent agents

Define behavior once and create durable conversation threads from any client.

An agent defines persistent behavior. A thread is one durable conversation with that agent.

export const coder = app.agent({
  name: "coder",
  instructions: "Inspect the workspace, make the requested change, and check it.",
  tools,
});

The agent uses the application’s default model and Flary’s safe runtime defaults. Its thread keeps messages, tool calls, approvals, model selection, usage, and recovery state.

For repository work, use the complete Codex-style coding agent. It shows the actual built-in grep, read, edit, write, delete, Git, Sandbox, subagent, checkpoint, and realtime APIs.

Add controls only when needed

You can later add an allowed-model list, custom limits, subagents, a mode, or a compaction policy. These controls are optional. Keep them out of the first agent until the product needs them.

Models

An agent can allow explicit provider switching:

models: {
  allow: ["openai/gpt-5", "anthropic/claude-sonnet"],
  switching: "user",
  fallback: "none",
}

Read Providers and connections before you enable model switching. Flary preserves provider-neutral history and does not move private provider state across providers.

Tested starter source

import { app } from "./flary";
import { codingTools } from "./tools";

export const reviewer = app.agent({
  name: "reviewer",
  instructions: `
Review the current workspace diff.
Find concrete defects, missing tests, and unsafe changes.
Do not change files unless the parent asks you to.
`,
  tools: codingTools,
});

export const coder = app.agent({
  name: "coder",
  instructions: `
Work like a careful coding agent:
1. Inspect the workspace before you change it.
2. Use grep and read to find the smallest correct change.
3. Edit files with workspace tools.
4. Run focused checks in the Sandbox when it is available.
5. Review the final diff and report the exact result.
`,
  tools: codingTools,
  subagents: { reviewer },
  delegation: {
    mode: "auto",
    maxConcurrent: 2,
    maxTotal: 4,
  },
});