Files
sundynix-agentix/scripts/demo.sh
T
Blizzard adc521f94d feat: 打通 Dispatcher→MCP 工具调用链路 (core NATS request-reply)
第 4 层 Dispatcher 经 NATS request-reply + 队列组同步调用第 5 层 MCP 工具,
工具不可用/超时即降级,不阻断主流程。

- shared/contract: ToolCall/ToolResult + sundynix.tools.go.* subject 约定 + ToolSubjectGo/Py
- shared/bus: CallTool(发起) / ServeTool(队列组订阅+应答)
- mcp-go: 接共享 bus,gateway 通配订阅按工具名分发(wiki_search/echo),main 优雅退出
- dispatcher: ToolCaller 接口 + Orchestrator.retrieveContext(调 wiki_search,超时3s降级)
- e2e: TestToolCallRoundTrip(PASS);demo.sh 加 mcp-go(就绪门避免启动竞态),live 跑通

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 11:31:58 +08:00

57 lines
2.3 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env bash
# 无 Docker 的最小任务流演示:devnats(内嵌NATS) + gateway + dispatcher + mcp-go。
# 提交一个 DSL 任务,验证 Gateway → NATS → Dispatcher → MCP 工具 全链路。
set -euo pipefail
cd "$(dirname "$0")/.."
mkdir -p .bin
echo "== 编译 =="
( cd sundynix-shared && go build -o ../.bin/devnats ./cmd/devnats )
( cd sundynix-gateway && go build -o ../.bin/gateway ./cmd/server )
( cd sundynix-dispatcher && go build -o ../.bin/dispatcher ./cmd/dispatcher )
( cd sundynix-mcp-go && go build -o ../.bin/mcp-go ./cmd/server )
cleanup() { kill "${GW_PID:-}" "${DISP_PID:-}" "${MCP_PID:-}" "${NATS_PID:-}" 2>/dev/null || true; }
trap cleanup EXIT
# 若 :4222 已有 NATSdocker compose 的容器),直接复用;否则起内嵌 devnats。
if nc -z 127.0.0.1 4222 2>/dev/null; then
echo "== 检测到已运行的 NATS(:4222),复用之 =="
else
echo "== 启动内嵌 devnats =="
.bin/devnats > .bin/devnats.log 2>&1 & NATS_PID=$!
for _ in $(seq 1 30); do nc -z 127.0.0.1 4222 2>/dev/null && break || sleep 0.2; done
fi
echo "== 启动 mcp-go / dispatcher / gateway =="
.bin/mcp-go > .bin/mcp-go.log 2>&1 & MCP_PID=$!
.bin/dispatcher > .bin/dispatcher.log 2>&1 & DISP_PID=$!
.bin/gateway > .bin/gateway.log 2>&1 & GW_PID=$!
for _ in $(seq 1 30); do
curl -s -o /dev/null http://127.0.0.1:8080/api/v1/billing && break || sleep 0.3
done
# 等 mcp-go 订阅就绪后再提交,否则工具调用会撞上启动竞态而降级。
for _ in $(seq 1 30); do
grep -q "tools ready" .bin/mcp-go.log 2>/dev/null && break || sleep 0.1
done
echo "== 提交 DSL 任务 =="
RESP=$(curl -s -X POST http://127.0.0.1:8080/api/v1/tasks \
-H 'Content-Type: application/json' \
-d '{"nodes":[{"id":"n1","type":"agent","data":{"prompt":"hello"}}],"edges":[]}')
echo "$RESP"
TASK_ID=$(echo "$RESP" | sed -n 's/.*"task_id":"\([^"]*\)".*/\1/p')
echo "== 订阅 SSE Token 流 (Gateway ← NATS ← Dispatcher) =="
# 客户端在 TTFT(700ms) 内连上即可收全部 token--max-time 超时(exit 28) 属正常,不让 set -e 中断
curl -sN --max-time 10 "http://127.0.0.1:8080/api/v1/tasks/$TASK_ID/stream" || true
echo
echo "== mcp-go 日志 (工具被调用) =="
cat .bin/mcp-go.log
echo "== dispatcher 日志 =="
cat .bin/dispatcher.log