feat: expand node agent routing and media artifacts

This commit is contained in:
lpf
2026-03-09 01:21:19 +08:00
parent c0fe977bce
commit 2d5a384342
14 changed files with 1291 additions and 81 deletions

View File

@@ -352,10 +352,15 @@ func (al *AgentLoop) dispatchNodeSubagentTask(ctx context.Context, task *tools.S
return "", fmt.Errorf("node-backed subagent %q missing node_id", task.AgentID)
}
taskInput := loopTaskInputForNode(task)
reqArgs := map[string]interface{}{}
if remoteAgentID := remoteAgentIDForNodeBranch(task.AgentID, nodeID); remoteAgentID != "" {
reqArgs["remote_agent_id"] = remoteAgentID
}
resp, err := al.nodeRouter.Dispatch(ctx, nodes.Request{
Action: "agent_task",
Node: nodeID,
Task: taskInput,
Args: reqArgs,
}, "auto")
if err != nil {
return "", err
@@ -372,6 +377,23 @@ func (al *AgentLoop) dispatchNodeSubagentTask(ctx context.Context, task *tools.S
return fmt.Sprintf("node %s completed agent_task", nodeID), nil
}
func remoteAgentIDForNodeBranch(agentID, nodeID string) string {
agentID = strings.TrimSpace(agentID)
nodeID = strings.TrimSpace(nodeID)
if agentID == "" || nodeID == "" {
return ""
}
prefix := "node." + nodeID + "."
if !strings.HasPrefix(agentID, prefix) {
return ""
}
remote := strings.TrimPrefix(agentID, prefix)
if strings.TrimSpace(remote) == "" {
return ""
}
return remote
}
func loopTaskInputForNode(task *tools.SubagentTask) string {
if task == nil {
return ""

View File

@@ -23,6 +23,9 @@ func TestDispatchNodeSubagentTaskUsesNodeAgentTask(t *testing.T) {
if req.Action != "agent_task" {
t.Fatalf("unexpected action: %s", req.Action)
}
if got, _ := req.Args["remote_agent_id"].(string); got != "coder" {
t.Fatalf("expected remote_agent_id=coder, got %+v", req.Args)
}
if !strings.Contains(req.Task, "Parent Agent: main") {
t.Fatalf("expected parent-agent context in task, got %q", req.Task)
}
@@ -43,7 +46,7 @@ func TestDispatchNodeSubagentTaskUsesNodeAgentTask(t *testing.T) {
}
out, err := loop.dispatchNodeSubagentTask(context.Background(), &tools.SubagentTask{
ID: "subagent-1",
AgentID: "node.edge-dev.main",
AgentID: "node.edge-dev.coder",
Transport: "node",
NodeID: "edge-dev",
ParentAgentID: "main",