microsoft/autogen · error · InvalidOperationException

Request message is missing a target. Message: '{request}'.

Error message

Request message is missing a target. Message: '{request}'.

What it means

A plain InvalidOperationException (not an RpcException) thrown in GrpcGateway.DispatchRequestAsync when an RpcRequest arrives with a null Target. The target identifies which agent (or agent type) the invocation is for; the gateway cannot route or place the agent without it, so it fails fast.

Source

Thrown at dotnet/src/Microsoft.AutoGen/RuntimeGateway.Grpc/Services/Grpc/GrpcGateway.cs:434

            _logger.LogWarning("No agent types found for event type {EventType}. Adding to Dead Letter Queue", evt.Type);
            // buffer the event to the dead-letter queue
            await _messageRegistry.AddMessageToDeadLetterQueueAsync(evt.Source, evt).ConfigureAwait(true);
        }
    }

    /// <summary>
    /// Dispatches a request to the appropriate agent.
    /// </summary>
    /// <param name="connection">The worker connection.</param>
    /// <param name="request">The RPC request.</param>
    /// <returns>A task that represents the asynchronous operation.</returns>
    private async ValueTask DispatchRequestAsync<TMessage>(GrpcWorkerConnection<TMessage> connection, RpcRequest request)
    where TMessage : class
    {
        var requestId = request.RequestId;
        if (request.Target is null)
        {
            throw new InvalidOperationException($"Request message is missing a target. Message: '{request}'.");
        }
        await InvokeRequestDelegate(connection, request, async request =>
        {
            var (gateway, isPlacement) = await _gatewayRegistry.GetOrPlaceAgent(request.Target);
            if (gateway is null)
            {
                return new RpcResponse { Error = "Agent not found and no compatible gateways were found." };
            }
            if (isPlacement)
            {
                // TODO// Activate the worker: load state
            }
            // Forward the message to the gateway and return the result.
            return await gateway.InvokeRequestAsync(request).ConfigureAwait(true);
        }).ConfigureAwait(false);
    }

    /// <summary>

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Set request.Target (the target agent/type descriptor) on every RpcRequest before writing it to the worker stream.
  2. Add a client-side assertion/serializer test that RpcRequest.Target round-trips non-null.
  3. If the request comes from user code or a planner, validate the target argument at the API boundary before converting it to an RpcRequest.

Example fix

// before
var req = new RpcRequest { Method = "echo", Arguments = args };

// after
var req = new RpcRequest { Target = new AgentId("worker", id), Method = "echo", Arguments = args };
Defensive patterns

Strategy: type-guard

Type guard

static bool HasTarget(RpcRequest request) => request?.Target is not null && !string.IsNullOrEmpty(request.Target.ToString());

// usage
if (!HasTarget(request)) throw new ArgumentException($"RpcRequest needs a Target: {request}");

Try / catch

try { await DispatchRequestAsync(connection, request); }
catch (InvalidOperationException ex) when (ex.Message.Contains("missing a target"))
{
    _logger.LogError("Dropping malformed RpcRequest {RequestId}: target not set.", request.RequestId);
    // return an error RpcResponse instead of crashing the read loop
}

Prevention

When it happens

Trigger: A worker or client sending an RpcRequest message where Target was never populated (e.g. constructed with only Method and Arguments); serialization bugs that drop the oneof/target field; invoking an agent by method name only and assuming the gateway infers the target.

Common situations: Hand-rolled RPC clients that build RpcRequest manually; protobuf schema drift between client and gateway where Target moved or was renamed; agents sending requests during shutdown with partially initialized messages.

Related errors


AI-assisted analysis of microsoft/autogen@027ecf0a37 (2026-08-15). Data as JSON: /api/errors/7a0ecbedab5f1f7a. Report an issue: GitHub.