sipeed/picoclaw · error

target agent not found in registry

Error message

target agent %q not found in registry

What it means

Registry lookup guard in spawnSubTurn: the request's TargetAgentID names an agent that is not present in the agent registry, so the child cannot inherit that agent's workspace/model/tools/system prompt. The lookup happens on the deliberately parent-independent child context; the %q is the unmatched agent id from the spawn request.

Solutions

  1. Verify the TargetAgentID matches a registered agent (exact id, no typos)
  2. Ensure the target agent is started before the spawning turn runs
  3. Register the intended agent in the loop's registry at startup
  4. Fall back to the parent agent when the target is optional
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at pkg/agent/subturn.go:350 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sipeed/picoclaw@49183d7e8d (2026-08-15). Data as JSON: /api/errors/465018999bf685d8. Report an issue: GitHub.

Appendix: source

Thrown at pkg/agent/subturn.go:350

	// 4. Create INDEPENDENT child context (not derived from parent ctx).
	// This allows the child to continue running after parent finishes gracefully.
	// The child has its own timeout for self-protection.
	childCtx, cancel := context.WithTimeout(context.Background(), timeout)
	defer cancel()

	childID := al.generateSubTurnID()

	// Resolve the agent instance for the child turn.
	// When TargetAgentID is set, look up that agent from the registry so the
	// child runs with the target's workspace, model, tools, and system prompt.
	// Otherwise fall back to the parent's agent (existing behavior).
	var baseAgent *AgentInstance
	if cfg.TargetAgentID != "" {
		var ok bool
		baseAgent, ok = al.registry.GetAgent(cfg.TargetAgentID)
		if !ok {
			return nil, fmt.Errorf("target agent %q not found in registry", cfg.TargetAgentID)
		}
	} else {
		baseAgent = parentTS.agent
		if baseAgent == nil {
			baseAgent = al.registry.GetDefaultAgent()
		}
	}
	if baseAgent == nil {
		return nil, errors.New("parent turnState has no agent instance")
	}
	ephemeralStore := newEphemeralSession(nil)
	agent := *baseAgent // shallow copy
	agent.Sessions = ephemeralStore
	// Clone the tool registry so child turn's tool registrations
	// don't pollute the parent's registry.
	if baseAgent.Tools != nil {
		agent.Tools = baseAgent.Tools.Clone()
	}

View on GitHub (pinned to 49183d7e8d)