使用说明
Gemini代理
Python包装器 谷歌Gemini CLI 代理能力。
安装
pip install gemini-agent # client only
pip install gemini-agent[core] # + direct CLI usage
pip install gemini-agent[server] # + REST API service
要求: Node.js 18+和 npm install -g @google/gemini-cli
快速开始
export GEMINI_API_KEY=your_key
from gemini_agent.core import GeminiAgent
agent = GeminiAgent()
result = agent.run("Create a Python CLI that lists files")
print(result.response) # Gemini's response
print(result.modified_files) # {"cli.py": "import os..."}
用法
直接CLI包装器
from gemini_agent.core import GeminiAgent
agent = GeminiAgent(
model="gemini-2.5-flash", # optional
sandbox=True, # isolated execution
)
result = agent.run(
"Build a REST API with FastAPI",
mcp_servers=["filesystem"],
files={"spec.txt": "..."},
)
# result.success, result.response, result.modified_files
Python客户端(远程)
from gemini_agent.client import GeminiAgentClient
async with GeminiAgentClient("http://localhost:8000") as client:
result = await client.run("Create a hello world script")
print(result.modified_files)
REST API
podman-compose up -d --build
# Submit task
curl -X POST http://localhost:8000/tasks \
-H "Content-Type: application/json" \
-d '{"prompt": "Create a fibonacci function"}'
# Get result
curl http://localhost:8000/tasks/{task_id}
API终点
| 方法 | 端点 | 描述 |
|---|---|---|
POST |
/tasks |
提交任务 |
GET |
/tasks/{id} |
获取结果 |
DELETE |
/tasks/{id} |
取消任务 |
GET |
/health |
健康检查 |
GET |
/mcp/servers |
列出MCP服务器 |
POST |
/mcp/servers |
添加MCP服务器 |
配置
| 变量 | 描述 |
|---|---|
GEMINI_API_KEY |
API密钥(必需) |
GEMINI_MODEL |
模型覆盖 |
GEMINI_TIMEOUT |
超时时间(秒)(默认值:300) |
REDIS_URL |
服务器模式的Redis URL |
许可证
麻省理工学院
