Skip to main content

Python SDK for mink — sandboxed AI coding agent

Project description

Mink

Crates.io MIT licensed Rust 1.94+ Python SDK

Rust 原生 · 终端优先 · 可嵌入

Mink 是一个 Rust 实现的 AI agent runtime:面向终端,也面向系统。既适合在终端中直接 工作(REPL / Full TUI / Inline TUI),也适合嵌入到服务端、桌面端或内部工具中 —— CLI、 Python SDK 和 Rust 嵌入共享同一个运行时内核,不依赖子进程,语义完全一致。


[TOC]


快速开始

终端使用

# 前置:Rust 1.94+,设置 DEEPSEEK_API_KEY 或通过配置指定 OpenAI-compatible 端点

# 编译
cargo build --release        # 或 make build

# REPL 交互模式
./target/release/mink -m flash -i

# Full TUI 全屏模式
./target/release/mink -m flash --tui

# Inline TUI 原生 scrollback 模式
./target/release/mink -m flash --tui=inline

# 单次查询 / 恢复最近会话
./target/release/mink -m flash "explain this project"
./target/release/mink -m flash --continue -i

# 使用自定义系统提示词
./target/release/mink --mission ./my-task.mission.md -i

Python SDK

pip install mink-agent
from mink_agent import AgentSession, SandboxConfig

session = AgentSession(SandboxConfig(
    api_key="sk-...",               # 或设置 DEEPSEEK_API_KEY 环境变量
    read_dirs=["src"],
    signal_mode="full",             # "full" 启用信号系统,"off" 关闭
))
result = session.run("scan this repo and summarize")
print(result["text"])
session.close()

Rust 嵌入

[dependencies]
mink = { package = "mink-core", version = "0.3.0", default-features = false, features = ["runtime"] }
use mink::prelude::{AgentOptions, AgentRuntime};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let rt = AgentRuntime::start_with_options(
        AgentOptions::new("/tmp/mink-home", ".")
            .with_api_key(std::env::var("DEEPSEEK_API_KEY")?)
            .with_model("flash"),
    ).await?;

    let outcome = rt.run_turn("hello").await?;
    println!("{}", outcome.text);

    rt.shutdown().await?;
    Ok(())
}

核心特点

  • 可嵌入的运行时内核AgentRuntime::start() → run_turn() / stream_turn() → shutdown() 完整生命周期。CLI、REPL、TUI、Python SDK 和 Rust 嵌入共享同一套运行时语义,不需要维护多套 agent 内核。
  • 长上下文与长任务可控 — 显式压缩参数 + LLM 摘要非破坏式投影 + 持久化 session 共同工作,上下文不无限膨胀,长任务可持续推进;enabled_tools 统一工具边界。
  • 编辑与状态管理更可靠 — Anchored Edit(Read snapshot + Edit.patch 行锚定)、artifact 超长输出回读、Plan/Todo revision 原子提交和 session 恢复机制,不把正确性交给运气。

特性

⚙️ 核心引擎

  • OpenAI-compatible 默认后端 — 内置 DeepSeek / OpenAI 流式客户端,支持 reasoning、usage、工具调用和扩展参数(openai_tool_choiceopenai_extra_body
  • 可注入 LLM backend — 实现 mink::runtime::LlmBackend trait,接入私有模型、内网网关、厂商 SDK 或非 HTTP transport
  • 信号驱动的信念系统 — 自动检测工具执行错误,低信念时注入修正提示并约束恢复首步;MINK_SIGNAL_MODE=off 可完全关闭
  • 显式上下文压缩 — 百分比阈值、响应预留、热尾部和摘要输出预算全参数化;可选摘要输入降噪(过滤 thinking、压缩工具结果)
  • 三段维修流水线 — Scavenge(回收遗漏调用)→ Truncation(修复残缺消息)→ StormBreaker(抑制重复调用),自动闭环修复

🖥️ 终端与界面

  • 三种交互 surface — REPL 行模式(-i)、Full TUI 全屏模式(--tui)、Inline TUI 原生 scrollback 模式(--tui=inline
  • Anchored Edit 协议Read 生成带行 hash 的 snapshot header,Edit.patch 按行锚定修改,stale snapshot fail closed,防止并发漂移
  • 结构化 transcript — 统一的工具卡片渲染、Markdown 子集、自动折叠、实时信念 / token / 费用状态栏
  • 机器协议--print 输出 ndjson 事件流;--agent-jsonl 提供 single-shot Agent JSONL 协议

🛠️ 工具系统

  • 内置工具 — Read / Write / Edit / Bash / Python / Glob / Grep / PlanDraft / PlanConfirm / PlanClear / TodoRead / TodoWrite / TodoAdvance / SubAgent
  • 统一工具选择enabled_tools 是唯一启用入口,同时决定模型可见 schema、能力工作流和真实执行边界;PythonSandbox 仅在显式列出时启用
  • 语义能力模型 — 工具按语义能力分类,自动组合工作流提示;不可用工具不会出现在 schema、提示词或组合链路中
  • 注册式轻量资源Read 通过 ResourceRouter 统一分发 artifact://skill://rule://session:// 等 scheme
  • 技能系统 — 按需加载 skill 文件,不污染后续 prompt;skill_discovery_policy 控制发现策略

🔒 沙箱与安全

  • 进程级沙箱 — Linux nsjail / bubblewrap(完整文件系统隔离)、macOS sandbox-exec(写入隔离)
  • CPython WASI 沙箱PythonSandbox 工具在 wasmtime + CPython WASI 中执行,WASI 级进程隔离,无网络、无 C 扩展
  • 危险命令过滤 — Bash 误用拦截与安全约束,可选审批策略

🗃️ 持久化与状态

  • Session 持久化 — Append-only JSONL 完整历史,活跃后缀内存缓存,--continue 无缝恢复
  • 非破坏式压缩 — 只更新 context-state.json 投影边界,不重写 conversation.jsonl;压缩统一使用 LLM 摘要
  • Plan & Todo 状态 — 确认计划按请求动态投影为 <current-plan>;Todo 使用稳定 ID、revision 和原子批量提交
  • Artifact 超长输出 — 工具结果超限自动落盘至 artifacts/,序号可恢复且禁止覆盖;Read artifact://<id> 读取
  • Token 用量与费用 — LLM 请求级 usage.jsonl journal,纳元级定价,覆盖主 Agent、自动压缩和子代理

🔌 集成与扩展

  • Rust 库 APImink::runtime::{AgentRuntime, AgentOptions, LlmBackend, ReadOnlyFileSystem},完整同步/流式 turn 生命周期
  • Python SDKpip install mink-agent,内置无 TUI 的 mink-core 二进制,支持全参数配置
  • 嵌入式只读 VFS — 为 Read/Glob/Grep 注入数据库后端,按 resource_session_id 隔离多租户知识库
  • 子代理(SubAgent) — 隔离或目录级 fork 完整 session 状态,复用父 runtime 的 LLM backend,支持并发执行
  • 自定义提示词--mission 加载 MISSION.md,允许覆盖白名单 core section,runtime 保留 section fail closed
  • 模型别名系统flash / pro 内置 DeepSeek 别名,model_aliases 可覆盖;任意模型名未命中时原样传递
  • Server 与 Webmink-server 单二进制 Web 工作区服务器:REST + SSE 实时流,前端构建产物嵌入二进制,与 TUI 共享会话,浏览器里继续终端里的工作

Workspace Packages

路径 职责
crates/mink-core Rust 发布包 mink-core,库 crate 名 mink,包含可嵌入 runtime、工具核心、session、sandbox 和 SDK 协议
crates/mink-cli workspace 内部二进制包,生成 mink 终端二进制和 mink-core SDK 精简二进制,持有 REPL/TUI 实现
mink_agent Python SDK,wheel 内置无 TUI 的 mink-core 二进制
crates/mink-server Web 工作区服务器:REST + SSE + 嵌入前端,build.rs 自动构建并嵌入 web 产物

参考项目

项目 说明
oh-my-pi 开源 CLI agent(Bun/TypeScript),Edit 工具的行号锚定与快照协议参考实现
bash-agent 终端 Agent(Bash 优先),交互与工具执行参考

文档索引

文档 说明
使用手册 面向终端用户:CLI 交互、配置、沙箱、session、工具和常见工作流
嵌入与 SDK Rust 库 / Python SDK 嵌入、Token 用量与费用
机器协议 --print stream-json 与 --agent-jsonl 协议
工具参考 面向工具协议:内置工具参数、结果通道、资源 URL、审批和构建裁剪
架构说明 运行时分层、模块职责、资源/能力系统、核心数据流
设计文档 设计总纲与关键不变式;信号与工具能力细节见对应设计哲学文档
变更日志 版本变更记录
Server 与 Web mink-server:REST/SSE API、嵌入构建、配置与部署
工具能力与提示词解耦 工具 surface、语义能力、自由组合和前向求值算法
信号系统设计 控制论 + 贝叶斯、冷却机制、信念度展示
Agent 开发指南 面向 AI agent:项目结构、模块索引、开发惯例

许可

MIT License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mink_agent-0.3.0-py3-none-musllinux_1_2_x86_64.whl (3.4 MB view details)

Uploaded Python 3musllinux: musl 1.2+ x86-64

mink_agent-0.3.0-py3-none-manylinux_2_35_x86_64.whl (3.4 MB view details)

Uploaded Python 3manylinux: glibc 2.35+ x86-64

mink_agent-0.3.0-py3-none-macosx_26_0_arm64.whl (3.0 MB view details)

Uploaded Python 3macOS 26.0+ ARM64

File details

Details for the file mink_agent-0.3.0-py3-none-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for mink_agent-0.3.0-py3-none-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 ff79ac703d11f0484ea3ba66b93239cffd7abb99611303ced8333fd217de4b9b
MD5 1f2be8cdad66df57095abc2f36a2170f
BLAKE2b-256 44b526165245614570a753a7fad66773c52b63450274cf912ecc90f387c1c2de

See more details on using hashes here.

Provenance

The following attestation bundles were made for mink_agent-0.3.0-py3-none-musllinux_1_2_x86_64.whl:

Publisher: ci.yml on fierceX/mink

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mink_agent-0.3.0-py3-none-manylinux_2_35_x86_64.whl.

File metadata

File hashes

Hashes for mink_agent-0.3.0-py3-none-manylinux_2_35_x86_64.whl
Algorithm Hash digest
SHA256 e85c7f0b401fd9f3a08dae4249591e778e808b450907c6370b462e7a9403f4f9
MD5 3f290f43132fc9ed89bfca88bb36477f
BLAKE2b-256 5266c64e7a74953d7d297b7fff4c889edb210ffae53fc488709e5d9b1ef0408b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mink_agent-0.3.0-py3-none-manylinux_2_35_x86_64.whl:

Publisher: ci.yml on fierceX/mink

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mink_agent-0.3.0-py3-none-macosx_26_0_arm64.whl.

File metadata

File hashes

Hashes for mink_agent-0.3.0-py3-none-macosx_26_0_arm64.whl
Algorithm Hash digest
SHA256 7a687b068d7ec11b852ec277047893709c3554a586a654abb9aca28ae489051a
MD5 c6fd1c6ee031bedb844ca7bdbfaff501
BLAKE2b-256 035670e6d77e0f6b8ed5ff36299e31ca8c96b1abf3580a0e0a7a0aa677fddd2b

See more details on using hashes here.

Provenance

The following attestation bundles were made for mink_agent-0.3.0-py3-none-macosx_26_0_arm64.whl:

Publisher: ci.yml on fierceX/mink

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page