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

    Class APIHubToolset

    Builds one tool per operation of an API registered in API Hub.

    The toolset fetches an OpenAPI spec from API Hub, parses it as YAML or JSON, and hands it to an OpenAPIToolset, which produces a RestApiTool for each operation.

    const toolset = new APIHubToolset({
    apihubResourceName:
    'projects/my-project/locations/us-central1/apis/my-api',
    });
    const agent = new LlmAgent({
    name: 'api_agent',
    model: 'gemini-flash-latest',
    tools: [toolset],
    });

    By default the spec is fetched when the toolset is constructed. A constructor cannot wait for the request, so a failure is reported by the first call to getTools or getTool, and every later call reports the same failure.

    With lazyLoadSpec, the spec is fetched on the first call to getTools or getTool. A successful result is kept, including a spec that produced no tools. A failed fetch is not kept, so the next call fetches again.

    Hierarchy (View Summary)

    "[BASE_TOOLSET_SIGNATURE_SYMBOL]": true
    apihubResourceName: string
    description: string

    The toolset description, filled in from the spec when empty.

    lazyLoadSpec: boolean
    name: string

    The toolset name, filled in from the spec when empty.

    prefix?: string
    toolFilter: string[] | ToolPredicate
    • Closes the toolset.

      NOTE: This method is invoked, for example, at the end of an agent server's lifecycle or when the toolset is no longer needed. Implementations should ensure that any open connections, files, or other managed resources are properly released to prevent leaks.

      Returns Promise<void>

      A Promise that resolves when the toolset is closed.

    • Returns the tool with the given name, or undefined when the spec produced no such tool.

      Unlike OpenAPIToolset.getTool, the result is a Promise, because the spec may still be loading.

      Parameters

      • name: string

        The tool name, which is the operation ID in snake_case.

      Returns Promise<RestApiTool | undefined>

      When the spec cannot be fetched or is not valid YAML or JSON.

    • Processes the outgoing LLM request for this toolset. This method will be called before each tool processes the llm request.

      Use cases:

      • Instead of let each tool process the llm request, we can let the toolset process the llm request. e.g. ComputerUseToolset can add computer use tool to the llm request.

      Parameters

      • _toolContext: Context

        The context of the tool.

      • _llmRequest: LlmRequest

        The outgoing LLM request, mutable this method.

      Returns Promise<void>