{"record":{"id":"610b49ef5c3d9bc3","repo":"microsoft/semantic-kernel","slug":"function-invoke-not-found-in-plugin-this-name","errorCode":null,"errorMessage":"Function Invoke not found in plugin {this.Name}","messagePattern":"Function Invoke not found in plugin (.+?)","errorType":"exception","errorClass":"ArgumentException","httpStatus":null,"severity":"error","filePath":"dotnet/src/Experimental/Process.LocalRuntime/LocalAgentStep.cs","lineNumber":61,"sourceCode":"        Verify.NotNull(message, nameof(message));\n\n        // Lazy one-time initialization of the step before processing a message\n        await this._initializeTask.Value.ConfigureAwait(false);\n\n        string targetFunction = \"Invoke\";\n        KernelArguments arguments = new()\n        {\n            { \"message\", message.TargetEventData switch\n                {\n                    KernelProcessEventData proxyData => proxyData.ToObject(),\n                    _ => message.TargetEventData\n                }\n            },\n            { \"writtenToThread\", message.writtenToThread == this._agentThread.ThreadId }\n        };\n        if (!this._functions.TryGetValue(targetFunction, out KernelFunction? function) || function == null)\n        {\n            throw new ArgumentException($\"Function Invoke not found in plugin {this.Name}\");\n        }\n\n        object? result = null;\n\n        // Invoke the function, catching all exceptions that it may throw, and then post the appropriate event.\n#pragma warning disable CA1031 // Do not catch general exception types\n        try\n        {\n            FunctionResult invokeResult = await this.InvokeFunction(function, this._kernel, arguments).ConfigureAwait(false);\n            result = invokeResult.GetValue<object>();\n            this.EmitEvent(\n                ProcessEvent.Create(\n                    result,\n                    this._eventNamespace,\n                    sourceId: $\"{targetFunction}.OnResult\",\n                    eventVisibility: KernelProcessEventVisibility.Public,\n                    writtenToThread: this._agentThread.ThreadId)); // TODO: This is keeping track of the thread the message has been written to, clean it up, name it better, etc. \n        }","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/dotnet/src/Experimental/Process.LocalRuntime/LocalAgentStep.cs#L43-L79","documentation":"Thrown by `LocalAgentStep.HandleMessageAsync` when the agent step's plugin does not contain a kernel function named `\"Invoke\"`. The step loads functions from a `KernelProcessAgentExecutorInternal` plugin at init; if that plugin exposes no `Invoke` method (e.g. the agent executor type lacks it or it was renamed/obscured), the lookup fails and every inbound message is rejected. It is an ArgumentException.","triggerScenarios":"Use an agent whose executor internal type does not declare a `[KernelFunction] Invoke(...)` method; reflection-based plugin creation skips `Invoke` due to visibility/signature mismatch; the executor was subclassed and `Invoke` removed; version change renamed the expected function.","commonSituations":"Custom agent executor implementations that omit the `Invoke` kernel function; AOT/trimming stripping the method; signature changes where `Invoke` no longer matches the expected parameters; misuse of a non-agent step where an agent step was expected.","solutions":["Ensure the agent executor type declares a public `[KernelFunction(\"Invoke\")]` method with the expected signature (`message`, `writtenToThread`).","Confirm the executor is the SDK's `KernelProcessAgentExecutorInternal` or a compatible subclass that retains `Invoke`.","Disable trimming/AOT for the executor assembly, or annotate `Invoke` with dynamic-dependency attributes so it is preserved.","Verify `this._functions` actually contains `\"Invoke\"` after init by logging its keys in a debug build."],"exampleFix":"// before\ninternal sealed class MyAgentExecutor\n{\n    [KernelFunction]\n    public Task<string> RunAsync(string message) => ...; // wrong name\n}\n// after\ninternal sealed class MyAgentExecutor\n{\n    [KernelFunction(\"Invoke\")]\n    public Task<string> InvokeAsync(string message, bool writtenToThread) => ...;\n}","handlingStrategy":"validation","validationCode":"var executor = new KernelProcessAgentExecutorInternal(stepInfo, thread, psm);\nvar plugin = KernelPluginFactory.CreateFromObject(executor, pluginName: stepInfo.State.Name);\nif (!plugin.Any(f => f.Name == \"Invoke\"))\n    throw new InvalidOperationException($\"Agent '{stepInfo.State.Name}' plugin has no 'Invoke' kernel function; check the executor type and trimming settings.\");","typeGuard":"bool PluginHasInvoke(KernelPlugin plugin) => plugin.Any(f => string.Equals(f.Name, \"Invoke\", StringComparison.Ordinal));","tryCatchPattern":"try { await agentStep.HandleMessageAsync(message); }\ncatch (ArgumentException ex) when (ex.Message.Contains(\"Function Invoke not found\"))\n{ _logger.LogError(ex, \"Agent plugin missing Invoke; verify executor declaration.\"); throw; }","preventionTips":["Ensure the agent executor declares a public [KernelFunction(\"Invoke\")] method matching the expected signature.","In trimming/AOT scenarios, root-keep the executor's Invoke method.","Log plugin function keys at init to confirm Invoke is present."],"tags":["process-framework","local-runtime","agents","reflection","kernel-functions"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}