Tooling System

The Tooling System provides a modular framework defining various tools callable by AI agents or large language models (LLMs). It enables agents to extend their capabilities by invoking specialized functionalities such as executing Go functions, loading artifacts, performing web searches, or integrating with external protocols like MCP (Model Context Protocol). This modularity allows flexible composition of AI workflows and enriches the agent's interaction with external data and services.


Core Concepts and Purpose

At its core, the Tooling System abstracts "tools" as callable units of functionality that agents or LLMs can invoke during their operation. Each tool encapsulates a specific task or interface to an external system. The framework supports diverse tool types, including:

This system solves the problem of connecting AI agents with external data, services, and sub-agents in a clean, extensible, and schema-validated manner, enabling dynamic, context-aware AI workflows.


Structure and Functionality

Tool Interface and Context

All tools implement the tool.Tool interface defining:

Tools receive a tool.Context when invoked, which provides:

Toolsets

A tool.Toolset is a collection of related tools, allowing grouping and dynamic exposure of tools based on the current invocation context.


Function Tools

Function tools wrap Go functions, providing a seamless way to expose typed functionality to agents and LLMs.

Example usage includes creating a tool that sums two integers or retrieves weather information based on city input.

The function tool implementation handles:

This pattern enables robust, schema-driven tooling with minimal boilerplate.


Artifact Loading Tool

The artifact loading tool (loadartifactstool package) allows agents and LLMs to interact with stored artifacts such as files or blobs.

Key features include:

This tool tightly integrates with the artifact service and session management, enabling agents to answer queries or perform reasoning based on persistent external data.


Google Search Tool

The geminitool package provides access to Google Search as a built-in tool for Gemini 2 models.

This tool provides external knowledge retrieval without explicit API calls in the agent code.


MCP Toolset Integration

The MCP toolset (mcptoolset package) bridges the ADK with external MCP servers, allowing agents to call MCP tools as if they were native.

This integration enables seamless extension of agent capabilities through the MCP ecosystem.


Agent Tools

Agent tools (agenttool package) wrap sub-agents as callable tools.

This composition pattern supports modular, hierarchical AI workflows.


Exit Loop Tool

The exit loop tool (exitlooptool package) provides a mechanism for agents to exit looping workflows.


Interactions and Workflow

Agents invoke tools during LLM generation cycles. The typical interaction sequence is:

  1. Tool Inclusion: Each tool registers its function declaration and capabilities into the LLM request (ProcessRequest).

  2. LLM Request: The agent sends a prompt with tool declarations to the LLM.

  3. Function Call Detection: If the LLM issues a function call (e.g., to a function tool or artifact loader), the agent calls the corresponding tool's Run method.

  4. Tool Execution: The tool performs its logic—executing native functions, loading artifacts, querying MCP servers, or invoking sub-agents.

  5. Response Handling: The tool returns results, which are appended to the conversation and used to generate further LLM responses.

  6. Loop Control: Tools like the exit loop tool can modify session actions to influence agent workflow (e.g., exit loops).

These interactions tightly couple the tooling system with the agent lifecycle, session state, artifact management, and external protocols.


File and Package Relationships

Each tool package implements the tool.Tool interface and integrates with the agent invocation context (tool.Context) and request lifecycle.


Visualization of Tool Invocation Flow

sequenceDiagram
participant Agent
participant ToolingSystem
participant LLMModel
participant ArtifactService
participant MCPServer
participant SubAgent
Agent->>ToolingSystem: Initialize LLM Request with Tools
ToolingSystem->>LLMModel: Send Request
LLMModel->>Agent: Return Response (may include Function Call)
alt Function Call Detected
Agent->>ToolingSystem: Invoke Tool.Run()
alt Function Tool
ToolingSystem->>Agent: Execute Go Function
Agent-->>ToolingSystem: Return Function Result
else Artifact Loading Tool
ToolingSystem->>ArtifactService: Load Artifact(s)
ArtifactService-->>ToolingSystem: Return Content
else MCP Tool
ToolingSystem->>MCPServer: Call MCP Tool
MCPServer-->>ToolingSystem: Return Result
else Agent Tool
ToolingSystem->>SubAgent: Run Sub-Agent Session
SubAgent-->>ToolingSystem: Return Output
end
ToolingSystem->>Agent: Return Tool Result
Agent->>LLMModel: Append Result and Continue Generation
else No Function Call
Agent->>Agent: Process Final Output
end

Summary of Subtopics

For detailed information on specific tool implementations, refer to: