Utilities for building Agent Development Kit (ADK) applications
Project description
ADK Tools
A collection of utilities and patterns for building agents with Google's Agent Development Kit (ADK).
Installation
pip install adktools
Features
@adk_tooldecorator: Standardize your ADK tools with consistent error handling and response formatting- Domain error models: Create rich, domain-specific error types that automatically convert to standard responses
- Tool discovery: Automatically find all tool functions in your modules
- Response utilities: Standardized success and error response generation
- Type safety: Comprehensive typing support for better IDE integration
Quick Start
Basic Tool Creation
from adktools import adk_tool
from pydantic import BaseModel
class WeatherResult(BaseModel):
location: str
temperature: float
conditions: str
@adk_tool
def get_weather(location: str) -> WeatherResult:
"""Get current weather for a location."""
# Your implementation here
return WeatherResult(
location=location,
temperature=72.5,
conditions="Sunny"
)
Domain-Specific Error Handling
from adktools import adk_tool
from adktools.models import DomainError
from typing import Literal, Union
from pydantic import BaseModel
class TimeResult(BaseModel):
timezone: str
datetime: str
is_dst: bool
class InvalidTimezoneError(DomainError):
timezone: str
error_type: Literal["invalid_timezone"] = "invalid_timezone"
@adk_tool(
name="get_time",
description="Get the current time in a specified timezone."
)
def get_current_time(timezone: str) -> Union[TimeResult, InvalidTimezoneError]:
try:
# Implementation...
if timezone == "invalid":
return InvalidTimezoneError(
timezone=timezone,
error_message=f"Unknown timezone: {timezone}"
)
return TimeResult(
timezone=timezone,
datetime="2025-04-12T12:34:56",
is_dst=True
)
except Exception as e:
# The decorator will catch and format any exceptions
raise RuntimeError(f"Error getting time: {str(e)}")
Tool Discovery
from adktools import discover_adk_tools
from google.adk.agents import Agent
# Import your modules containing tools
import myagent.weather_tools
import myagent.time_tools
# Create an agent with auto-discovered tools
agent = Agent(
name="my_assistant",
description="A helpful assistant",
tools=discover_adk_tools(myagent.weather_tools)
)
# Or discover tools across multiple modules
all_tools = discover_adk_tools_in_modules([
myagent.weather_tools,
myagent.time_tools
])
Documentation
The @adk_tool Decorator
The decorator standardizes ADK tool responses and provides additional metadata for tools:
@adk_tool # Simple usage
def simple_tool(param: str):
# Implementation...
@adk_tool(
name="custom_name", # Override function name
description="Custom description", # Override docstring
detailed_errors=True # Include stack traces in errors
)
def custom_tool(param: str):
# Implementation...
Response Models
ADK Tools provides standardized response models:
from adktools.models import ErrorResponse, SuccessResponse, DomainError
# Success response
success = SuccessResponse(result={"key": "value"})
# Or without data
empty_success = SuccessResponse() # result is optional
# Error response
error = ErrorResponse(error_message="Something went wrong")
# Domain-specific error base class
class MyCustomError(DomainError):
error_type: Literal["custom_error"] = "custom_error"
error_message: str # Matches ErrorResponse field name
additional_field: str
Helper Functions
from adktools import success_response, error_response
# Create success response dictionary
response = success_response({"data": "value"})
# {"status": "success", "result": {"data": "value"}}
# Create success response without data
empty_response = success_response()
# {"status": "success"}
# Create error response dictionary
response = error_response("Something went wrong")
# {"status": "error", "error_message": "Something went wrong"}
Response Format
By default, ADK Tools uses the following standardized response formats:
Success Response
{
"status": "success",
"result": { ... } // Optional result data
}
Error Response
{
"status": "error",
"error_message": "Description of what went wrong"
}
This consistent response format makes it easy for agents to handle tool responses predictably.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE for more information.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file adktools-0.1.2.tar.gz.
File metadata
- Download URL: adktools-0.1.2.tar.gz
- Upload date:
- Size: 12.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
205349d1019e0d0178f29f428caff67e247999b4b14d6fd2abc76312a130f805
|
|
| MD5 |
a0e43f83f3a741cbb45f13ec89ca81ab
|
|
| BLAKE2b-256 |
7daf030dd933d439e1266e88782ce159e209da0b1540cc8d9db47e9da38ce8ec
|
File details
Details for the file adktools-0.1.2-py3-none-any.whl.
File metadata
- Download URL: adktools-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2b1adc94db24098c571eeffdfcdf4535fd47595dc47a9215c4079f8daf7e82f9
|
|
| MD5 |
cf15132bc57c92479c5c53e3fdcf3e52
|
|
| BLAKE2b-256 |
a090d96a3cf8d8c2bf4b3680de1ba78602301fabd3e6600e34c3ed7fa13786cc
|