使用说明
桥梁与检查情报员
本地AI代理: QwenV3(奥利玛) + 桥接MCP服务器(stdio、TypeScript). 没有云。一切都在你的Linux机器上运行。
bridges-inspections-agent/
├── AGENT.md ← agent definition, domain rules, memory spec
├── config.yaml ← model + MCP launch settings
├── agent.py ← Python agentic loop
├── requirements.txt ← Python deps
├── .env.example ← env var template
├── memory/
│ └── MEMORY.md ← auto-managed memory index
└── mcp-server/
├── index.ts ← MCP server (your original, unchanged)
├── package.json
└── tsconfig.json
先决条件
| 工具 | 版本 | 安装 |
|---|---|---|
| Python | ≥3.10 | sudo apt install python3 |
| Node.js | ≥18 | sudo apt install nodejs npm |
| Ollama | 最新 | curl -fsSL https://ollama.com/install.sh | sh |
1--拉动模型
ollama pull qwen3:8b
对于8GB VRAM, qwen3:8b 是安全默认值(~5.5 GB)。
2--构建MCP服务器
cd mcp-server
npm install
npm run build # compiles index.ts → dist/index.js
cd ..
验证服务器是否正确说出MCP:
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"test","version":"0"}}}' \
| API_BASE_URL=http://localhost:3003 API_KEY=secret node mcp-server/dist/index.js
您应该看到一个JSON响应 serverInfo.
3--配置环境
cp .env.example .env
# Edit .env: set API_BASE_URL and API_KEY to match your REST API
export API_BASE_URL=http://localhost:3003
export API_KEY=your_secret
4--安装Python deps
pip install -r requirements.txt
5--启动Olama
OLLAMA_GPU_LAYERS=99 ollama serve
6--运行代理
# Single query
python agent.py "Show me statistics of all bridges"
# Interactive REPL
python agent.py --interactive
代理程序启动MCP服务器作为 子进程 通过stdio自动--
你不需要开始 node mcp-server/dist/index.js 单独。
查询示例
Show me statistics of all bridges
List all bridges with condition grade D
Which inspections are currently in_review?
Get the full profile for bridge <uuid>
Show me the photo gallery for bridge <uuid>
List pending inspections assigned to inspector <uuid>
Which bridges haven't been inspected this fiscal year?
Get the full inspection report for inspection <uuid>
更改模型
编辑 config.yaml:
model: qwen3:8b # default — safe for 8 GB VRAM
# model: qwen3:8b-q4_K_M # lighter, ~4.5 GB
# model: qwen3:14b-q4_K_M # best quality, fills 8 GB
MCP连接的工作原理
agent.py
└── spawns subprocess: node mcp-server/dist/index.js
├── stdin ← JSON-RPC requests (tools/list, tools/call)
└── stdout → JSON-RPC responses
└── MCP server calls your REST API (API_BASE_URL)
with Bearer API_KEY
Python mcp SDK(stdio_client)处理所有框架。
代理从不直接调用REST API,只有MCP服务器会调用。
故障排除
| 症状 | 修复 |
|---|---|
CUDA out of memory |
切换到 qwen3:8b-q4_K_M 在 config.yaml |
ModuleNotFoundError: mcp |
pip install mcp |
Cannot find module 'dist/index.js' |
快跑 npm run build 在 mcp-server/ |
API error 401 |
检查 API_KEY env-var与您的REST API匹配 |
API error 404 |
检查 API_BASE_URL 指向正在运行的REST API |
| Agent返回散文而不是调用工具 | 较低 temperature 到 0.1 |
模型输出 <think> blocks |
自动剥离-无需任何操作 |