API Reference
Agent 类
本地 Agent SDK 的核心公开接口
Agent 类
Agent 是本地 SDK 中可跨项目复用的主体,拥有身份、指令、模型、自定义 Tool、Plugin 注册和
当前进入的 Workspace 集合,但不拥有永久绑定的 Workspace 或全局 Session 集合。
公开 API
new Agent(options)agent.sessions.create({ workspace })agent.set_instruction(input)agent.get_instructions()agent.get_logger()agent.pluginsagent.dispose()
Session 由 Agent 创建,并在创建时显式选择 Workspace:
const session = await agent.sessions.create({ workspace });构造参数
id:稳定 Agent 身份和私有数据分区键。tools:每个 AgentWorkspace 都会使用的 Agent 自定义 Tool。instruction:Agent 级静态基础指令。model:默认AgentModel,本地 Session 可以覆盖。plugins:只在 Agent 注册一次的 Plugin 对象。session_class:可选的本地自定义 Session 类。
构造参数中没有 workspace。宿主独立创建 Workspace,并在 Agent 需要进入项目执行时调用
agent.sessions.create({ workspace })。
AgentWorkspace
AgentWorkspace 暴露 workspace、sessions、tools、plugins、data_path 与 leave()。
其中的 Session 集合提供 create、get、list、archive、archived、clean_archive、
remove 与 clear_messages。
一个 Agent 可以进入多个 Workspace。agent.dispose() 会离开所有活跃 AgentWorkspace,关闭其中
的 Shell 与存储资源,最后注销 Agent 级 Plugin。@downcity/agent 创建的网络 transport 仍由宿主
负责关闭。