f238ae1455
让画布上串联的多个 agent 真正协作完成一件事(如 检索→撰写→审查 出报告), 而非各自对原 query 重答: - board 增 agentOut(各上游 agent 产出按序);RunCtx 增 Upstream,buildMessages 注入"前序协作 agent 的产出,请在此基础上继续"。 - runAgent / runReactAgent / runComposeConversation 三条路径统一:注入 b.agentOut 作上下文,产出经 recordAgentOutput 入黑板(append agentOut + 设为当前成稿 answer, 多 agent 时最后一个 agent 产出即最终成品)。 不需要 eino multiagent 组件——编排式协作由现有图引擎 + 上下文传递实现。 测试 TestAgentCollaborationPassesOutput:下游 agent 确见上游产出、成稿=下游产出; make test-go 全绿。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
47 lines
1.5 KiB
Go
47 lines
1.5 KiB
Go
package eino
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
"testing"
|
|
|
|
"github.com/sundynix/sundynix-dispatcher/internal/harness"
|
|
"github.com/sundynix/sundynix-dispatcher/internal/llm"
|
|
"github.com/sundynix/sundynix-shared/contract"
|
|
)
|
|
|
|
// TestAgentCollaborationPassesOutput 验证编排式多智能体接力:
|
|
// agent1 的产出注入 agent2 的上下文,agent2 基于它继续;最终成稿 = 下游 agent 的产出。
|
|
func TestAgentCollaborationPassesOutput(t *testing.T) {
|
|
graph := `{"version":"1","nodes":[
|
|
{"id":"a1","kind":"agent","config":{"system":"研究"}},
|
|
{"id":"a2","kind":"agent","config":{"system":"撰写"}}
|
|
],"edges":[{"source":"a1","target":"a2"}]}`
|
|
|
|
saw := false
|
|
ll := &fakeLLM{ready: true, stream: func(m []llm.ChatMessage) string {
|
|
var sys string
|
|
for _, x := range m {
|
|
if x.Role == "system" {
|
|
sys = x.Content
|
|
}
|
|
}
|
|
if strings.Contains(sys, "研究产出XYZ") { // agent1 的产出出现在 agent2 的 system → 接力成功
|
|
saw = true
|
|
return "最终报告:基于上游研究撰写"
|
|
}
|
|
return "研究产出XYZ"
|
|
}}
|
|
o := &Orchestrator{pool: ll, breaker: harness.NewCircuitBreaker(), sink: &fakeSink{}}
|
|
ans, err := o.runGraph(context.Background(), &contract.Task{ID: "tc", Graph: []byte(graph)}, &execTracer{})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
if !saw {
|
|
t.Fatal("下游 agent 未看到上游 agent 的产出——协作没接力")
|
|
}
|
|
if !strings.Contains(ans, "最终报告") {
|
|
t.Fatalf("最终成稿应为下游 agent 产出,得 %q", ans)
|
|
}
|
|
}
|