@animahealth/adk

中文文档
0.6.13发布于 2026/11/06MITTypeScriptESM + CJS构建来源已验证近 30 天下载 7.4万

Anima Agent Development Kit - Framework for building production-grade multi-agent AI systems

原始使用文档
文档目录9 节
  1. Install
  2. First run — no API key
  3. Quick start — live
  4. Evaluation CLI
  5. Execution completion and persistence
  6. What's in the box
  7. Stability
  8. Testing
  9. Contributing, security, license

Anima ADK

A TypeScript framework for production multi-agent AI systems — schema-first, event-sourced, and provider-agnostic. Built and used in production at Anima to run clinical and operational agent workflows.

Documentation: adk.animahealth.com — runnable docs: every code cell on the site executes this shipped package in your browser.

The ADK is a library, not a platform: no infrastructure dependency beyond a database you choose (or none — the in-memory and SQLite backends need nothing). Every layer is independently useful.

  • One session ledger. Everything an agent does is an append-only event history; all state derives from it. Time travel, forking, and auditing come for free.
  • Agents that stop and ask. Tools can yield: the run pauses, the session persists as a row, and a human (or another system) resumes it — minutes or days later.
  • The model sees what you choose. Context renderers are the only bridge between the ledger and the prompt, so full audit coexists with a small context.
  • Deterministic testing. The test kit replaces only the model with scripted turns — tools really execute, state really writes — so agent tests run with no API key.
  • Providers behind subpaths. OpenAI, Gemini, Claude (via Vertex), and EUrouter are optional integrations behind @animahealth/adk/openai and friends. Importing the core pulls in none of them.

Install

npm install @animahealth/adk

Node ≥ 22. zod is the one required peer (npm and pnpm install it automatically). The ADK accepts Zod 3 Classic from 3.25.76 and Zod 4 Classic from 4.6.5; an existing Zod 3 application does not need to migrate to Zod 4. Optional backends declare optional peers — install them only for what you use (for example better-sqlite3 for the SQLite session store).

First run — no API key

The real agent loop over a scripted model turn. Tools execute, state writes, the ledger accrues; only the model is played by the script.

import { getLastAssistantText, runTest, user, model, mockAgent } from '@animahealth/adk/testing'

const greeter = mockAgent('greeter')
const result = await runTest(greeter, [user('hi'), model('Hello! Ask me anything.')])

console.log(getLastAssistantText(result.events)) // Hello! Ask me anything.
console.log(result.events.map((e) => e.type))
// [ 'user', 'invocation_start', 'model_start', 'assistant', ... ]

Quick start — live

export OPENAI_API_KEY=sk-...
import { z } from 'zod'
import { adk } from '@animahealth/adk'
import { openai } from '@animahealth/adk/openai'

const app = adk()

const calculator = app.tool({
  name: 'calculate',
  description: 'Evaluate a mathematical expression',
  schema: z.object({
    expression: z.string().describe('Math expression to evaluate'),
  }),
  execute: (ctx) => {
    const sanitized = ctx.args.expression.replace(/[^\d\s+\-*/().eE%]/g, '')
    const result = Function(`"use strict"; return (${sanitized})`)()
    return { result }
  },
})

const assistant = app.agent({
  name: 'math_assistant',
  model: openai('gpt-5.6-luna'),
  context: [
    app.context.system(`You are helpful, use the calculator tool for arithmetic.`),
    app.context.history(),
  ],
  tools: [calculator],
})

const result = await app.run(assistant, 'What is 134 divided by 4?')
console.log(result.output.text) // 134 divided by 4 is 33.5.

Gemini ships behind @animahealth/adk/gemini (AI Studio or Vertex) and Claude behind @animahealth/adk/claude (Vertex AI). Provider setup lives in each subpath's typed config.

EUrouter ships behind @animahealth/adk/eurouter for hosted models such as DeepSeek, Kimi, and GLM. See the provider guide for credentials, routing, and a local example that needs no key.

Evaluation CLI

Text and voice cases can share one evaluation and one CLI entry point:

async function main() {
  process.exitCode = await app.evaluate.cli([...textCases, ...voiceCases], {
    concurrency: 4,
  })
}
void main()

Call the entry script with list, or run --case <name> --repeat 3 --output ./runs. The CLI writes JSON to stdout, diagnostics to stderr, and reports and case evidence to a fresh run directory. Use silent package scripts when parsing stdout. It exits successfully only when every selected execution passes. Normal imports still run before the CLI, so keep them quiet.

Use app.evaluate(cases, options) for the same mixed suite without command-line handling. Voice-specific hooks, metrics and room configuration belong in options.voice. See the mixed voice example.

For native voice with ADK backend tools, GPT Live voice handler documents openai.live(...) with app.handler.voice(...), typed result hooks, and transcript persistence.

For speech that has no structural signal, the judge metric documents app.evaluate.judge(...), an LLM-judge metric for text and voice cases, and when to use a state or event metric instead.

Execution completion and persistence

app.run() starts execution immediately. Awaiting it returns its outcome; a run deadline or run.abort() rejects promptly. run.settled always fulfills after ADK-owned execution and cleanup finish and their ledger events are buffered. Use it before committing or closing a session store:

const run = app.run(assistant, { session, timeout: 30_000 })
try {
  return await run
} finally {
  run.abort()
  await run.settled
  await app.sessions.commit(session)
}

Completion is neither success nor durable storage. Admitted tools, their retry chains, inline child runs and spawned/dispatched work remain owned until they finish. A tool can outlive its own timeout; the timeout receipt stays authoritative and settled waits for the underlying work. A tool or hook that never finishes can keep settled pending. Detached application promises are outside this contract. Root run cancellation prevents new model/tool admissions after awaited hooks. ctx.run's local handoff timeout and an agent's duration policy retain their existing behavior; a local handoff timeout does not itself cancel the child or guarantee its terminal invocation event. Cancel the root run before draining when stopping the whole operation. Breaking stream iteration cancels it; handler.turn provides the same separate completion barrier, including its persistence work.

What's in the box

Entry pointSurface
@animahealth/adkThe app: agents, steps, sequence/parallel/loop, tools, yielding tools, orchestration (run/spawn/dispatch/transfer, app.ask, fanout), context renderers, sessions and typed state scopes, memory, structured output with a forgiving parser, hooks, error handlers, the turn/REST/AG-UI handlers, MCP
/openai · /gemini · /claude · /eurouterModel provider configs and adapters
/stores/sqlite · /stores/postgres · /stores/dynamodbDurable session stores behind one SessionStore contract (in-memory ships in the core)
/voyage · /qdrantEmbedders and served vector backends (pgvector, sqliteVec, and inMemoryIndex ship in the core)
/testingThe deterministic test kit: runTest, mockAgent, MockAdapter, matchers
/evalEvaluation suites, metrics, reports, simulation
/voiceThe LiveKit voice handler and realtime models
/webWeb tools: search, fetch, screenshot
/agui · /terminalThe AG-UI protocol adapter and the interactive terminal UI

Stability

The ADK is pre-1.0 and favors one clear API over compatibility aliases. Two tiers:

  • Core — the main entry and every subpath above. Changes arrive deliberately and are documented in the CHANGELOG.
  • Experimental — /workflow (dynamic multi-agent workflows and the Claude-Code-compatible workflow-file loader), /agents/coding and /agents/coding/claude-code (coding agents over provisioned workspaces), and /executors (Docker/Modal workspace executors). Any release may change or remove these without a deprecation cycle; pin your version.

Experimental surfaces are reachable only through their own subpaths, never through the main entry — a build gate enforces it.

Testing

pnpm install
pnpm run test

The suite runs with no API keys and no database. Every documented session store and vector backend also runs a shared compliance suite against real service containers in CI — the contract claims are continuously proven, not asserted.

Contributing, security, license

This repository is a continuously exported snapshot of the ADK's development home — see CONTRIBUTING.md for how issues and pull requests flow (short version: issues are the front door, and accepted PRs are imported with your authorship preserved). Report vulnerabilities via SECURITY.md, not public issues.

MIT © Anima Health.

版本与发布记录

@animahealth/adk 共发布 54 个版本,首次发布于 2026/01/30;过去 12 个月发布了 54 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.6.13latest2026/11/06今天
0.6.122026/10/306 天前
0.6.112026/10/298 天前
0.6.102026/10/289 天前
0.6.92026/10/2215 天前
0.6.82026/10/1522 天前

关于 @animahealth/adk 的常见问题

@animahealth/adk 是什么?

Anima Agent Development Kit - Framework for building production-grade multi-agent AI systems

如何安装 @animahealth/adk?

在项目目录运行 npm install @animahealth/adk,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:zod(^3.25.76 || ^4.6.5)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@animahealth/adk 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@animahealth/adk 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@animahealth/adk 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.0.0。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@animahealth/adk 可以商用吗?

@animahealth/adk 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@animahealth/adk 的下载量有多少?

根据 npm 官方下载统计,@animahealth/adk 在 2026/10/06 – 2026/11/04 这 30 天内被下载 73,742 次,日均约 2,458 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@animahealth/adk 还在维护吗?

最新版本 0.6.13 发布于 2026/11/06(今天);至今共发布 54 个版本,其中过去 12 个月发布了 54 个;首次发布于 2026/01/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。