Skip to content

nailcui/ipa

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ipa

一个面向学习场景的通用 AI 智能体,在终端中与 LLM 对话,自主调用工具完成任务。

Go Version License

特性

  • 交互式终端 REPL — 在命令行中与 AI 自然对话,支持流式输出
  • Agentic Loop — Agent 自主规划并调用工具,多步推理直至完成任务
  • 可扩展工具系统 — 实现 Tool 接口即可注册新工具,内置 read_file 工具
  • 用户确认机制 — 每次工具调用前需用户确认,安全可控
  • Ctrl+C 随时中断 — 通过 context 取消正在执行的 Agent 循环

快速开始

前置条件

安装

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 会自主推理并调用工具来回答。

REPL 命令

命令 说明
/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 会:

  1. 将对话历史和可用工具定义发送给 LLM
  2. LLM 返回文本回复或工具调用请求
  3. 文本回复直接展示给用户;工具调用经用户确认后执行,结果回传给 LLM
  4. 重复直至 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

About

General AI agent for learning.

Resources

License

Stars

0 stars

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages