adc521f94d
第 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>
45 lines
1.3 KiB
Go
45 lines
1.3 KiB
Go
// Command dispatcher 启动 sundynix-dispatcher —— 第 4 层 AI Agent 调度集群。
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"log"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"github.com/sundynix/sundynix-dispatcher/internal/eino"
|
|
"github.com/sundynix/sundynix-dispatcher/internal/harness"
|
|
"github.com/sundynix/sundynix-dispatcher/internal/llm"
|
|
dnats "github.com/sundynix/sundynix-dispatcher/internal/nats"
|
|
)
|
|
|
|
func main() {
|
|
natsURL := envOr("NATS_URL", "nats://localhost:4222")
|
|
|
|
pool := llm.NewPool() // LLM Pool: vLLM / Ollama 集群
|
|
breaker := harness.NewCircuitBreaker() // Harness: 熔断降级中心
|
|
|
|
sub := dnats.MustConnect(natsURL)
|
|
defer sub.Close()
|
|
|
|
// sub 同时作为 Token 回流出口(TokenSink)与 MCP 工具调用出口(ToolCaller)。
|
|
orch := eino.NewOrchestrator(pool, breaker, sub, sub)
|
|
|
|
// 监听退出信号,优雅停止消费。
|
|
ctx, stop := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM)
|
|
defer stop()
|
|
|
|
log.Println("[dispatcher] consuming sundynix.tasks.* (Ctrl-C to quit)")
|
|
if err := sub.ConsumeTasks(ctx, orch.Handle); err != nil && err != context.Canceled {
|
|
log.Fatalf("[dispatcher] exit: %v", err)
|
|
}
|
|
}
|
|
|
|
func envOr(key, def string) string {
|
|
if v := os.Getenv(key); v != "" {
|
|
return v
|
|
}
|
|
return def
|
|
}
|