AI代理CLI工具

支持MCP(模型上下文协议)服务器的AI代理命令行工具,提供交互式操作和外部工具集成。

  • by alexkutsan
  • Crystal
  • 本地部署
  • 更新于
在 GitHub 查看 alexkutsan/agentish

使用说明

代理

具有MCP(模型上下文协议)服务器支持的AI代理的CLI。

建在上面 AgentKit 的 图书馆。

安装

需求

  • 晶体>=1.19.0
  • OpenAI API密钥(或兼容提供程序)

从源代码构建

git clone https://github.com/alexkutsan/agentish.git
cd agentish
shards install
shards build --release

二进制将位于 ./bin/agentish.


快速开始

1.创建配置

mkdir -p ~/.config/agentish
cat > ~/.config/agentish/config.json << 'EOF'
{
  "openaiApiKey": "sk-your-api-key-here",
  "openaiModel": "gpt-4o"
}
EOF

2.运行代理

./bin/agentish -p "Hello! How are you?"

用法

# Direct prompt
./bin/agentish -p "Your question"

# Prompt from file
./bin/agentish prompt.txt

# Output to file
./bin/agentish -p "Generate a list" -o result.txt

# Interactive mode
./bin/agentish -i

# Specify config
./bin/agentish -p "Question" -c /path/to/config.json

选项

选项 描述
-p, --prompt 提示文本
-o, --output 输出文件(默认:stdout)
-c, --config 配置文件路径
-i, --interactive 交互模式(REPL)
-h, --help 显示帮助
-v, --version 显示版本

配置

代理在以下位置查找配置:

  1. ~/.config/crystal_agent/config.json
  2. ~/.crystal_agent.json

最小配置

{
  "openaiApiKey": "sk-..."
}

完整配置

{
  "openaiApiKey": "sk-...",
  "openaiApiHost": "https://api.openai.com",
  "openaiModel": "gpt-4o",
  "maxIterations": 10,
  "timeoutSeconds": 120,
  "mcpServers": {
    "my-server": {
      "type": "http",
      "url": "http://localhost:8000/mcp"
    }
  }
}
参数 说明 默认值
openaiApiKey API密钥(必需) -
openaiApiHost API URL https://api.openai.com
openaiModel 型号 gpt-4o
maxIterations 最大迭代次数 10
timeoutSeconds 超时(秒) 120
mcpServers MCP服务器 {}

日志记录 通过ENV配置: CRYSTAL_AGENT_LOG_LEVEL (debug/info/awarn/error,默认值 warn)以及 CRYSTAL_AGENT_LOG_FILE.


MCP服务器

代理可以连接到MCP服务器以使用外部工具。

没有HTTP配置 "type": "http" 被视为无效。环境变量可以用作 ${VAR} 或 ${VAR:-default}.

{
  "openaiApiKey": "sk-...",
  "mcpServers": {
    "filesystem": {
      "type": "http",
      "url": "http://localhost:8000/mcp"
    },
    "database": {
      "type": "http",
      "url": "http://localhost:8001/mcp",
      "headers": {
        "Authorization": "Bearer token"
      }
    }
  }
}

Stdio MCP服务器(本地进程)

{
  "openaiApiKey": "sk-...",
  "mcpServers": {
    "local-tools": {
      "command": "python3",
      "args": ["-u", "/path/to/mcp_server.py"]
    }
  }
}

启动时,代理会自动连接到服务器并注册可用工具。


文档


许可证

麻省理工学院