agent-squad-typescript
它能做什么
这份指南帮助 AI 编写一个使用 agent-squad 包运行多个 AI 智能体的 Node.js 或 TypeScript 应用。它适合在服务器上构建 AI 助手的开发者。
适用场景
- ✓当我想组建一个 AI 智能体团队,每个智能体负责不同主题的时候。
- ✓当我需要一条 AI 步骤链,每一步都把结果传给下一步的时候。
- ✓当我的 AI 回答需要参考我自己的文档或知识库的时候。
技能链接
https://github.com/2FastLabs/agent-squad/blob/main/typescript/SKILL.md复制后粘贴给你的 AI(Claude、ChatGPT 或 Cursor),让它按照说明操作。
使用方法
最简单的方法:复制下面的消息,粘贴给你的 AI。它会读取这个技能并按说明操作。
可直接粘贴的消息
适用于 Claude Code、Codex 或 Cursor:在项目文件夹中运行,即可安装该技能。
下载 SKILL.md,放进智能体的技能文件夹。
可以这样问 AI
“我想搭建一个 TypeScript 应用,让多个 AI 智能体分别回答不同类型的问题。应该如何开始?”
每周 5 个新技能,1 分钟读完。
工作原理
它会告诉 AI 应使用这个包的哪些部分,例如协调器、智能体、路由和存储,以及应避免什么。具体的代码细节以包本身为准。
技术内容(原始 SKILL.md)
作者在 GitHub 上的英文原文。
agent-squad TypeScript — assistant guide
Node.js / TypeScript multi-agent orchestration framework (npm package agent-squad). All public
symbols are exported from a single barrel typescript/src/index.ts. This file is guidance and a
map — not an API reference. Read exact signatures from
typescript/src/ and worked recipes from docs/src/content/docs/; this file tells you what to
use, when, and what to watch out for.
When to use what
- One assistant → a single
Agentsubclass +AgentSquadwith no routing. Or skip the orchestrator entirely and callagent.processRequest(...)directly. - Several specialists → multiple agents registered with
orchestrator.addAgent(agent), a classifier routes each turn. - Answers must not drift from data (prices, balances, live lookups) →
GroundedAgent: a gatherer LLM calls tools, an isolated presenter LLM speaks only from the curated results. - Fixed pipeline →
ChainAgent: each agent's output is the next agent's input. - One lead LLM coordinating a team →
SupervisorAgent: the lead calls sub-agents as tools. - External tools via MCP →
MCPToolProvider(async factory pattern, optional peer dep). - RAG context → attach a
Retrieverto any agent that supportsretriever?in its options.
How to install
npm install agent-squad
Optional peer dependencies — install only what you use:
| Package | Used by |
|---|---|
@aws-sdk/client-bedrock-runtime |
BedrockLLMAgent, BedrockClassifier (already a hard dep in current releases) |
@anthropic-ai/sdk |
AnthropicAgent, AnthropicClassifier (already a hard dep) |
openai |
OpenAIAgent, OpenAIClassifier (already a hard dep) |
@modelcontextprotocol/sdk |
MCPToolProvider — lazy await import() at connect time |
@dakera-ai/dakera |
DakeraRetriever — lazy require() at construction time |
@modelcontextprotocol/sdk and @dakera-ai/dakera are the only two true optional peer deps;
everything else ships as a hard dependency at the moment.
How a turn works
routeRequest is the single entry point. It classifies the input, dispatches to the selected
agent, saves the exchange, and returns an AgentResponse. The response is either a plain string or
a Node.js Transform stream:
import { AgentSquad, BedrockLLMAgent, BedrockClassifier } from 'agent-squad';
const orchestrator = new AgentSquad({
classifier: new BedrockClassifier(), // default when omitted
// storage: new DynamoDbChatStorage(...),
// config: { LOG_AGENT_CHAT: true, MAX_MESSAGE_PAIRS_PER_AGENT: 50 },
});
orchestrator.addAgent(new BedrockLLMAgent({
name: 'Tech Support',
description: 'Handles technical questions about software and hardware',
streaming: true,
}));
const response = await orchestrator.routeRequest(
userInput,
userId,
sessionId,
additionalParams // optional Record<string, any>
);
if (response.streaming) {
// response.output is an AccumulatorTransform (Node.js Transform)
for await (const chunk of response.output) {
process.stdout.write(chunk);
}
} else {
// response.output is a string
console.log(response.output);
// response.thinking? is set when the agent used extended thinking
}
// response.metadata: { agentId, agentName, userId, sessionId, userInput, additionalParams }
routeRequest never throws — it catches all errors and returns them as a non-streaming
AgentResponse with the error string in output (configurable via GENERAL_ROUTING_ERROR_MSG_MESSAGE).
The pieces
Orchestrator: AgentSquad
new AgentSquad(options?: OrchestratorOptions)
Key OrchestratorOptions fields:
| Field | Default | Notes |
|---|---|---|
classifier |
new BedrockClassifier() |
Any Classifier subclass |
storage |
new InMemoryChatStorage() |
Any ChatStorage subclass |
defaultAgent |
undefined |
Used when classifier returns no match and USE_DEFAULT_AGENT_IF_NONE_IDENTIFIED is true |
config.USE_DEFAULT_AGENT_IF_NONE_IDENTIFIED |
true |
Fall back to defaultAgent or return NO_SELECTED_AGENT_MESSAGE |
config.MAX_MESSAGE_PAIRS_PER_AGENT |
100 |
Per-agent history cap (pairs = user+assistant) |
config.MAX_RETRIES |
3 |
Classifier retries on bad XML response |
config.LOG_AGENT_CHAT |
false |
Useful methods: addAgent(agent), setDefaultAgent(agent), getDefaultAgent(),
getAllAgents(), analyzeAgentOverlap(), classifyRequest(...), `agentProcess
常见问题
智能体的数据可以存储在哪里?
该包支持内存存储、DynamoDB 和 SQL 数据库,你可以选择适合自己的一种。
如何安装这个包?
这份指南使用 agent-squad 包的标准 npm 安装命令,只有在需要时才添加可选的扩展。
智能体可以使用 MCP 工具吗?
可以。MCP 工具提供者可以让智能体使用外部服务器上的工具。
详情
作者的原始描述
Use when building or modifying a Node.js / TypeScript app that uses the agent-squad npm package — multi-agent orchestration: orchestrator, agents (all built-in types + GroundedAgent), classifier routing (Bedrock / Anthropic / OpenAI), storage (in-memory / DynamoDB / SQL), retrievers (Amazon KB / Dakera), and tools (AgentTools + MCPToolProvider).
repo: 2FastLabs/agent-squad
热度
- GitHub 星标
- 7.8k
- 排名
- #12832
- 许可证
- Apache-2.0
- 更新时间
- 2026/10/8
评论
- …