by TheSyart
Local Emperor-style AI agent with Vue WebUI, multi-provider LLMs, streaming chat, tools, skills, memory, and token telemetry.
# Add to your Claude Code skills
git clone https://github.com/TheSyart/emperor-agentGuides for using ai agents skills like emperor-agent.
Last scanned: 6/18/2026
{
"issues": [],
"status": "PASSED",
"scannedAt": "2026-06-18T08:49:11.373Z",
"npmAuditRan": true,
"pipAuditRan": false,
"promptInjectionRan": true
}emperor-agent is an open-source ai agents skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by TheSyart. Local Emperor-style AI agent with Vue WebUI, multi-provider LLMs, streaming chat, tools, skills, memory, and token telemetry. It has 104 GitHub stars.
Yes. emperor-agent passed SkillsLLM's automated security scan — a dependency vulnerability audit plus prompt-injection heuristics — with no high-severity issues. You can read the full report in the Security Report section on this page.
Clone the repository with "git clone https://github.com/TheSyart/emperor-agent" and add it to your Claude Code skills directory (see the Installation section above).
emperor-agent is primarily written in Python. It is open-source under TheSyart on GitHub, so you can review or fork the full source.
Yes. SkillsLLM lists many other AI Agents skills you can browse and compare side by side. Open the AI Agents category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh emperor-agent against similar tools.
No comments yet. Be the first to share your thoughts!
用户下旨,主智能体("大内总管")统筹上下文、工具、记忆与子代理;把任务拆解、执行、校验后回禀。 项目重点不是教学材料,而是一个可持续演进的个人 Agent 工程。
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txt
pip install -e . # 提供 emperor-agent 命令
emperor-agent init # 终端向导配置 provider / model / WebUI 参数
# 也可以使用:python agent.py init
emperor-agent chat
# 兼容入口:python agent.py
常用命令:
emperor-agent status
emperor-agent doctor
emperor-agent web --host 127.0.0.1 --port 8765 --open
启动时若发现热 memory/history.jsonl 中有活跃对话,会先调用模型做一次启动压缩。
WebUI 用 Vue 3 + Vite + Tailwind + vue-router 构建,首次使用前必须先打包前端产物:
cd webui
npm install
npm run build # 产出 webui/dist/
cd ..
emperor-agent web --open
# 兼容入口:python webui.py
# 浏览器打开 http://127.0.0.1:8765
后端 aiohttp 服务器把 webui/dist/ 作为 SPA 静态资源托管,并代理 /api/* 与 /ws。前端开发模式可以另起 cd webui && npm run dev(Vite 5173),并配 proxy 指到 8765。
桌宠 companion 默认关闭。首次使用需单独安装 Electron 依赖,然后在 WebUI「配置文件」页开启,或用 CLI 管理:
cd desktop-pet
npm install
cd ..
emperor-agent pet status
emperor-agent pet start
emperor-agent pet stop
emperor-agent pet restart
桌宠窗口位置写入 memory/desktop_pet/window.json;运行时会用顶部气泡展示简短动作摘要,不显示用户原文或工具参数。若 Electron 依赖缺失,WebUI 只显示安装命令,不会影响主服务启动。
开发环境建议安装 dev 依赖:
.venv/bin/python -m pip install -r requirements-dev.txt
make check
make check 会调用 scripts/check.sh,固定执行 git diff --check、Python 编译、ruff、pytest 和 WebUI build。需要同时查看本地配置、依赖、持久化状态时可运行:
emperor-agent doctor --dev
memory/、templates/USER.local.md、model_config.json、emperor.local.json、webui/dist/、webui/node_modules/、desktop-pet/node_modules/ 都被 .gitignore 排除,所以新克隆的仓库是干净的。首次启动会自动从仓库内的初始化模板生成本地副本:
| 私密文件 | 由谁生成 | 来源 |
|---|---|---|
memory/(整个目录) |
MemoryStore._ensure() |
mkdir |
memory/MEMORY.local.md |
MemoryStore._ensure() |
复制 templates/init/MEMORY.md |
memory/history.jsonl |
HistoryLog 首次启动 |
热对话日志,只保留活跃上下文 |
memory/history_index.json |
HistoryLog 首次启动 |
热/冷历史统计索引 |
memory/history_archive/*.jsonl.gz |
压缩后自动生成 | 已压缩原始对话冷归档 |
memory/versions/ |
记忆写入或恢复时生成 | MEMORY.local.md、USER.local.md 与情景记忆的本地快照 |
memory/tokens.jsonl |
TokenTracker 首次写入 |
append |
memory/control/state.json |
ControlStore 首次启动 |
当前 ask / plan 等待状态 |
memory/runtime/events.jsonl |
RuntimeEventStore 首次启动 |
Chat 行为事件热日志,只保留活跃 turn |
memory/runtime/index.json |
RuntimeEventStore 首次启动 |
Runtime 热/冷统计索引 |
memory/runtime/archive/*.jsonl.gz |
Runtime 维护/压缩后生成 | 已归档的旧行为事件 |
memory/external/state.json |
ExternalBridgeStore 首次写入 |
外部平台基础层的 seen / pending / outbox durable 状态 |
memory/desktop_pet/ |
桌宠启动后生成 | 悬浮窗位置、pid 与最近错误 |
memory/scheduler/jobs.json |
SchedulerStore 首次启动 |
本地持久定时任务热配置 |
memory/scheduler/action.jsonl |
SchedulerStore 写操作 |
跨入口 action log,用于合并任务变更 |
memory/scheduler/action.corrupt-*.jsonl |
SchedulerStore 发现坏 action 时生成 |
无法解析或未知 action 的隔离备份,diagnostics 可见 |
memory/watchlist.md |
WatchlistStore 首次启动 |
主动检查清单,供 Scheduler heartbeat 周期判断 |
memory/watchlist_state.json |
Watchlist 检查后写入 | 最近一次 skip/run 决策与模型信息 |
templates/USER.local.md |
AgentLoop._ensure_local_user_file() |
复制 templates/init/USER.md |
model_config.json |
emperor-agent init 或 WebUI /model 保存 |
本地私密模型配置 |
emperor.local.json |
emperor-agent init 或桌宠开关 |
本地 CLI/WebUI 偏好:host、port、openBrowser、desktopPet |
webui/dist/ |
需要手动 cd webui && npm install && npm run build |
Vite 构建 |
只要按"快速开始"两步走,引导链路就完整了,无需再手动建任何目录。
history)、情景记忆(memory/YYYY-MM-DD.md)、长期记忆(memory/MEMORY.local.md)协同运转。/memory-log / /memory-restore 可查看 diff 并恢复。mcp_{server}_{tool},与内置工具统一调度。message_delta、tool_call、tool_result、subagent_* 等事件;活跃行为事件持久化到 memory/runtime/events.jsonl,旧事件进入 memory/runtime/archive/*.jsonl.gz,刷新或后端重启后按 seq 回放未压缩会话细节;Scheduler 主动 turn 会显示为中性的“定时任务触发”卡片,不伪装成用户消息;Chat 停止按钮与 /stop 会通过统一 active task registry 取消当前 turn / Scheduler run / Watchlist check。ask_before_edit 会在危险或不确定动作前审批;auto 走最高自动权限;plan 只允许只读探索、提问和提交 PlanCard,批准或取消后恢复进入 Plan 前的模式。at / every / cron 任务,启动 WebUI 后后台 timer 自动恢复;支持触发本地主动 Agent turn、Team wake 与系统维护 heartbeat;Agent 可通过 scheduler 工具查看任务,创建/修改/删除/手动运行长期任务会走权限审批。memory/watchlist.md 记录希望系统主动留意的事项;受保护的 watchlist-check 定期用次模型判断 skip/run,只有必要时才投递完整主动 turn。agent/external/ 提供通用外部平台适配骨架、入站去重、inbox/outbox 状态和 runtime 事件;当前不内置任何具体平台实现。外部消息只会汇入唯一主线,不创建多会话、不暴露 session_id。.team/ 下独立 inbox、thread、状态和 WebUI 工作台;v1 采用“按消息唤醒”,不启动后台常驻轮询。skills/ 下的能力包,避免一开始塞满 system prompt。runner._pair_tool_calls 保证 OpenAI 格式 history 中 assistant tool_calls 与 tool 消息严格配对,运行时异常或压缩切边都不会污染下一次请求。_cap_tool_result,留头尾,默认 8KB 上限)+ 旧大体积工具消息摘要化(_shrink_old_tool_results,最近 10 条保留原文,更早的替换为 [shrunk] name → N chars omitted)。让长对话从 8-10 轮稳定到 30+ 轮不撞 token 上限。step_async 内置两个状态机:模型偶发空响应时自动注入 nudge 重试(≤2 次);finish_reason="length" / "max_tokens" 时自动续写并拼接(≤3 次)。前端通过既有 tool_error 事件可见 _empty_response / _length_truncation 提示。MemoryStore.write_checkpoint 在每次工具批次完成后把 history 原子写到 memory/_checkpoint.json(gitignore),关 tab / Ctrl-C / 模型超时都不丢。AgentLoop 启动时 read_checkpoint 优先于 history.jsonl 未归档段恢复 in-memory history,再 clear_checkpoint;_pair_tool_calls 兜底处理任何 orphan tool_call。turn 正常落地时自动清理。memory/attachments/YYYY-MM/{hash8}-{name}.{ext},PDF 与文本文档同步抽取 sidecar 文本(pypdf),发消息时按 OpenAI 多模态格式装配 user content:vision-capable entry 走 image_url block,否则替换为占位提示;文档总把抽出的文本内联进 prompt,并在末尾附落盘路径供 read_file 兜底读取。User 多模态消息在 cap/shrink 链上原样保留,不会被截断;WebUI 刷新恢复时只显示用户原话与附件卡片,不把模型侧提取文本 / 落盘说明塞回气泡。/model 编辑器内置「测试文本」「测试视觉」两个按钮:发一次最小 ping 或一张内置 2×2 红色 PNG 探测图,返回延迟、模型名、响应 sample。视觉测试通过会自动把 entry.supports_vision = true 持久化到 model_config.json,entry 列表立刻在该条目右侧显示视觉能力像素徽章;Composer 的附件按钮 tooltip 与图片上传路径都依据该徽章决定走视觉链还是占位文字。agent.py CLI 兼容入口(转发到 agent.cli)
webui.py WebUI 启动入口
agent/
├── loop.py 主循环、组件装配、CLI 命令处理
├── cli.py Python CLI 命令入口:init / chat / web / status / doctor / pet
├── onboarding.py Rich + Questionary 初始化向导、doctor 检查、配置构造
├── local_config.py emperor.local.json 本地偏好读写
├── model_router.py 主/次模型路由:main_agent、memory、subagent、team 的模型选择与 fallback
├── runner.py 单轮执行编排、tool_use 循环、并发安全工具组合、tool_call 配对保护、上下文治理(cap/shrink)、空响应+截断重试
├── runner_factory.py 子代理 / Team runner 构造入口,集中套用模型路由快照与 fallback
├── runner_model.py ModelCaller:模型调用、流式 delta、次模型失败后升主模型一次
├── memory.py 三层记忆存储、未归档历史载入、中断恢复 checkpoint
├── memory_versions.py 记忆快照、diff 与 restore,本地存储在 memory/versions/
├── attachments.py 附件落盘 + mime 校验 + PDF/文本抽取 + 引用反查(LRU)
├── compactor.py 历史压缩与长期记忆 / 用户档案更新
├── model_config.py 多 provider 模型配置读写
├── context.py system prompt 组装(SOUL.md / TOOL.md / USER.md / MEMORY / Skills)
├── control/ Ask / Plan 会话控制:pending interaction、暂停/恢复、Ask Guard
├── permissions/ Claude Code 风格三模式权限策略:ask_before_edit / auto / plan
├── runtime/ WebUI 行为事件冷记录、event payload、seq replay
├── scheduler/ 本地长期自动运行中枢:job store / timer service / scheduler tool
├── desktop_pet/ 可选 Electron 桌宠进程管理、pid