配置
DeepSeek
Section titled “DeepSeek”DeepSeek 提供 Anthropic 兼容接口,所以只需要配置 baseURL 并使用 DeepSeek 模型名。
import { createAgent } from "agent-lattice";
const agent = createAgent({ apiKey: process.env.DEEPSEEK_API_KEY, baseURL: "https://api.deepseek.com/anthropic", model: "deepseek-v4-flash", systemPrompt: "你是一个简洁的工程助手。", maxTokens: 16384, maxTurns: 50,});Anthropic
Section titled “Anthropic”直接使用 Anthropic 时可以省略 baseURL:
const agent = createAgent({ apiKey: process.env.ANTHROPIC_API_KEY, model: "claude-sonnet-4-6", systemPrompt: "你是一个简洁的工程助手。",});使用 systemPrompt 定义 agent 的稳定角色、职责和边界。团队场景尤其需要它,因为每个真正工作的 Agent 都应该有自己的职责描述。
const backendAgent = createAgent({ apiKey: process.env.DEEPSEEK_API_KEY, baseURL: "https://api.deepseek.com/anthropic", model: "deepseek-v4-flash", systemPrompt: [ "你是 backend 执行 agent。", "你负责 API、数据模型、存储、集成和服务端正确性。", "遇到产品或 UI 决策时向上级反馈,不要擅自假设。", ].join("\n"),});Workspace
Section titled “Workspace”每个 agent 默认都有自己的私有 workspace,用于存储持久化文件、代码、报告、日志和测试证据。workspace 属于这个 agent,不属于 Team 或 teamMember() 定义。
默认路径是 ~/.agent/workspaces/<agent-name>。如果 agent 没有 name,则使用 ~/.agent/workspaces/agent-<session-id>。
const backendAgent = createAgent({ apiKey, name: "backend", model, systemPrompt: "你是 backend 执行 agent。",});只有当宿主想覆盖默认位置时,才需要显式传入 workspace:
const backendAgent = createAgent({ apiKey, name: "backend", model, workspace: ".agent-workspaces/backend",});SDK 会自动给 agent 增加 workspace 工具,并注入说明:交付时用自然语言汇报重要路径和验证结果。
传 workspace: false 可以完全关闭内建工作区:不装内建文件/Shell 工具,也不加 workspace 提示段落——等价于 createBareAgent()。需要 0.23.0 及以上版本。 与 createBareAgent() 不同,这个选项对 defineAgent() 也生效,defineAgent({ workspace: false }) spawn 出来的就是裸会话。适合不需要任何文件系统和 Shell 权限面的 typed 委派专科子 agent。
Bare agent
Section titled “Bare agent”当宿主需要一个不带默认提示词、不带默认工具、也不创建 workspace 目录的纯模型循环时,使用 createBareAgent()。它适合已经由宿主提供 sandbox 的应用、需要精确控制工具列表的测试,或由应用自己组装能力的 wrapper。
import { createBareAgent, createBuiltinTools } from "agent-lattice";
const agent = createBareAgent({ apiKey, model, systemPrompt: "你是一个简洁的工程助手。", tools: createBuiltinTools({ cwd: process.cwd(), allowedDirectories: [process.cwd()], }),});大多数需要产出持久文件的 agent 应该使用 createAgent()。只有当应用要显式拥有每一项能力时,才选择 createBareAgent()。
AbortSignal 会中断当前模型请求和后续工具循环:
const controller = new AbortController();
setTimeout(() => controller.abort(), 5000);
const result = await agent.prompt("总结这个仓库。", { signal: controller.signal,});Query options
Section titled “Query options”| 选项 | 类型 | 默认值 | 说明 |
|---|---|---|---|
stream |
boolean |
true |
是否启用模型流式调用,并输出 stream_event 事件。 |
signal |
AbortSignal |
undefined |
取消当前模型请求和工具循环。 |
maxTurns 统计的是模型请求次数,不是工具执行次数。默认值是 50,这样多智能体和重工具调用流程有足够空间完成,同时仍然能防止无限循环。
小型一次性工具或测试场景可以显式调低:
const agent = createAgent({ apiKey, model, maxTurns: 8,});