Skip to content
fastagent-shPublic

About

The TypeScript runtime for production AI agents: write in Markdown & TypeScript, package as an npm artifact, embed in Node.js, self-host with Docker, or deploy to any cloud.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

67 stars

Watchers

1 watching

Forks

Repository files navigation

FastAgent — The TypeScript runtime for production AI agents.

The TypeScript runtime for production AI agents.

English · 简体中文

Write agents in Markdown (SYSTEM.md, skills/), typed TypeScript tools, and MCP — built for engineers and coding agents.
Package as an npm artifact, embed in Next.js, Hono, Express, or Fastify, self-host with Docker, or deploy to Fly.io, Railway, and AWS.

CI npm version MIT License Node version GitHub stars follow @kid7st

Quickstart · Examples · Packaging & CI · Embed · Deploy · Docs · Discussions

FastAgent workflow: write in Markdown and TypeScript, run locally with durable sessions, invoke via CLI or HTTP webhook, and deploy to any host.

Why FastAgent?

Modern teams build with both engineers and coding agents. Visual canvases and proprietary graph DSLs break that workflow, while wrapping raw LLM SDKs forces you to build weeks of backend plumbing by hand.

FastAgent treats an AI agent like normal TypeScript software and ships the production runtime out of the box:

Production problem Built into FastAgent
Graph DSLs are hard for humans and coding agents to maintain Zero DSL: plain Markdown, typed TypeScript tools, MCP, and a --json CLI
Prompts and tools have no clean CI gate or rollback path Versioned npm packages: fastagent build runs tsc and emits dist/
Deploys, crashes, or browser refreshes drop long runs Durable sessions (SQLite, PostgreSQL, Aurora DSQL) and resumable SSE
Webhook retries double-run or corrupt active sessions Idempotent POST /v1/invoke, per-conversation locking, and live steer
Your app already has authentication and a database Native Node.js embedding (openAgent() or Fetch handler) sharing your auth & DB
Secrets leak into shells or containers; tools need isolation Declared needs() secrets, deploy check, OS sandboxing, and AWS microVMs

Quickstart

Requires Node ≥ 24.15 (Node 26 LTS recommended). Client SDKs (@fastagent-sh/client, @fastagent-sh/client-agentcore) support Node 22+, modern browsers, edge runtimes, and Bun.

npm i -g @fastagent-sh/fastagent
fastagent init my-agent && cd my-agent
fastagent dev                 # local server with hot reload & SQLite persistence
fastagent invoke "hello"      # send a message through the Agent API

Using a coding agent? Paste this into Claude Code, Codex, Cursor, or Pi:

Read https://raw.githubusercontent.com/fastagent-sh/fastagent/main/docs/ai-start.md and build an agent in this project.

Tip: Without a global install, run npx @fastagent-sh/fastagent <command> (never npx fastagent, which is an unrelated package). See the full Quickstart.

Write once in Markdown & TypeScript

Every agent is a standalone Git project with zero framework DSL. Both engineers and coding agents can read, refactor, type-check, and review it with standard tools:

my-agent/
├── fastagent.config.ts   # model, tool permissions, MCP servers, sandbox
├── SYSTEM.md             # system prompt (hot-reloaded in dev)
├── AGENTS.md             # optional operating rules
├── skills/               # reusable Agent Skills (skills/<name>/SKILL.md)
└── src/tools/            # typed TypeScript tools (defineTool + needs())
// fastagent.config.ts
import { defineAgent } from "@fastagent-sh/fastagent";

export default defineAgent({
  model: "anthropic/claude-sonnet-4-6",
  codingTools: false, // or ["read", "bash"] with sandbox: "read-only"
  mcpServers: {
    sentry: {
      type: "http",
      url: "https://mcp.sentry.example.com/mcp",
      headers: { Authorization: "Bearer ${SENTRY_MCP_TOKEN}" },
    },
  },
});

Build, verify & ship as an npm package

FastAgent software engineering lifecycle: write in Markdown and TypeScript with humans and coding agents, compile into an immutable npm package with CI gates, and run embedded, sleep-when-idle, or on per-user AWS microVMs.

fastagent build runs tsc, verifies tools and MCP commands, warns on hardcoded credentials, and atomically emits an ESM npm package in dist/ (with index.js, index.d.ts, a SHA-256 build.json fingerprint, and peerDependencies so multi-agent hosts share one runtime):

# In CI (non-interactive, deterministic exit codes 0 / 1 / 2)
npm exec -- fastagent info --json
npm exec -- fastagent build --json          # type-checks and emits immutable dist/ npm package
npm exec -- fastagent deploy check --json   # blocks builds if .secrets/, .env*, or .state/ would leak

# Publish to your private registry (or consume in a monorepo workspace)
npm publish ./dist --access restricted

Upgrading or rolling back an agent is a standard SemVer version change (npm i @acme/[email protected]), and platform teams can host multiple teams' compiled npm agent packages inside one Node.js host with unified auth and observability. See Packaging, Distribution & CI/CD.

Embed, self-host, or call over HTTP

Use the same compiled agent package across every runtime shape with zero code rewrites.

Embed in your Node.js app (Next.js, Hono, Express, Fastify)

Keep your own authentication, tenancy rules, and PostgreSQL pool:

import { baseEnv, openAgent, openPostgresDatabase } from "@fastagent-sh/fastagent";
import copilot from "@acme/saas-copilot"; // versioned npm package from `fastagent build`

const db = openPostgresDatabase({ url: process.env.DATABASE_URL! }, { max: 20 });

const agent = await openAgent(copilot, {
  root: "/var/lib/myapp/tenants/acme",
  name: "tenant-acme",
  database: db, // share one pool across tenants
  secrets: { OPENAI_API_KEY: process.env.OPENAI_API_KEY },
  env: baseEnv(process.env),
});

const session = await agent.sessions.create();
for await (const event of agent.messages.stream({ sessionId: session.id, content: "Summarize my usage" })) {
  if (event.type === "delta" && event.channel === "text") render(event.text);
}

Self-host with Docker or deploy to your cloud

# Targets: docker | compose | fly | railway | agentcore
fastagent deploy init fly
fastagent deploy check

# Optional: kernel-enforced OS sandboxing (sandbox-exec / bwrap / Landlock)
fastagent dev --harness dsh --sandbox read-only

Call from webhooks, cron jobs, CI, or edge workers

@fastagent-sh/client has zero Node.js dependencies and runs anywhere fetch exists:

import { connectAgent } from "@fastagent-sh/client";

const agent = connectAgent("https://agent.example.com", {
  apiKey: process.env.AGENT_API_KEY!,
});

// Wakes a sleeping container (up to 600s wait), deduplicates retries, and steers if already running
const reply = await agent.invoke(
  {
    conversation: "incident:inc-415",
    idempotencyKey: webhookEventId,
    whenBusy: "steer",
    content: alertSummary,
  },
  { wait: 300 },
);
console.log(reply.status, reply.answer?.text);

Cost & scale

Pick the hosting topology that matches your workload and budget without changing agent or caller code:

Scale & workload Typical bottleneck FastAgent pattern Quantified architecture impact
1–20 background agents
(PR review, AI SRE, daily briefs)
Always-on containers sit idle 95%+ of the day Sleep when idle on Fly.io (suspend) or Railway (App Sleeping) woken via POST /v1/invoke ~98% less idle compute vs 24/7 containers (20 runs/day × 1 min ≈ 10 active hrs/mo vs 720 always-on hrs/mo)
100–1,000+ SaaS tenants
(embedded product copilot)
Per-tenant services, 1,000 DB pools, or lease heartbeats overload Postgres Embed in your backend via openAgent() + shared openPostgresDatabase({ url }, { max: 20 }) (codingTools: false) 0 extra services; 1 fixed 20-connection pool with batched lease renewals (up to 500 tenants/query) and cooperative idle handoff across replicas
100–10,000+ isolated users
(per-user coding & shell assistants)
Operating hundreds of always-on VMs and idle costs Per-user AWS MicroVMs on Bedrock AgentCore + 1 shared serverless Aurora DSQL cluster (pi-durable or dsh) 0 always-on servers; microVMs recycle when idle and resume from 1 shared DSQL cluster (or swap to fixed-price Postgres via FASTAGENT_DATABASE_URL)
Local-first desktop apps
(Electron, local workspace tools)
Shipping Python runtimes or forcing cloud relays for local files Embed locally via openAgent() + built-in node:sqlite + optional dsh OS sandbox 0 cloud services and 0 native DB builds; offline durable state with dynamic model pickers (agent.info().models)

Single-writer fencing guarantees one active owner per instance (default limits: inFlightPerProcess: 100, queuedPerSession: 20). Scale horizontally across instances or automatically per user on AgentCore.

Production examples

Clone a complete working agent from examples/:

Example Runs on Key capabilities
Multi-Tenant SaaS Copilot Embedded (Hono + PostgreSQL) Shared DB pool, codingTools: false, resumable SSE
Sandboxed PR Review Agent Self-hosted + GitHub Actions Read-only OS sandbox, per-PR memory, idempotent retries
Sleep-When-Idle AI SRE Fly.io + Alert Webhooks Alert deduplication, mid-run steer, MCP servers
Deep Research & Daily Brief Self-hosted + External Cron Long crash-resilient runs, live terminal attach via Pi
Per-User AWS MicroVM Agent AWS Bedrock AgentCore Per-user microVM, Aurora DSQL, Secrets Manager, IAM auth

When to use FastAgent

Need Workflow Frameworks Raw LLM SDKs Coding CLIs FastAgent
How you write it Graph DSLs & chains Custom loop in code Local terminal Markdown, skills, typed TS tools, MCP (zero DSL)
Packaging & CI App-coupled code App-coupled code Not packageable Compiled npm packages, tsc, --json CI gates
Embed in Node.js Separate service / glue Stateless by default Not embeddable Native openAgent() + shared Postgres pool
Scale & isolation DIY hosting & sandbox DIY hosting & sandbox Local machine Docker, sleep-when-idle cloud, AWS microVMs, OS sandbox

Compared: Workflow frameworks (LangGraph, CrewAI), Raw LLM SDKs (Vercel AI SDK, OpenAI SDK), Coding CLIs (Claude Code).

Not the right fit if you want:

  • A visual no-code canvas for non-engineers → use Dify or n8n.
  • An interactive local coding assistant only on your laptop → use Claude Code, Codex, or Pi.
  • A static deterministic DAG workflow engine → use Temporal or Inngest.

Architecture & operations

Every caller speaks one contract: the Agent API. Swap models, storage backends, hosts, or execution harnesses without changing your agent or application code:

Callers (CLI · openAgent · @fastagent-sh/client · client-agentcore · @fastagent-sh/pi-remote)
                                        │  Agent API (/v1)
┌───────────────────────────────────────▼───────────────────────────────────────┐
│ Unified Runtime Layer (@fastagent-sh/fastagent)                               │
│  Build · defineTool · needs() Secrets · Models & Durable Auth · MCP · OTLP    │
└───────────────────┬───────────────────────────────────────┬───────────────────┘
                    │                                       │ (optional, lazy)
         ┌──────────▼──────────┐                 ┌──────────▼──────────┐
         │ pi-durable (default)│                 │ @fastagent-sh/      │
         │ SQLite / PostgreSQL │                 │ harness-dsh         │
         │ / Aurora DSQL       │                 │ + Kernel OS Sandbox │
         └─────────────────────┘                 └─────────────────────┘
  • Privacy-safe tracing: Export cost, token, and tool spans via OpenTelemetry (OTEL_EXPORTER_OTLP_ENDPOINT) without logging prompts or answers.
  • Remote CLI & OAuth: Manage live instances (fastagent remote add prod <url>) and complete provider OAuth remotely (fastagent login openai-codex --remote prod).
  • Live terminal attach: Inspect or steer running remote sessions from your terminal with @fastagent-sh/pi-remote.

Packages & documentation

Package Role Runtime baseline
@fastagent-sh/fastagent Core runtime (pi-durable), openAgent, defineTool, openPostgresDatabase, HTTP server, CLI Node ≥ 24.15 (26 LTS recommended)
@fastagent-sh/client Zero-Node-dep HTTP Agent API & Auth client (connectAgent, connectAuth) Node 22+, Browsers, Edge, Bun (ES2024)
@fastagent-sh/client-agentcore Zero-Node-dep Amazon Bedrock AgentCore client (connectAgentCore, connectAgentCoreAuth) Node 22+, Browsers, Edge, Bun (ES2024)
@fastagent-sh/agentcore AWS AgentCore server runtime, Aurora DSQL adapter, Secrets Manager, CDK construct Node ≥ 24.15 (26 LTS recommended)
@fastagent-sh/harness-dsh Optional DeepSeek Harness (@deepseek-ai/dsh) adapter with kernel OS sandboxing (experimental) Node ≥ 24.15 (26 LTS recommended)
@fastagent-sh/pi-remote Pi TUI extension (/fa) for live terminal access to deployed HTTP or AgentCore instances Node ≥ 24.15 (26 LTS recommended)

Documentation (docs/): Overview · Quickstart · Packaging & CI · AI Guide · Architecture · Agent API · Configuration · MCP · Embedding · Deploy · AgentCore · Remotes · CLI · API Reference · Troubleshooting

Community & status

FastAgent is pre-1.0 with the Agent API as its stable contract. See releases, join GitHub Discussions, or read Contributing, Code of Conduct, Security, and the MIT license.

☁️ Prefer managed hosting? FastAgent Cloud adds managed multi-instance durability, sleep-when-idle hosting, and observability while self-hosting stays free. Join the waitlist →

Powered by pi (pi-durable & pi-ai), Effect, undici, node-postgres, and optional OS sandboxing via @deepseek-ai/dsh. Scaffolded writing-great-skills vendored from mattpocock/skills.

If FastAgent saves you from building agent infrastructure from scratch, give it a ⭐.

About

The TypeScript runtime for production AI agents: write in Markdown & TypeScript, package as an npm artifact, embed in Node.js, self-host with Docker, or deploy to any cloud.

Topics

Resources

Code of conduct

Contributing

Security policy

Stars

67 stars

Watchers

1 watching

Forks

Releases

Packages

Used by

Contributors

Languages