一个面向学习场景的通用 AI 智能体,在终端中与 LLM 对话,自主调用工具完成任务。
- 交互式终端 REPL — 在命令行中与 AI 自然对话,支持流式输出
- Agentic Loop — Agent 自主规划并调用工具,多步推理直至完成任务
- 可扩展工具系统 — 实现
Tool接口即可注册新工具,内置read_file工具 - 用户确认机制 — 每次工具调用前需用户确认,安全可控
- Ctrl+C 随时中断 — 通过 context 取消正在执行的 Agent 循环
- Go 1.26+
- Anthropic API Key
go install github.com/nailcui/ipa/cmd/ipa@latest或从源码编译:
git clone https://github.com/nailcui/ipa.git
cd ipa
go build -o ipa ./cmd/ipa/首次运行会自动在 ~/.ipa/settings.json 创建默认配置文件:
{
"provider": "anthropic",
"model": "claude-sonnet-4-20250514",
"api_key": "",
"base_url": "https://api.anthropic.com/v1",
"max_steps": 30
}在 api_key 字段填入你的 Anthropic API Key 即可使用。
ipa进入 REPL 后直接输入问题,Agent 会自主推理并调用工具来回答。
| 命令 | 说明 |
|---|---|
/help |
查看帮助信息 |
/tools |
列出所有已注册工具 |
/clear |
清空对话历史 |
/exit |
退出程序 |
cmd/ipa/main.go # 程序入口
internal/
agent/ # Agent 核心:状态机、Agentic Loop
cli/ # REPL 终端界面:命令解析、流式渲染
config/ # 配置管理
llm/ # LLM 抽象层与 Anthropic 适配器
tool/ # 工具系统接口与内置工具
用户输入 → REPL → Agentic Loop
├─ 调用 LLM(流式输出文本回复)
├─ LLM 调用工具 → 用户确认 → 执行工具
└─ 循环直至 LLM 给出最终回答
每轮对话中,Agent 会:
- 将对话历史和可用工具定义发送给 LLM
- LLM 返回文本回复或工具调用请求
- 文本回复直接展示给用户;工具调用经用户确认后执行,结果回传给 LLM
- 重复直至 LLM 不再调用工具(默认最多 30 步)
实现 tool.Tool 接口即可添加自定义工具:
type Tool interface {
Name() string
Description() string
Parameters() map[string]interface{}
Execute(ctx context.Context, args map[string]interface{}) (string, error)
}在 cmd/ipa/main.go 中注册:
registry.Register(myCustomTool)MIT © 2026 nailcui