microsoft/autogen · error · InvalidOperationException

FunctionMap is not available

Error message

FunctionMap is not available

What it means

When FunctionCallMiddleware processes a ToolCallMessage, it resolves each requested function via its functionMap (name -> delegate). Per the shown logic: if the function exists it is invoked; else if functionMap itself is non-null it records a 'Function X is not available' error result; but if functionMap is null entirely it throws InvalidOperationException('FunctionMap is not available'). So this specific throw means the middleware instance was constructed without any function map while the agent still emitted tool calls.

Source

Thrown at dotnet/src/AutoGen.Core/Middleware/FunctionCallMiddleware.cs:159

        var toolCalls = toolCallMessage.ToolCalls;
        foreach (var toolCall in toolCalls)
        {
            var functionName = toolCall.FunctionName;
            var functionArguments = toolCall.FunctionArguments;
            if (this.functionMap?.TryGetValue(functionName, out var func) is true)
            {
                var result = await func(functionArguments);
                toolCallResult.Add(new ToolCall(functionName, functionArguments, result) { ToolCallId = toolCall.ToolCallId });
            }
            else if (this.functionMap is not null)
            {
                var errorMessage = $"Function {functionName} is not available. Available functions are: {string.Join(", ", this.functionMap.Select(f => f.Key))}";

                toolCallResult.Add(new ToolCall(functionName, functionArguments, errorMessage) { ToolCallId = toolCall.ToolCallId });
            }
            else
            {
                throw new InvalidOperationException("FunctionMap is not available");
            }
        }

        return new ToolCallResultMessage(toolCallResult, from: agent.Name);
    }

    private async Task<IMessage> InvokeToolCallMessagesAfterInvokingAgentAsync(ToolCallMessage toolCallMsg, IAgent agent)
    {
        var toolCallsReply = toolCallMsg.ToolCalls;
        var toolCallResult = new List<ToolCall>();
        foreach (var toolCall in toolCallsReply)
        {
            var fName = toolCall.FunctionName;
            var fArgs = toolCall.FunctionArguments;
            if (this.functionMap?.TryGetValue(fName, out var func) is true)
            {
                var result = await func(fArgs);
                toolCallResult.Add(new ToolCall(fName, fArgs, result) { ToolCallId = toolCall.ToolCallId });

View on GitHub (pinned to 027ecf0a37)

Solutions

  1. Pass the function map when creating the middleware, e.g. new FunctionCallMiddleware(functionMap: functions.ToDictionary(f => f.Name, f => f.InvokeAsync)).
  2. Ensure the FunctionExecutor(s) whose schema you advertised to the LLM are the same ones wired into the middleware.
  3. If you intentionally never execute tools, remove tool schemas from the agent's config so the model does not emit tool calls.
  4. As a safety net, construct with an empty map so unavailable functions degrade to error ToolCall results instead of throwing.

Example fix

// before
var middleware = new FunctionCallMiddleware(); // no functionMap
// model returns ToolCallMessage -> InvalidOperationException

// after
var functionMap = functionExecutors.ToDictionary(f => f.Name, f => f.InvokeAsync);
var middleware = new FunctionCallMiddleware(functionMap: functionMap);
Defensive patterns

Strategy: validation

Validate before calling

if (functionMap is null || functionMap.Count == 0)
    throw new ConfigurationException("FunctionCallMiddleware needs a functionMap before the agent can emit tool calls");
var middleware = new FunctionCallMiddleware(functionMap: functionMap);

Try / catch

try { var reply = await agent.SendAsync(msg); }
catch (InvalidOperationException ex) when (ex.Message.Contains("FunctionMap is not available"))
{
    // rebuild the agent with FunctionCallMiddleware(functionMap: map) and retry
}

Prevention

When it happens

Trigger: Constructing FunctionCallMiddleware with no functionMap (or an empty constructor path that leaves it null) and the LLM returns a ToolCallMessage; registering FunctionCallMiddleware only for its print/pre-processing side while the model has tools in its schema; a model hallucinating a tool call even though no functions were registered.

Common situations: Agent config advertises function schemas but the middleware was never given the corresponding FunctionExecutors/delegates; middleware ordering mistakes where a bare FunctionCallMiddleware intercepts tool calls meant for another handler; strong models calling tools that were removed between runs.

Related errors


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