{"record":{"id":"e8d670b367b6c97e","repo":"microsoft/semantic-kernel","slug":"the-agent-agent-name-agent-id-cannot-have-a-h","errorCode":null,"errorMessage":"The agent {agent.Name ?? agent.Id} cannot have a handoff to itself.","messagePattern":"The agent (.+?) cannot have a handoff to itself\\.","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Agents/Orchestration/Handoff/HandoffActor.cs","lineNumber":45,"sourceCode":"    private string? _handoffAgent;\n    private string? _taskSummary;\n\n    /// <summary>\n    /// Initializes a new instance of the <see cref=\"HandoffActor\"/> class.\n    /// </summary>\n    /// <param name=\"id\">The unique identifier of the agent.</param>\n    /// <param name=\"runtime\">The runtime associated with the agent.</param>\n    /// <param name=\"context\">The orchestration context.</param>\n    /// <param name=\"agent\">An <see cref=\"Agent\"/>.</param>\n    /// <param name=\"handoffs\">The handoffs available to this agent</param>\n    /// <param name=\"resultHandoff\">The handoff agent for capturing the result.</param>\n    /// <param name=\"logger\">The logger to use for the actor</param>\n    public HandoffActor(AgentId id, IAgentRuntime runtime, OrchestrationContext context, Agent agent, HandoffLookup handoffs, AgentType resultHandoff, ILogger<HandoffActor>? logger = null)\n        : base(id, runtime, context, agent, logger)\n    {\n        if (handoffs.ContainsKey(agent.Name ?? agent.Id))\n        {\n            throw new ArgumentException($\"The agent {agent.Name ?? agent.Id} cannot have a handoff to itself.\", nameof(handoffs));\n        }\n\n        this._cache = [];\n        this._handoffs = handoffs;\n        this._resultHandoff = resultHandoff;\n    }\n\n    /// <summary>\n    /// Gets or sets the callback to be invoked for interactive input.\n    /// </summary>\n    public OrchestrationInteractiveCallback? InteractiveCallback { get; init; }\n\n    /// <inheritdoc/>\n    protected override bool ResponseCallbackFilter(ChatMessageContent response) => response.Role == AuthorRole.Tool;\n\n    /// <inheritdoc/>\n    protected override AgentInvokeOptions CreateInvokeOptions(Func<ChatMessageContent, Task> messageHandler)\n    {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Agents/Orchestration/Handoff/HandoffActor.cs#L27-L63","documentation":"Thrown by the HandoffActor constructor when the handoffs map already contains the agent's own name/id. A self-handoff is a no-op that would loop forever (the agent handing control back to itself), so it is rejected at construction with ArgumentException.","triggerScenarios":"Defining a HandoffOrchestration where an agent's handoff dictionary includes its own Name (or Id when Name is null) as a key.","commonSituations":"Auto-generated handoff maps that copy every agent into every map; a typo using the agent's own name as a target.","solutions":["Remove the self-reference from the agent's handoff map.","When generating handoff maps programmatically, exclude the agent itself."],"exampleFix":"// before\nvar handoffs = new HandoffLookup { [\"writer\"] = new() { [\"writer\"] = new(/*...*/) } };\n\n// after — do not let an agent hand off to itself\nvar handoffs = new HandoffLookup { [\"writer\"] = new() { [\"reviewer\"] = new(/*...*/) } };","handlingStrategy":"validation","validationCode":"// Build handoff maps from the member list, excluding self\nforeach (var agent in agents)\n{\n    var targets = desiredTargets[agent.Name].Where(n => n != (agent.Name ?? agent.Id));\n    handoffs[agent.Name] = new(targets.Select(n => new Handoff(n)));\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never include an agent's own name in its handoff map.","Generate handoff maps programmatically and filter out self.","Review handoff definitions for accidental self-references."],"tags":["orchestration","handoff","configuration","agents","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}