AI 驱动的命令行微 Agent 框架,通过 TOML 配置将 Shell 命令包装为 LLM 可调用函数,支持多 LLM 后端和 MCP 协议,实现安全可控的自然语言到系统操作转换。
项目简介#
ESA 是一个用 Go (71.3%) 编写的 AI 驱动命令行工具,由 meain 开发并维护(222 commits)。核心概念是"个性化微 Agent"——通过限制 LLM 只能访问高度特定、经过审计的小型工具集,实现更安全、精准、高效的系统自动化。
核心特性#
多 LLM 提供商支持#
- OpenAI (
OPENAI_API_KEY) - Groq (
GROQ_API_KEY) - OpenRouter (
OPENROUTER_API_KEY) - GitHub Models (
GITHUB_MODELS_API_KEY) - Ollama 本地部署 (
OLLAMA_API_KEY) - 自定义 OpenAI-compatible APIs
Agent 系统#
通过 TOML 配置文件定义专用 Agent,每个 Agent 包含:
system_prompt: 定义 Agent 角色和行为functions: 可调用的命令定义(含参数验证、类型检查、格式化)
内置 Agent:+default(基本系统操作)、+new(创建新 Agent)、+auto(自动选择合适 Agent)
Function-Based 架构#
- 将 Shell 脚本/CLI 命令包装为 LLM 可调用的函数
- 支持
{{$command}}动态执行 Shell 命令并插入输出 - 参数验证:type、required、format
MCP Server 集成#
支持 Model Context Protocol (MCP) 服务器,可连接外部数据源和工具(文件系统、数据库、Web 服务等),支持函数级别安全控制(safe_functions、allowed_functions)。
交互模式#
- CLI 单次执行:
esa "your query" - REPL 模式:
esa --repl - Web 界面:
esa --serve(WebSocket 流式响应,默认端口 8080)
安全控制#
- 三级确认模式:
none(默认)、unsafe(危险命令确认)、all(全部确认) - 函数安全标记:
safe = true/false
对话管理#
会话历史保存与恢复(--continue、--conversation <id>),历史查看(--list-history、--show-history <index>),重试机制(--retry)\n
快速开始#
# 安装
go install github.com/meain/esa@latest
# 配置 API Key
export OPENAI_API_KEY="your-key"
# 基础使用
esa "what time is it"
esa +k8s "show pod status"
git diff --staged | esa +commit
Agent 配置示例#
name = "Kubernetes Command Assistant"
description = "An agent with read-only access to Kubernetes cluster"
system_prompt = """
You are a Kubernetes Command Assistant.
"""
[[functions]]
name = "get_namespaces"
description = "Retrieve all namespaces"
command = "kubectl get namespaces"
safe = true
[[functions]]
name = "get_resources"
command = "kubectl get {{resource}} {{namespace}}"
safe = true
[[functions.parameters]]
name = "resource"
type = "string"
required = true
典型应用场景#
- DevOps/Kubernetes 管理:
esa +k8s "what is the secret value that starts with AUD_" - Git 工作流:
git diff --staged | esa +commit - JIRA 集成:
esa +jira "list all open issues assigned to me" - 代码库分析:Tree-sitter 查询生成、代码搜索
- 个人工作流:时区转换、系统监控、Web 检索
核心价值#
- 减少混淆(LLM 选择更精准)
- 更好的工具调用(避免"猜脚本")
- 更快、更便宜(可用小模型)
- 更安全的自主性
技术要求#
- Go 1.23.6+
- 至少一个 LLM 提供商的 API Key
- 配置文件路径:
~/.config/esa/config.toml