Files
Blizzard 4928ffc0f7 feat: 短期多轮历史接入 Eino 图 MessagesPlaceholder (⑨)
会话历史(Redis,易失,与长期画像分开)经 MCP 工具进出 Eino 图:
recall 召回历史填 MessagesPlaceholder,写回把本轮 user/assistant 落历史。

- mcp-go: internal/history(go-redis, sundynix:history:<session>, LPUSH+LTRIM 保留近20条,
  24h TTL) + 工具 history_get(返回JSON turns)/history_append; main 开 Redis(降级)
- dispatcher Eino: 模板加 MessagesPlaceholder('history'); recall 调 history_get→转 schema.Message;
  Handle 累积 answer; memorize 异步 history_append(user+assistant)
- shared: contract.MetaSessionID; gateway: SubmitTask 注入 Meta[session_id](X-Session-ID 头,缺省 default)
- demo.sh: 同会话两轮提交,验证第2轮召回第1轮历史
- 验证: 4 模块 build✓ + 3 e2e PASS; live 跑通——轮1=0轮历史→落库, 轮2 history_get 命中→注入

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-10 14:18:45 +08:00

78 lines
3.2 KiB
Bash
Executable File
Raw Permalink 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
USER="wt"
echo "== 登记用户偏好记忆 (→ mcp-go memory_upsert → sundynix_user_profile) =="
curl -s -X PUT http://127.0.0.1:8080/api/v1/memory \
-H 'Content-Type: application/json' -H "X-User-ID: $USER" \
-d '{"key":"称呼","value":"老王"}'; echo
curl -s -X PUT http://127.0.0.1:8080/api/v1/memory \
-H 'Content-Type: application/json' -H "X-User-ID: $USER" \
-d '{"key":"回答偏好","value":"简洁、中文、多给要点"}'; echo
SESSION="sess-demo"
# 清掉上一次 demo 的会话历史,让本次轮次计数从 0 起(best-effort,无 Redis 容器则跳过)。
docker exec sundynix_agentix-redis-1 redis-cli DEL "sundynix:history:$SESSION" >/dev/null 2>&1 || true
submit_and_stream() {
local prompt="$1"
local resp task_id
resp=$(curl -s -X POST http://127.0.0.1:8080/api/v1/tasks \
-H 'Content-Type: application/json' -H "X-User-ID: $USER" -H "X-Session-ID: $SESSION" \
-d "{\"nodes\":[{\"id\":\"n1\",\"type\":\"agent\",\"data\":{\"prompt\":\"$prompt\"}}],\"edges\":[]}")
echo "$resp"
task_id=$(echo "$resp" | sed -n 's/.*"task_id":"\([^"]*\)".*/\1/p')
# 客户端在 TTFT(700ms) 内连上即可收全部 token--max-time 超时(exit 28) 属正常
curl -sN --max-time 12 "http://127.0.0.1:8080/api/v1/tasks/$task_id/stream" || true
echo
}
echo "== 第 1 轮提交 (带 X-User-ID + X-Session-ID,召回画像) =="
submit_and_stream "你好"
sleep 1 # 等写回把第 1 轮落进会话历史
echo "== 第 2 轮提交 (同会话,应召回到第 1 轮历史) =="
submit_and_stream "继续"
echo "== mcp-go 日志 (工具被调用) =="
cat .bin/mcp-go.log
echo "== dispatcher 日志 =="
cat .bin/dispatcher.log