Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 28 additions & 47 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,51 +1,32 @@
# ===== Required =====
LLM_API_KEY=your_api_key_here
LLM_MODEL=deepseek:<model-id>
LLM_API_BASE=https://api.deepseek.com/v1
# Interactive setup: miniagent --connect (optional OS vault: miniagent[credentials]).
# Otherwise select a real model explicitly; a key alone never selects one.
LLM_MODEL=
# LLM_MODEL=provider:model-id
# Set the selected provider's credential, e.g. DEEPSEEK_API_KEY or OPENAI_API_KEY.
# ANTHROPIC_API_KEY, DASHSCOPE_API_KEY, GEMINI_API_KEY / GOOGLE_API_KEY are supported.
# LLM_API_KEY and LLM_API_BASE are explicit OpenAI-compatible gateway overrides.
# LLM_API_KEY=your-provider-key
# LLM_API_BASE=https://your-gateway.example/v1

# ===== Alternative models (uncomment one) =====
# LLM_MODEL=qwen-plus
# LLM_API_BASE=https://dashscope.aliyuncs.com/compatible-mode/v1

# LLM_MODEL=gpt-4o
# LLM_API_BASE=https://api.openai.com/v1

# LLM_MODEL=gemini-2.5-flash
# LLM_API_BASE=https://generativelanguage.googleapis.com/v1beta/openai/
# Optional: set GEMINI_API_KEY instead of LLM_API_KEY

# ===== Optional: Agent behavior =====
# Existing configuration (JSON can override temperature / context_budget).
# LLM_TEMPERATURE=0.7
# LLM_ORGANIZATION= # OpenAI organization ID
# BASH_TIMEOUT=120 # bash tool timeout in seconds
# BASH_MAX_OUTPUT=50000 # max bash output chars
# TOOL_RESULT_LIMIT=16000 # max tool result chars fed to LLM
# MAX_CONTEXT_MESSAGES=20 # auto-compress after this many messages
# MINIAGENT_CONTEXT_BUDGET=32768 # new runtime: conservative budget including tool schemas
# Sensitive files: managed tools hide .env*, .git and private-key files by default.
# Explicit opt-in is --allow-sensitive-files; Shell/MCP remain trusted software.
# CONFIRM_DANGEROUS=true # confirm rm -rf, sudo, etc.
# MINIAGENT_STREAM=1 # 1=streaming on, 0=off
# MINIAGENT_HOME=~/.miniagent # Harness sessions/ and legacy memory storage
# MINIAGENT_HOME also stores connections.json (model IDs/URLs/environment names only).
# Interactive setup: miniagent --connect; OS vault support: pip install 'miniagent[credentials]'.
# Without an OS vault, entered keys stay only in the current process; export provider keys for automation.
# LOG_LEVEL=INFO # logging level (DEBUG/INFO/WARNING/ERROR)

# ===== Optional: Reflection =====
# ENABLE_REFLECTION=true
# REFLECTION_MAX_ITERATIONS=3
# Temperature precedence: --temperature > JSON llm.temperature > environment > 0.7.
# Empty environment is unset; only the effective value is validated. JSON null uses the provider default.
# MINIAGENT_CONTEXT_BUDGET=32768
# MINIAGENT_HOME=~/.miniagent
# MINIAGENT_STREAM=1
# LOG_LEVEL=WARNING

# ===== Optional: Web search =====
# SERPAPI_KEY=your_serpapi_key_here
# Tool execution limits are environment settings, not JSON agent options.
# BASH_TIMEOUT=120
# BASH_MAX_OUTPUT=50000
# TOOL_RESULT_LIMIT=16000
# Managed tools hide .env*, .git and private-key files by default.
# --allow-sensitive-files explicitly opens managed access; Shell/MCP remain trusted.

# ===== Provider isolation =====
# Prefer LLM_MODEL=provider:model-id with that provider's own credential.
# Model selection: CLI --model > JSON llm.model > LLM_MODEL > saved connection default.
# A key or base URL alone never selects a default model. Replace <model-id>.
# OPENAI_API_KEY, DEEPSEEK_API_KEY, ANTHROPIC_API_KEY, DASHSCOPE_API_KEY, etc.
# LLM_API_KEY and LLM_API_BASE are explicit compatibility endpoint overrides.
# Keys from unrelated providers are never searched as a fallback chain.
# MINIAGENT_TEST_MODEL=provider:model-id # opt-in live smoke test only
# Custom endpoints are configured in JSON: providers.<name> with
# type=openai-compatible, base_url, api_key_env; then LLM_MODEL=<name>:<model-id>.
# Retired: MAX_CONTEXT_MESSAGES, CONFIRM_DANGEROUS, ENABLE_REFLECTION,
# REFLECTION_MAX_ITERATIONS, LLM_ORGANIZATION and built-in SERPAPI_KEY search.
# Use --policy readonly|confirm|trusted, context_budget and explicit plugins instead.
# Old teaching APIs are available on codex/legacy-pre-harness; see docs/legacy-migration.md.
# Custom endpoint JSON: providers.<name> {type, base_url, api_key_env}.
# Opt-in live tests: MINIAGENT_TEST_MODEL=provider:model-id.
16 changes: 8 additions & 8 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@ jobs:
with:
python-version: ${{ matrix.python }}
- run: python -m pip install --upgrade pip uv==0.13.0
- run: uv sync --locked --extra mcp --extra legacy --extra credentials --python ${{ matrix.python }}
- run: uv sync --locked --extra mcp --extra credentials --python ${{ matrix.python }}
- name: Project principles and instruction assets
run: python scripts/check_ai_assets.py
- run: uv run --locked --python ${{ matrix.python }} --extra mcp --extra legacy --extra credentials python -m pytest tests -q -m "not live"
- run: uv run --locked --python ${{ matrix.python }} --extra mcp --extra legacy --extra credentials python -m compileall -q miniagent
- run: uv run --locked --python ${{ matrix.python }} --extra mcp --extra credentials python -m pytest tests -q -m "not live"
- run: uv run --locked --python ${{ matrix.python }} --extra mcp --extra credentials python -m compileall -q miniagent
- name: Native runtime static checks
run: uv run --locked --python ${{ matrix.python }} --extra mcp --extra legacy --extra credentials ruff check --select F miniagent/agent.py miniagent/harness.py miniagent/llm.py miniagent/policy.py miniagent/plugins.py miniagent/cli.py miniagent/cli_runtime.py miniagent/config.py miniagent/connections.py miniagent/logger.py miniagent/tools/registry.py miniagent/extensions/mcp_plugin.py tests/test_runtime_recovery.py tests/test_provider_protocols.py tests/test_cli_runtime.py tests/test_model_selection.py tests/test_connections.py tests/conftest.py scripts/source_stats.py scripts/minimal_install_smoke.py
run: uv run --locked --python ${{ matrix.python }} --extra mcp --extra credentials ruff check --select F miniagent tests/test_runtime_recovery.py tests/test_provider_protocols.py tests/test_cli_runtime.py tests/test_model_selection.py tests/test_connections.py tests/conftest.py scripts/source_stats.py scripts/minimal_install_smoke.py
- name: Export locked production dependencies
run: uv export --locked --no-dev --extra mcp --extra legacy --extra credentials --no-emit-project --output-file audit-requirements.txt
run: uv export --locked --no-dev --extra mcp --extra credentials --no-emit-project --output-file audit-requirements.txt
- name: Audit production dependencies
run: uv run --locked --python ${{ matrix.python }} --extra mcp --extra legacy --extra credentials pip-audit --disable-pip --no-deps -r audit-requirements.txt
- run: uv run --locked --python ${{ matrix.python }} --extra mcp --extra legacy --extra credentials python scripts/source_stats.py
run: uv run --locked --python ${{ matrix.python }} --extra mcp --extra credentials pip-audit --disable-pip --no-deps -r audit-requirements.txt
- run: uv run --locked --python ${{ matrix.python }} --extra mcp --extra credentials python scripts/source_stats.py
- run: uv build
- name: Minimal installed wheel without optional extras
run: uv run --locked --python ${{ matrix.python }} --extra mcp --extra legacy --extra credentials python scripts/minimal_install_smoke.py
run: uv run --locked --python ${{ matrix.python }} --extra mcp --extra credentials python scripts/minimal_install_smoke.py
2 changes: 1 addition & 1 deletion .github/workflows/regression.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
with:
python-version: ${{ matrix.python }}
- name: Install this stage and available extras
run: python -m pip install -e ".[mcp,legacy]" "pytest>=9.0.3,<10"
run: python -m pip install -e ".[mcp,credentials,dev]" "pytest>=9.0.3,<10"
- run: python -m pytest tests -q -m "not live"
- run: python -m compileall -q miniagent
- run: python scripts/source_stats.py
4 changes: 2 additions & 2 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ MiniAgent 是以插件为核心的轻量 Python Agent Harness。目标是用容

### DSH 常用能力

- 用 Context/Service、依赖声明、插件清理、可替换 Loop 等解决实际 Agent 任务;新增生命周期行为必须说明等待、激活、失活、恢复和异常回滚。
- 用 Context/Service、依赖声明和插件清理解决实际 Agent 任务;响应式依赖与可替换 Loop 按独立需求评估,不作为原生 API 精简的前置条件。新增生命周期行为必须说明等待、激活、失活、恢复和异常回滚。
- 默认优先稳定和显式语义;兼容性变化要说明迁移路径。运行中的任务禁止生命周期变更。
- 工具仍经 Schema、Policy 和 Skill 检查;会话保留原记录,不重放未知副作用。新能力不得破坏这些守卫。
- 自定义插件/Loop 的责任和可信边界必须写清楚,不把 Mock 或菜单选项当作真实远端兼容验收。
Expand All @@ -48,7 +48,7 @@ MiniAgent 是以插件为核心的轻量 Python Agent Harness。目标是用容

- miniagent/agent.py、harness.py、llm.py、tools/registry.py:四文件核心;以统计脚本清单为准。
- policy.py、plugins.py、session.py:外围运行机制;连接配置在 connections.py,CLI 在 cli.py / cli_runtime.py。
- extensions/:可选集成;legacy.py / legacy_cli.py 及旧工具是兼容路径,删除需独立迁移评审。
- extensions/:可选集成;旧文本 API、系统工具与编排器保存在 codex/legacy-pre-harness 历史分支,原生版不重新引入,迁移见 docs/legacy-migration.md。
- tests/:确定性回归与显式 opt-in live 测试;scripts/:验证与构建;docs/:专题说明;.claude/reviews/:本地审查产物。
- 以可执行代码、脚本和工作流为准,发现相关文档漂移要顺手修正。AGENTS.md 不复制完整架构或过期实现。

Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

<p align="center"><a href="README_EN.md">English</a> · <a href="#核心特性">核心特性</a> · <a href="#快速开始">快速开始</a> · <a href="#作为-python-调用">Python API</a> · <a href="#演示">演示</a> · <a href="#项目结构">项目结构</a></p>

MiniAgent 是一个**超轻量、常用功能齐备的 Python Agent / Harness**,核心仅 **531 行代码**。支持工具调用、会话记忆、上下文管理与插件扩展等主流 Agent 常用能力,**可以直接使用,也适合快速入门学习、定制修改和二次开发。**
MiniAgent 是一个**超轻量、常用功能齐备的 Python Agent / Harness**,核心仅 **524 行代码**。支持工具调用、会话记忆、上下文管理与插件扩展等主流 Agent 常用能力,**可以直接使用,也适合快速入门学习、定制修改和二次开发。**

## 核心特性

- 🧠 **功能齐备**:原生工具调用、流式输出、会话记忆、上下文压缩、Skills、MCP、插件管理与权限控制,组成可运行的 Agent / Harness。
- 🚀 **直接使用**:连接模型后即可通过 CLI 执行编程与自动化任务,也能通过 Python API 嵌入现有项目。
- 📖 **快速入门**:核心仅 **531 行、4 个文件**,从模型调用、工具执行到插件管理,适合通过阅读和运行源码理解 Agent / Harness 的工作原理。
- 📖 **快速入门**:核心仅 **524 行、4 个文件**,从模型调用、工具执行到插件管理,适合通过阅读和运行源码理解 Agent / Harness 的工作原理。
- 🧩 **定制开发**:修改提示词与 Skills,通过 Plugin 接入自己的工具和服务;复用已有的会话与权限机制,开发自己的 Agent。

## 快速开始
Expand Down Expand Up @@ -88,7 +88,7 @@ Harness 负责模型与工具之间的循环、插件启动和清理,以及会

```text
miniagent/
├── agent.py # Agent 循环 · 72 行
├── agent.py # Agent 循环 · 65 行
├── harness.py # 插件、服务与生命周期 · 256 行
├── llm.py # 模型调用与流式输出 · 149 行
├── tools/
Expand All @@ -102,7 +102,7 @@ miniagent/
└── cli.py # 命令行入口
```

四文件核心 **531 行**;全部官方包 Python **5,079 行**(含旧版兼容代码)。行数包含注释和空行,不含第三方依赖。运行 `python scripts/source_stats.py` 可复核。[统计脚本](scripts/source_stats.py)
四文件核心 **524 行**;全部官方包 Python **2,067 行**。行数包含注释和空行,不含第三方依赖。运行 `python scripts/source_stats.py` 可复核。[统计脚本](scripts/source_stats.py)

## 文档与贡献

Expand Down
8 changes: 4 additions & 4 deletions README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@

<p align="center"><a href="README.md">中文</a> · <a href="#key-features">Key features</a> · <a href="#quick-start">Quick start</a> · <a href="#use-from-python">Python API</a> · <a href="#demos">Demos</a> · <a href="#project-structure">Project structure</a></p>

MiniAgent is an **ultra-lightweight Python Agent / Harness with the essentials built in**, centered on just **531 lines of core code**. It supports common agent capabilities such as tool calling, session memory, context management and plugin extensions. **Use it directly, learn how agents work, or customize it to build your own.**
MiniAgent is an **ultra-lightweight Python Agent / Harness with the essentials built in**, centered on just **524 lines of core code**. It supports common agent capabilities such as tool calling, session memory, context management and plugin extensions. **Use it directly, learn how agents work, or customize it to build your own.**

## Key features

- 🧠 **Essential capabilities**: native tool calling, streaming, session memory, context compaction, Skills, MCP, plugin management and permission controls form a working Agent / Harness.
- 🚀 **Ready to use**: connect a model and run coding and automation tasks through the CLI, or embed the runtime in an existing project through the Python API.
- 📖 **Learn by exploring**: the core is just **531 lines across 4 files**, covering model calls, tool execution and plugin management. Read and run the code to understand how an Agent / Harness works.
- 📖 **Learn by exploring**: the core is just **524 lines across 4 files**, covering model calls, tool execution and plugin management. Read and run the code to understand how an Agent / Harness works.
- 🧩 **Build your own**: customize prompts and Skills, add tools and services through Plugin. Reuse the existing session and permission mechanisms as you develop your own agent.

## Quick start
Expand Down Expand Up @@ -88,7 +88,7 @@ The core lives in [agent.py](miniagent/agent.py), [harness.py](miniagent/harness

```text
miniagent/
├── agent.py # Agent loop · 72 lines
├── agent.py # Agent loop · 65 lines
├── harness.py # Plugins, services and lifecycle · 256 lines
├── llm.py # Model calls and streaming · 149 lines
├── tools/
Expand All @@ -102,7 +102,7 @@ miniagent/
└── cli.py # CLI entry point
```

The core totals **531 lines**; all first-party package Python totals **5,079 lines**, including legacy compatibility code. Counts include comments and blank lines and exclude third-party dependencies. Run `python scripts/source_stats.py` to verify. [Counting script](scripts/source_stats.py)
The core totals **524 lines**; all first-party package Python totals **2,067 lines**. Counts include comments and blank lines and exclude third-party dependencies. Run `python scripts/source_stats.py` to verify. [Counting script](scripts/source_stats.py)

## Docs and contributing

Expand Down
5 changes: 5 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

## [Unreleased]

- [修复] 自定义算术工具及指南示例接收 Policy 注入的 path,补充实际 Registry 执行与清理检查;温度按 CLI、JSON、环境的最终生效值校验,空环境回退默认值,不再阻止高优先级配置覆盖。
- [改进] 0.3.0a1 候选集中原生 Harness / Session / Plugin / MCP,退役旧文本 Agent、系统工具、Memory 和 Orchestrator;旧实现保留在 codex/legacy-pre-harness,迁移说明列出不兼容入口。
- [改进] 文件工具元数据不再注册到全局目录,Shell 复用单一异步实现;移除旧版运行依赖和无效配置字段,未知 JSON 设置明确报错。
- [文档] 原生精简直接基于 main,保留静态 Harness,不依赖响应式插件或可替换 Loop;同步双语源码统计、原生示例和迁移指南。
- [测试] 保留主线原生协议、权限、会话与 MCP 回归,补充退役入口、工具隔离、配置和示例检查;构建与独立安装验证原生包不再包含旧实现。
- [改进] CLI 终端欢迎界面显示模型、权限和会话摘要,帮助列出命令用途,单次任务与工具执行结果更易辨认;复用 Rich,不改变模型、工具、权限和会话语义。
- [文档] 重写中英文 README,突出小核心、常用能力及使用/学习/定制三种用途;恢复 Windows 案例,加入已有终端回放与来源说明,按主线校正源码行数和公开能力,不改变运行时。

Expand Down
4 changes: 2 additions & 2 deletions docs/demo.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## 终端任务回放

首页动图来自 2026-10-17 的真实 CLI 任务记录:Windows、Python 3.12、MiniAgent 0.2.0a1。运行基于 main `64c1fcb`,加入展示分支的终端样式;该样式尚未进入主线。记录与素材保留于[原提交](https://github.com/ZhuLinsen/MiniAgent/tree/634b94ec8d9c55b8270807e8387f74ec3beb4de4)。
首页动图来自 2026-10-17 的真实 CLI 任务记录:Windows、Python 3.12、MiniAgent 0.2.0a1。运行基于 main `64c1fcb`,加入展示分支的终端样式;该样式现已通过 #15 合入主线。记录与素材保留于[原提交](https://github.com/ZhuLinsen/MiniAgent/tree/634b94ec8d9c55b8270807e8387f74ec3beb4de4)。

Agent 读取有错误的 `calculator.py`,将加法函数中的减法修正,再执行原有单元测试。模型之外另跑一次测试确认通过,测试文件 SHA-256 保持不变。此次运行调用真实模型和工具,使用 Anspire 网关的 `qwen3.5-flash`,共 4 次请求、5,068 tokens。

Expand All @@ -12,7 +12,7 @@ Agent 读取有错误的 `calculator.py`,将加法函数中的减法修正,

GIF 根据原始文本逐段绘制,保留提示、工具顺序和回答,压缩了播放间隔。这是一项小型函数修复演示,不是响应速度或复杂仓库任务的基准测试。

The GIF replays a real CLI task recorded on the presentation branch, based on main `64c1fcb`. Its terminal styling is not yet part of main. Playback timing is condensed; the transcript, tool results and model answer are preserved. This is a small repair example, not a latency or coding benchmark.
The GIF replays a real CLI task recorded on the presentation branch, based on main `64c1fcb`. Its terminal styling has since been merged into main through #15. Playback timing is condensed; the transcript, tool results and model answer are preserved. This is a small repair example, not a latency or coding benchmark.

## 复现任务

Expand Down
Loading
Loading