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>
This commit is contained in:
@@ -15,6 +15,15 @@ const (
|
||||
// HeaderStreamEnd 是 Token 流的结束信号(core NATS 消息头)。
|
||||
// 置为 "1" 的消息体为空,表示该 task 的 Token 流结束。
|
||||
HeaderStreamEnd = "X-Stream-End"
|
||||
|
||||
// MCP 工具调用约定(第 4 层 Dispatcher → 第 5 层 MCP Tools)。
|
||||
// 用 core NATS request-reply:同步拿结果,队列组内负载均衡。
|
||||
SubjectToolsGo = "sundynix.tools.go" // Go I/O 型工具前缀;实际 sundynix.tools.go.<tool>
|
||||
SubjectToolsGoAll = "sundynix.tools.go.>" // mcp-go 通配订阅
|
||||
SubjectToolsPy = "sundynix.tools.py" // Python 算法型工具前缀;实际 sundynix.tools.py.<tool>
|
||||
SubjectToolsPyAll = "sundynix.tools.py.>" // mcp-py 通配订阅
|
||||
QueueToolsGo = "mcp-go-workers" // mcp-go 队列组(多副本负载均衡)
|
||||
QueueToolsPy = "mcp-py-workers" // mcp-py 队列组
|
||||
)
|
||||
|
||||
// Task 是 DSL 解析组装后的可调度任务,在 NATS 上以 JSON 传输。
|
||||
@@ -30,6 +39,24 @@ func TaskSubject(id string) string { return SubjectTasks + "." + id }
|
||||
// StreamSubject 返回某任务的 Token 回流主题。
|
||||
func StreamSubject(id string) string { return SubjectStream + "." + id }
|
||||
|
||||
// ToolSubjectGo / ToolSubjectPy 返回某工具的调用主题。
|
||||
func ToolSubjectGo(tool string) string { return SubjectToolsGo + "." + tool }
|
||||
func ToolSubjectPy(tool string) string { return SubjectToolsPy + "." + tool }
|
||||
|
||||
// ToolCall 是 Dispatcher 对一个 MCP 工具的调用请求(NATS request 体)。
|
||||
type ToolCall struct {
|
||||
Tool string `json:"tool"` // 工具名,如 wiki_search
|
||||
Args map[string]any `json:"args,omitempty"` // 工具参数
|
||||
TaskID string `json:"task_id,omitempty"` // 触发该调用的任务(便于追踪)
|
||||
}
|
||||
|
||||
// ToolResult 是 MCP 工具的应答(NATS reply 体)。
|
||||
type ToolResult struct {
|
||||
OK bool `json:"ok"`
|
||||
Content string `json:"content,omitempty"` // 工具产出(如检索结果文本)
|
||||
Error string `json:"error,omitempty"` // 非空表示工具内部出错
|
||||
}
|
||||
|
||||
// Marshal / Unmarshal 便捷方法。
|
||||
func (t *Task) Marshal() ([]byte, error) { return json.Marshal(t) }
|
||||
func Unmarshal(b []byte) (*Task, error) {
|
||||
|
||||
Reference in New Issue
Block a user