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>
This commit is contained in:
+22
-10
@@ -46,17 +46,29 @@ 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
|
||||
|
||||
echo "== 提交 DSL 任务 (带 X-User-ID,Dispatcher 将召回其画像) =="
|
||||
RESP=$(curl -s -X POST http://127.0.0.1:8080/api/v1/tasks \
|
||||
-H 'Content-Type: application/json' -H "X-User-ID: $USER" \
|
||||
-d '{"nodes":[{"id":"n1","type":"agent","data":{"prompt":"hello"}}],"edges":[]}')
|
||||
echo "$RESP"
|
||||
TASK_ID=$(echo "$RESP" | sed -n 's/.*"task_id":"\([^"]*\)".*/\1/p')
|
||||
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
|
||||
|
||||
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
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user