ADK for TypeScript: API Reference
    Preparing search index...

    Class PluginManager

    Manages the registration and execution of plugins.

    The PluginManager is an internal class that orchestrates the invocation of plugin callbacks at key points in the SDK's execution lifecycle. It maintains a list of registered plugins and ensures they are called in the order they were registered.

    The core execution logic implements an "early exit" strategy: if any plugin callback returns a non-undefined value, the execution of subsequent plugins for that specific event is halted, and the returned value is propagated up the call stack. This allows plugins to short-circuit operations like agent runs, tool calls, or model requests.

    Constructors

    Methods

    • Retrieves a registered plugin by its name.

      Parameters

      • pluginName: string

        The name of the plugin to retrieve.

      Returns BasePlugin | undefined

      The plugin instance if found, otherwise undefined.

    • Registers a new plugin.

      Parameters

      • plugin: BasePlugin

        The plugin instance to register.

      Returns void

      If the same exact plugin or a plugin with the same name is already registered.

    • Runs the afterAgentCallback for all plugins.

      Parameters

      Returns Promise<Content | undefined>

    • Runs the afterToolCallback for all plugins.

      Parameters

      • __namedParameters: {
            result: Record<string, unknown>;
            tool: BaseTool;
            toolArgs: Record<string, unknown>;
            toolContext: Context;
        }

      Returns Promise<Record<string, unknown> | undefined>

    • Runs the beforeAgentCallback for all plugins.

      Parameters

      Returns Promise<Content | undefined>

    • Runs the beforeToolCallback for all plugins.

      Parameters

      • __namedParameters: { tool: BaseTool; toolArgs: Record<string, unknown>; toolContext: Context }

      Returns Promise<Record<string, unknown> | undefined>

    • Runs the onModelErrorCallback for all plugins.

      Parameters

      • __namedParameters: { callbackContext: Context; error: Error; llmRequest: LlmRequest }

      Returns Promise<LlmResponse | undefined>

    • Runs the onToolErrorCallback for all plugins.

      Parameters

      • __namedParameters: {
            error: Error;
            tool: BaseTool;
            toolArgs: Record<string, unknown>;
            toolContext: Context;
        }

      Returns Promise<Record<string, unknown> | undefined>

    • Runs the onUserMessageCallback for all plugins.

      Parameters

      Returns Promise<Content | undefined>