---
title: "Designing Reusable Toolsets: Packaging ADK Tools as Standalone Python Packages"
date: "2026-11-29T08:55:10+07:00"
description: "How to package, version, and distribute reusable Google ADK tools as standalone Python libraries using pyproject.toml, hatchling, and clean Toolset interfaces."
author: "AI Assistant"
image: "https://blog.redlinesoft.net/images/post/adk-reusable-toolsets-packaging-python-packages.jpg"
alt: "Designing Reusable Google ADK Toolsets as Python Packages"
tags: ['google-adk', 'python', 'packaging', 'tools', 'architecture']
---

As organizations scale their AI initiatives, engineering teams often reinvent the wheel: one team writes a tool to query the corporate Snowflake warehouse, another team rewrites the same logic for GitHub issues, and a third team creates another Slack notifier.

Copy-pasting tool code across multiple agent repositories creates maintenance nightmares, divergence in security controls, and duplicated testing efforts.

The solution is to design **reusable toolsets** and package them as standard Python libraries distributed via an internal PyPI registry or Git submodules. In this tutorial, we will design, structure, and package an enterprise-ready ADK toolset using modern Python packaging standards (`pyproject.toml` and `hatchling`).

---

## 1. Architecture of a Modular Toolset

A well-architected ADK toolset library should satisfy four principles:

1. **Self-Contained Dependencies:** Declares its own HTTP, database, or SDK dependencies independently of the host agent application.
2. **Standard Registration Interface:** Provides an exported `Toolset` class or factory function that returns callable functions ready for `Agent(tools=[...])`.
3. **Environment & Configuration Isolation:** Accepts configuration options explicitly (or from standardized environment variables) rather than assuming global config files exist.
4. **Typed Pydantic Schemas:** Ships comprehensive input and output Pydantic models with type stubs (`py.typed`).

```
adk-tools-crm/
├── pyproject.toml               # Modern build configuration (PEP 621)
├── README.md                    # Tool documentation and schema guide
├── src/
│   └── adk_tools_crm/
│       ├── __init__.py          # Exports CRMToolset, tools, schemas
│       ├── py.typed             # PEP 561 marker for mypy type checking
│       ├── client.py            # Underlying REST/gRPC client
│       ├── schemas.py           # Pydantic input models
│       └── tools.py             # ADK callable tool functions
└── tests/
    ├── test_schemas.py
    └── test_tools.py
```

---

## 2. Defining the Toolset Interface

Inside `src/adk_tools_crm/schemas.py`:

```python
from pydantic import BaseModel, Field
from typing import Optional, List

class ContactLookupInput(BaseModel):
    email: str = Field(description="The customer's email address to query in the CRM.")

class CreateLeadInput(BaseModel):
    name: str = Field(description="Full name of the prospective lead.")
    company: str = Field(description="Company or organization name.")
    email: str = Field(description="Business contact email address.")
    notes: Optional[str] = Field(default="", description="Initial qualification notes.")
```

Inside `src/adk_tools_crm/tools.py`:

```python
from typing import Dict, Any, Callable, List
from .schemas import ContactLookupInput, CreateLeadInput
from .client import CRMClient

class CRMToolset:
    """Configurable toolset exposing CRM operations for Google ADK agents."""

    def __init__(self, api_key: str, base_url: str = "https://api.crm.example.com"):
        self.client = CRMClient(api_key=api_key, base_url=base_url)

    def lookup_contact(self, input_data: ContactLookupInput) -> Dict[str, Any]:
        """Queries customer profile, deal history, and support tier from CRM."""
        return self.client.get_contact_by_email(input_data.email)

    def create_sales_lead(self, input_data: CreateLeadInput) -> Dict[str, Any]:
        """Creates a new sales lead record in the CRM pipeline."""
        return self.client.insert_lead(
            name=input_data.name,
            company=input_data.company,
            email=input_data.email,
            notes=input_data.notes
        )

    def get_tools(self) -> List[Callable]:
        """Returns all tools ready to pass into an ADK Agent."""
        return [self.lookup_contact, self.create_sales_lead]
```

Inside `src/adk_tools_crm/__init__.py`:

```python
"""Google ADK CRM Toolset Package."""

from .tools import CRMToolset
from .schemas import ContactLookupInput, CreateLeadInput

__version__ = "0.1.0"
__all__ = ["CRMToolset", "ContactLookupInput", "CreateLeadInput"]
```

---

## 3. Configuring `pyproject.toml`

Using `hatchling` as the build backend ensures fast, PEP 621-compliant builds:

```toml
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "adk-tools-crm"
version = "0.1.0"
description = "Reusable Google ADK tools for enterprise CRM integration"
readme = "README.md"
requires-python = ">=3.11"
license = "Apache-2.0"
authors = [
    { name = "Platform AI Team", email = "ai-platform@example.com" }
]
dependencies = [
    "pydantic>=2.7.0",
    "httpx>=0.27.0",
]

[project.optional-dependencies]
dev = [
    "pytest>=8.0.0",
    "pytest-asyncio>=0.23.0",
    "mypy>=1.10.0",
    "ruff>=0.4.0",
]

[tool.hatch.build.targets.wheel]
packages = ["src/adk_tools_crm"]
```

---

## 4. Consuming the Packaged Toolset in an ADK Agent

Once packaged and published (or installed locally via `pip install -e ./adk-tools-crm`), consuming the library in any ADK project takes only four lines:

```python
import os
from google.adk.agents import Agent
from adk_tools_crm import CRMToolset

# 1. Instantiate the toolset with credentials
crm_toolset = CRMToolset(
    api_key=os.environ["CRM_API_KEY"],
    base_url="https://production.crm.internal.net"
)

# 2. Register tools with the ADK Agent
sales_support_agent = Agent(
    name="sales_support_rep",
    model="gemini-3.8-flash",
    instruction="""
    You assist the sales team in qualifying inbound leads and checking customer profiles.
    Use `lookup_contact` when researching existing customers.
    Use `create_sales_lead` when creating new prospects.
    """,
    tools=crm_toolset.get_tools(),
)
```

---

## 5. Automated Testing of Packaged Toolsets

One of the greatest benefits of standalone packaging is running automated unit tests without launching an LLM or spinning up complex agent runners:

```python
# tests/test_tools.py
from adk_tools_crm import CRMToolset, ContactLookupInput

def test_lookup_contact_schema_validation():
    toolset = CRMToolset(api_key="mock_key")
    inp = ContactLookupInput(email="alice@company.com")
    assert inp.email == "alice@company.com"

def test_get_tools_exports_list():
    toolset = CRMToolset(api_key="mock_key")
    tools = toolset.get_tools()
    assert len(tools) == 2
    assert callable(tools[0])
    assert callable(tools[1])
```

---

## 6. Best Practices for Enterprise Toolset Libraries

1. **Include Docstrings & Type Hints:** ADK generates Gemini function schemas directly from tool docstrings and parameter type annotations. Maintain high documentation standards inside tool code.
2. **Zero Global State:** Avoid module-level global clients. By initializing tools through a `Toolset` instance, different agent sessions or tenants can use distinct credentials safely.
3. **Semantic Versioning:** Treat parameter changes or signature modifications as breaking changes (bump major versions) to prevent downstream agents from failing.

**Takeaway:** Packaging your ADK tools as standalone Python libraries standardizes enterprise integrations, promotes code reuse, and enables rigorous CI/CD test automation.

## Sources
- Google ADK Documentation: https://adk.dev/
- Python Packaging User Guide: https://packaging.python.org/
- Hatch Build Tool: https://hatch.pypa.io/
