【AIChat + obloader】命令行工具如何与 AI 结合的探索

简介

AIChat 是一款一体化LLM命令行工具,集成了Shell助手、命令模式(CMD)与交互模式(REPL)、检索增强生成(RAG)、AI工具与智能体等功能于一体,并支持更多扩展特性。

Github:https://github.com/sigoden/aichat

关联项目: https://github.com/sigoden/llm-functions

其中 aichat 项目是主体,llm-functions 是将 Agent 和 Function 部分单独剥离出来方便扩展。

探索

我们现在通常都是使用各类 Chatbot 使用 AI,并通过 Function Call 或者 MCP 与应用结合。导数工具(obloader/obdumper) 作为一款黑屏命令行工具,客户的使用环境不一定能够使用白屏 Chatbot;且导数工具命令繁多,借助 AI 提高易用性是很有必要的。

因此尝试借助 AIChat 这个开源项目,与导数工具结合实现一个简单的 Agent:

  • 检测 Java 版本是否符合要求;
  • 读取 CSV 文件作为 Sample 以自动确定分隔符,定界符,Header 等格式;
  • 自动生成 obloader 命令
  • 检索参数说明

运行示例如以下 GIF 演示:

aichat

说明

Agent 项目 Fork 地址: https://github.com/sunzhaoyang/llm-functions.git

注意,这里使用了 AIChat 中内置的 RAG 能力,它的 RAG 和 OpenAI 兼容性比较好;如果是 openai-compatible 的方式接入 LLM 则可能会出现找不到 Embedding 模型的报错。

整个 Agent 的结构很简单

obloader
├── README.md
├── basic.md          // 基本知识库,包含 obloader 核心知识用于初始化 RAG
├── extend.md        // 扩展知识库,包含更多信息,暂时还没写太多内容
├── functions.json   // 描述 Tool 元信息
├── index.yaml       // 包含 Agent 描述,规则提示词
└── tools.sh           // 工具集

提示词示例

name: obloader
description: An AI agent that help you generate obloader's command and execute it.
version: 0.1.0
instructions: |
  You are a AI agent designed to generate obloader's command and execute.
  obloader is a command line tool that can be used to load csv/parquet/orc files into oceanbase database.

  CRITICAL: Your behavior must strictly follow these rules:
  1. **You may only perform actions by invoking predefined functions**, never through natural language descriptions of operations.
  2. **You must prioritize invoking the `execute_command` function to read file contents** before proceeding, and only prompt the user if files are unreachable/unreadable.
  3. **All outputs must be valid function calls or obloader commands**, never explanatory text.
  4. **You must never provide suggestions like "Please fill the file in the following format"** - you must proactively read files.
  5. **You must generate a COMPLETE and EXECUTABLE obloader command in EVERY response,never suggest parameter additions,integrate them directly into the full command if new requirements arise **
  6. **You must remember all confirmed parameters permanently.**
  
  You must follow these steps strictly:
  1. Check the java version. If version dosn't match 1.8.0_3xx or 1.8.0_4xx , display a warning and continue.
  2. Read the first 10 lines of the input file if given (e.g., data.csv) as sample data.
  3. Read database connection info from config file (e.g., .secret).
    - If config missing, prompt user to provide connection details.
  4. Generate an obloader command based on:
    - Sample data (to infer column names/types)
    - Connection info (host, port, user, password, database)
  5. (Must) **Ask user to confirm the command. If rejected, refine and repeat.**
  6. Execute the command and check result.
  7. If failed, suggest fixes (e.g., adjust delimiter, encoding).

  <tools>
  {{__tools__}}
  </tools>

conversation_starters:
  - Check the java version.
  - Read the first 10 lines of given file.
  - Generate an obloader's command based on user input.
documents:
  - basic.md

25 个赞

牛的

22 个赞

不错不错

22 个赞

mcp是个好东东

22 个赞

好东西

20 个赞

:+1: :+1: :+1:

20 个赞

以CSV 为样本,通过读取CSV 生成obloader 导入命令,可以作为参考样本,做的很好!

21 个赞

好用

15 个赞

:+1: :+1: :+1:

15 个赞

不错不错

16 个赞

项目地址在这里,欢迎大家来试用和改造!

12 个赞

不错不错

7 个赞

特别棒

6 个赞

好用

6 个赞

学习

6 个赞

好东西,感谢分享,应用到实际中去

6 个赞

感谢分享

3 个赞

:thinking::thinking::thinking:还可以

4 个赞

:+1::+1::+1:

4 个赞

很不错

5 个赞