| Nested pattern | Class in AnimalAI.Plugins.NestedKernel.SK, internal kernel built in private method, Lazy-init | Class declaration, CreateInternalKernel, AddPlugins |
| IDisposable | Class declares IDisposable; Dispose() disposes _serviceProvider; comment that Kernel is not disposed | Class declaration, #region Dispose |
| IInternalCallTracker | Class declares IInternalCallTracker; has TrackInternalCall and GetAndClearInternalCalls; thread-safe with lock | Class declaration, #region Internal Call Tracking |
| Tracking fields | List<InternalFunctionCall> _internalCalls and object _internalCallsLock; lock used in both interface methods | #region Tracking Fields |
| InternalFunctionCallTracker | After builder.Build(), kernel.AutoFunctionInvocationFilters.Add(new InternalFunctionCallTracker(this, loggerFactory)) | End of CreateInternalKernel() |
| ChatHistory parameter | Main [KernelFunction] method has ChatHistory? ChatHistory = null (or same name used by KernelConstants.ChatHistoryArgumentKey); comment that it is injected via filter | Kernel function signature |
| Logger usage | ILoggerFactory?, ILogger<NestedXPlugin>? _logger; _logger?.LogInformation for function call/result, _logger?.LogError in catch | Constructor, kernel function |
| Lazy<Kernel> | Lazy<Kernel> _internalKernel; created in constructor as new Lazy<Kernel>(() => CreateInternalKernel()); never built in ctor | #region Kernel Fields, constructor |
| Error handling | try/catch around kernel invocation; on exception, log and return a string (e.g. $"Error calling SubKernel: {ex.Message}") | Kernel function body |
| Description attributes | [Description("...")] on the kernel function; describes when to use and what it does; [return: Description("...")] and param descriptions | Above kernel function and parameters |
| Regions | Logical regions used: Kernel Fields, Logger Fields, Tracking Fields, Other Fields, Constructors, AddPlugins, Kernel Functions, Internal Call Tracking, Dispose | File structure |
| Registration | In StandardKernel.AddNestedKernelPlugins: instance created, AddFromObject(instance, "AgentName"), _pluginInstances["AgentName"] = instance, _disposablePlugins.Add(instance) | StandardKernel.cs |
| Test coverage | At least one test with ExpectedToolsToCall containing "AgentName.MethodName"; ideally error and context tests | TestCaseDefinitions.cs |