AI守护进程
基于Spring Boot 4和Spring AI构建的轻量级AI框架。连接任何LLM提供商,用技能和MCP扩展功能,安排自主作业,并通过REST、Web UI或终端进行交互——所有这些都可以从一个自托管服务中实现。
建筑
graph TB
User([User])
subgraph Interface["Interface Layer"]
REST[REST API]
WebUI[Web UI]
CLI[Interactive CLI]
end
User -->|HTTP / curl| REST
User -->|Browser| WebUI
User -->|Terminal| CLI
WebUI --> REST
subgraph Engine["AI Engine"]
Chat[Chat Service]
Conv[Conversation Manager]
Providers[Provider Registry]
Memory[Persistent Memory]
Skills[Skills Reader]
Shell[Shell Executor]
Scheduler[Job Scheduler]
MCPTools[MCP Tools]
end
subgraph Providers_Sub["LLM Providers"]
OpenAI[OpenAI]
Anthropic[Anthropic]
Gemini[Gemini]
Ollama[Ollama / Local]
end
subgraph External["External Integrations"]
MCPRemote[Remote MCPs]
MCPLocal[Local MCPs - stdio]
Smithery[Smithery Skills Registry]
end
subgraph Storage["~/.aidaemon/"]
ProvidersJSON[providers.json]
MemoryJSON[memory.json]
JobsJSON[jobs.json]
ConversationsDir[conversations/]
SkillsDir[skills/]
McpsDir[mcps/]
end
REST --> Chat
REST --> Conv
CLI --> Conv
Conv -->|multi-turn history| Chat
Chat --> Providers
Providers --> OpenAI & Anthropic & Gemini & Ollama
Chat -->|tool calls| Memory & Skills & Shell & Scheduler & MCPTools
Memory -->|read/write| MemoryJSON
Skills -->|read| SkillsDir
Scheduler -->|persist| JobsJSON
Scheduler -->|executes via| Chat
Conv -->|persist| ConversationsDir
MCPTools --> MCPRemote & MCPLocal
MCPRemote & MCPLocal -.->|config| McpsDir
Smithery -->|install all files| SkillsDir
Providers -.->|persist| ProvidersJSON
Shell -->|guarded by flag| OS[Host OS]
style User fill:#f9f,stroke:#333
style Storage fill:#c9a800,stroke:#333,color:#fff
style External fill:#1a7a7a,stroke:#333,color:#fff授权
启用委派后,主代理可以生成子代理以并行处理子任务。子代理异步运行;当它们完成时,家长会被状态更新唤醒,可以综合结果或发送修订工作。 子代理可以创建自己的子代理。该图简单地显示了一个父代理和一个顶级子代理。
sequenceDiagram
participant User
participant Parent as Parent Agent
participant DelegationService
participant Sub1 as Sub-agent 1
participant Sub2 as Sub-agent 2
User->>Parent: Message
Parent->>Parent: Estimates time > threshold
Parent->>DelegationService: delegateToSubAgent x2
DelegationService->>Sub1: Create and run sub-conversation
DelegationService->>Sub2: Create and run sub-conversation
Parent->>User: Delegated, will respond when ready
Sub1->>DelegationService: Completed
Sub2->>DelegationService: Completed
DelegationService->>Parent: Delegation Status Update with sub results
Parent->>Parent: Review, addWorkToSubAgent or synthesize
Parent->>User: Final response- 工具:
delegateToSubAgent(name, instruction)创建子对话并将其排队。addWorkToSubAgent(subConversationId, instruction)在审查其输出后,将后续工作发送给子代理。 - 配置:
aidaemon.delegation-enabled=true,aidaemon.delegation-threshold-seconds=30当模型的估计时间超过阈值时,指示模型进行委托。
特性
- 多供应商 --OpenAI、Anthropic、Gemini、Ollama。使用API密钥持久性在运行时添加/删除提供程序。
- 对话 --有状态的多回合会话,具有完整的聊天历史记录,在以下情况下持续存在
~/.aidaemon/conversations/。已选择提供商(代理) 按提示:为对话设置或更改它,以便下一条消息使用该提供程序。对话有创建时间戳,可以按时间排序。 - 流媒体 --对话消息可以通过以下方式发送
POST /api/conversations/{id}/messages/stream上海证券交易所块包括reasoning,answer,以及tool类型,以便UI可以实时显示思维和工具。 - 授权 --可选的子代理委托:AI将工作拆分为并行运行的子对话;当它们完成时,家长会收到通知,可以综合或请求修改。启用
aidaemon.delegation-enabled=true. - 思考/推理 --支持暴露它的提供者(例如Anthropic扩展思维)。推理是单独流式传输的,并在Web UI中显示;计划作业结果包括存储输出中的思考。
- 快速缓存 --在支持的情况下(例如Anthropic、Gemini)使用对话历史和提示缓存来降低成本和延迟。
- 上下文窗口 --可选
aidaemon.context-window.chars-limit(字符限制)修剪旧消息,对于命名的机器人,修剪个人记忆,使提示适合。使用aidaemon.context-window.personal-memory-ratio(0–1)在对话历史和机器人个人记忆之间分配预算。AI可以使用retrieveOlderMessages当上下文被修剪时,用于获取旧对话内容的工具。 - 持久内存 --AI可以通过以下方式在会话之间保存和回忆信息
memory.json. - 技能 --将指令文件放入
~/.aidaemon/skills/或从安装 铁匠铺 通过REST端点。AI根据特定领域的上下文读取它们。 - MCP支持 --连接远程(流式HTTP、SSE)和本地(stdio)MCP服务器。将JSON配置放入
~/.aidaemon/mcps/并重新加载或添加 铁匠铺-通过聊天(Notion、谷歌日历等)托管MCP。 - 预定作业 --AI创建cron作业(重复或一次性),按计划自主执行指令。AI还可以列出和取消它们。
- Shell 访问 --可选地允许AI执行主机命令(git、docker、curl等)。由全局切换端点控制。
- 网页用户界面 --React应用程序
frontend/webui/对于提供者、对话和流媒体聊天,具有推理和工具可见性。 - 交互式CLI --基于终端的聊天功能,包括提供商选择、对话管理和shell切换。
先决条件
- Java 25+
- Maven(或使用附带的
mvnw包装)
快速开始
# Clone and build
git clone
cd aidaemon
./mvnw spring-boot:run在Windows PowerShell上:
.\mvnw.cmd spring-boot:run服务器启动于 http://localhost:8080.
1.注册提供商
curl -X POST http://localhost:8080/api/providers \
-H "Content-Type: application/json" \
-d '{"name":"my-gpt","type":"OPENAI","apiKey":"...","model":"gpt-4o"}'支持的类型: OPENAI, ANTHROPIC, GEMINI, OLLAMA
对于Ollama(不需要API密钥):
curl -X POST http://localhost:8080/api/providers \
-H "Content-Type: application/json" \
-d '{"name":"local-llama","type":"OLLAMA","baseUrl":"http://localhost:11434","model":"llama3"}'2.聊天(无状态)
curl -X POST http://localhost:8080/api/chat/{providerId} \
-H "Content-Type: application/json" \
-d '{"messages":[{"role":"user","content":"Hello!"}]}'3.对话(有状态)
对话持续进行 ~/.aidaemon/conversations/。每个都有一个可选名称。根据提示选择提供程序:在创建时设置或通过 PATCH;您发送的下一条消息将使用该提供商。
# Create a conversation
curl -X POST http://localhost:8080/api/conversations \
-H "Content-Type: application/json" \
-d '{"name":"My chat","providerId":""}'
# Send messages (history is maintained server-side)
curl -X POST http://localhost:8080/api/conversations/{id}/messages \
-H "Content-Type: application/json" \
-d '{"message":"What did I just ask you?"}'
# Stream response (SSE: reasoning, answer, tool chunks)
curl -X POST http://localhost:8080/api/conversations/{id}/messages/stream \
-H "Content-Type: application/json" \
-d '{"message":"Explain X"}' \
-N
# Set which provider to use for the next prompt(s)
curl -X PATCH http://localhost:8080/api/conversations/{id} \
-H "Content-Type: application/json" \
-d '{"providerId":"other-provider-id"}'4.交互式CLI
./mvnw spring-boot:run -Dspring-boot.run.profiles=cli在Windows PowerShell上:
.\mvnw.cmd spring-boot:run "-Dspring-boot.run.profiles=cli"CLI中的命令: /quit, /new (新对话), /shell (切换shell访问)。
5.Web用户界面
从项目根目录开始,构建并运行React UI(代理到后端):
cd frontend/webui
npm install
npm run dev连接到显示的URL(例如Vite-dev服务器)。配置提供者和对话,然后聊天;响应流中包含推理和工具调用(如果可用)。
技能
技能是包含以下内容的文件夹 SKILL.md 以及提供AI领域特定知识的可选资源(脚本、参考、资产)。
手动安装: 将技能文件夹放入 ~/.aidaemon/skills/启用Smithery MCP后,要求AI搜索并安装技能(例如“安装Smithery的技能创建者技能”);使用 searchSmitherySkills 和 installSmitherySkill.
管理技能: 让AI列出技能(listSkills),以技能列出或读取文件(listSkillFiles, readSkillFile),或删除技能(removeSkill).
MCP服务器
在中创建JSON配置文件 ~/.aidaemon/mcps/.
远程(流式HTTP):
{
"name": "github",
"type": "REMOTE",
"url": "https://api.githubcopilot.com/mcp/",
"headers": {
"Authorization": "Bearer "
}
}远程(传统SSE):
{
"name": "my-sse-server",
"type": "SSE",
"url": "https://example.com/mcp/sse"
}本地(stdio):
{
"name": "aviation",
"type": "LOCAL",
"command": "npx",
"args": ["-y", "aviationstack-mcp-server"],
"env": {
"AVIATIONSTACK_API_KEY": ""
}
}通过Smithery添加MCP
你可以连接 铁匠铺-托管MCP服务器(如Notion、Google Calendar),无需手动编写配置文件。
- 启用和配置Smithery MCP 在
application.yaml或环境:
aidaemon:
smithery-mcp:
enabled: true
namespace:
api-key: 从获取命名空间和API密钥 Smithery仪表板.
- 查找服务器 上 smithery.ai/servers 并注意它的蛞蝓(例如。
notion,googlecalendar)或完整URL(例如。https://smithery.ai/servers/notion).
- 通过聊天添加MCP: 在任何对话中,让AI通过slug或URL添加服务器,例如:
- “添加Smithery的MCP概念” - “添加Smithery MCP服务器谷歌日历”
AI使用 addSmitheryMcp 工具,将配置写入 ~/.aidaemon/mcps/,并连接服务器。
- OAuth: 如果服务器需要登录,该工具将返回一个授权URL。在浏览器中打开它,完成登录,然后重新加载MCP:
curl -X POST http://localhost:8080/api/mcps/reload# List connected MCPs
curl http://localhost:8080/api/mcps
# Reload after adding/editing config files
curl -X POST http://localhost:8080/api/mcps/reloadShell访问权限
Shell访问权限为 默认情况下禁用。在运行时切换它:
# Enable
curl -X POST http://localhost:8080/api/shell-access/enable
# Disable
curl -X POST http://localhost:8080/api/shell-access/disable
# Check status
curl http://localhost:8080/api/shell-access启用后,AI可以在主机系统上执行任意命令。
计划的作业
人工智能可以通过工具调用创建cron作业。您还可以通过REST管理它们:
# List all jobs
curl http://localhost:8080/api/jobs
# View execution results
curl http://localhost:8080/api/jobs/results
# Cancel a job
curl -X DELETE http://localhost:8080/api/jobs/{id}API 参考
| 方法 | 端点 | 描述 |
|---|---|---|
GET | /api/providers | 列出已注册的提供商 |
POST | /api/providers | 注册新提供商 |
DELETE | /api/providers/{id} | 删除提供者 |
POST | /api/chat/{providerId} | 无状态聊天 |
POST | /api/conversations | 创建对话 |
PATCH | /api/conversations/{id} | 为下一个提示设置提供者(例如providerId) |
POST | /api/conversations/{id}/messages | 发送消息 |
POST | /api/conversations/{id}/messages/stream | 发送消息(SSE流) |
GET | /api/conversations | 列出对话 |
DELETE | /api/conversations/{id} | 删除对话 |
GET | /api/mcps | 列出已连接的MCP服务器 |
POST | /api/mcps/reload | 重新加载MCP配置 |
GET | /api/shell-access | 外壳访问状态 |
POST | /api/shell-access/enable | 启用shell访问 |
POST | /api/shell-access/disable | 禁用shell访问 |
GET | /api/jobs | 列出计划作业 |
GET | /api/jobs/results | 查看作业执行结果 |
DELETE | /api/jobs/{id} | 取消作业 |
数据目录
所有持久数据都存在于 ~/.aidaemon/:
~/.aidaemon/
├── providers.json # Registered LLM providers and API keys
├── memory.json # AI's persistent memory
├── jobs.json # Scheduled job definitions
├── conversations/ # Conversation JSON files (stateful chats)
├── skills/ # Skill folders (SKILL.md + resources)
└── mcps/ # MCP server config JSON files配置
可选的 application.yaml /env属性:
| 属性 | 默认值 | 描述 |
|---|---|---|
aidaemon.config-dir | ~/.aidaemon | 数据目录 |
aidaemon.smithery-mcp.enabled | false | 允许通过聊天从Smithery添加MCP服务器 |
aidaemon.smithery-mcp.namespace | -- | Smithery命名空间(来自仪表板) |
aidaemon.smithery-mcp.api-key | - | Smithery API密钥(来自仪表板) |
aidaemon.shell-access | false | 允许AI shell执行 |
aidaemon.delegation-enabled | false | 启用子代理委派 |
aidaemon.delegation-threshold-seconds | 30 | 模型应委派的估计秒数 |
aidaemon.context-window.chars-limit | 0 | 对话历史记录的最大字符数(以及,对于命名机器人,对话+个人记忆的组合)。与...一起使用 retrieveOlderMessages 用于长时间聊天 |
aidaemon.context-window.personal-memory-ratio | 0 | 仅适用于命名机器人:用于个人内存的字符共享限制(0-1)。剩余部分用于对话历史记录 |
aidaemon.system-instructions | (参见application.yaml) | 模型的系统提示 |
小心
- API密钥以纯文本形式存储 在
~/.aidaemon/providers.json。相应地保护此文件。 - Shell访问权限授予AI完整的命令执行权限 在你的机器上。仅在受信任的环境中启用它,并在不需要时禁用它。
- 计划作业自主运行 使用您配置的提供程序并使用API令牌。监控您的作业并取消不再需要的作业。
- MCP服务器可能会暴露出强大的功能 (文件系统访问、API调用等)。在连接MCP配置之前,请先检查它们。
- 该项目使用Spring AI里程碑版本,这些版本之间可能会有突破性的变化。
贡献
欢迎投稿!无论是bug修复、新的提供商集成、额外的工具还是文档改进,我们都非常感谢所有PR。
如果您对新功能有想法或发现问题,请在提交PR之前打开GitHub问题进行讨论。
