
Description
Describe the bug
When attempting to define a custom tool using google.adk.tools.FunctionTool with google-adk==1.2.1, the FunctionTool.init() constructor consistently raises TypeError regardless of the argument pattern used. This includes patterns widely believed to be correct for this version and documented methods, as well as extensive permutations of positional and keyword arguments. This issue prevents any custom tools from being successfully integrated into the LlmAgent, effectively blocking agent functionality requiring tools.
Background / Comprehensive Troubleshooting Attempts & Observations:
My journey to integrating custom tools has involved navigating several API changes and inconsistencies, ultimately leading to the current intractable TypeError with FunctionTool.init.
Initial AttributeError Issues (Resolved):
Prior to encountering the core TypeError with FunctionTool.__init__, I faced and resolved several AttributeError issues, indicating a need to align with the google-adk==1.2.1 API. These were successfully addressed by diligently updating the code to the expected patterns for the specified version.
Error 1 (Resolved by iterating generator):
AttributeError: 'generator' object has no attribute 'response'
Context: This occurred when trying to access .response directly on the object returned by runner.run(), indicating the need to iterate through the generator (events).
Error 2 (Resolved by using correct LLM instantiation):
AttributeError: type object 'LLMRegistry' has no attribute 'get_llm'. Did you mean: 'new_llm'?
Context: This occurred when attempting to instantiate the LLM via an outdated method; resolved by adopting the correct LlmAgent initialization.
Error 3 (Resolved by using direct FunctionTool instantiation/subclassing):
AttributeError: type object 'FunctionTool' has no attribute 'from_function'
Context: This occurred when attempting to create a FunctionTool using a deprecated or non-existent from_function method, which led to subsequent attempts to initialize FunctionTool's __init__ constructor directly or via super().__init__ in a subclass.
Core TypeError Issues with FunctionTool.__init__ (Unresolved & Persistent):
Despite resolving the above AttributeErrors and aligning the code to google-adk==1.2.1's expected patterns, the FunctionTool.__init__ constructor consistently fails to initialize. Below are the various TypeError messages encountered across different attempts to initialize FunctionTool, demonstrating a fundamental and highly unusual issue with its constructor's argument parsing.
When using subclassing with super().__init__(name=..., description=..., parameters=..., func=...) (most persistent and recurring error, widely believed to be the correct pattern for ADK 1.2.1):
Traceback (most recent call last):
File "C:\Users\sveda\OneDrive\Desktop\compassionate-connect-ai\crisis_response_agent.py", line XX, in <module>
crisis_response_tool = RespondToCrisisTool()
File "C:\Users\sveda\OneDrive\Desktop\compassionate-connect-ai\crisis_response_agent.py", line XX, in __init__
super().__init__(
~~~~~~~~~~~~~~~^
name=tool_schema["name"],
description=tool_schema["description"],
parameters=tool_schema["parameters"],
func=self.run
)
TypeError: FunctionTool.__init__() got an unexpected keyword argument 'name'
(This error also appeared when trying to pass name, description, parameters directly as keyword arguments to FunctionTool without subclassing.)
When attempting FunctionTool(func=..., function_spec=...):
Traceback (most recent call last):
File "C:\Users\sveda\OneDrive\Desktop\compassionate-connect-ai\crisis_response_agent.py", line XX, in <module>
crisis_response_tool = FunctionTool(
^^^^^^^^^^^^^
func=respond_to_crisis,
function_spec=types.FunctionDeclaration(**tool_schema)
)
TypeError: FunctionTool.__init__() got an unexpected keyword argument 'function_spec'
When attempting FunctionTool(func=..., tool=...):
Traceback (most recent call last):
File "C:\Users\sveda\OneDrive\Desktop\compassionate-connect-ai\crisis_response_agent.py", line XX, in <module>
crisis_response_tool = FunctionTool(
^^^^^^^^^^^^^
TypeError: FunctionTool.__init__() got an unexpected keyword argument 'tool'
When attempting FunctionTool(func=..., function_declaration=...):
Traceback (most recent call last):
File "C:\Users\sveda\OneDrive\Desktop\compassionate-connect-ai\crisis_response_agent.py", line XX, in <module>
crisis_response_tool = FunctionTool(
^^^^^^^^^^^^^
TypeError: FunctionTool.__init__() got an unexpected keyword argument 'function_declaration'
When attempting FunctionTool(func, name_string, description_string, parameters_dict) (4 positional args, attempting to resolve keyword failures):
Traceback (most recent call last):
File "C:\Users\sveda\OneDrive\Desktop\compassionate-connect-ai\crisis_response_agent.py", line XX, in <module>
crisis_response_tool = FunctionTool(
^^^^^^^^^^^^^
TypeError: FunctionTool.__init__() takes 2 positional arguments but 5 were given
(Note: The 5 here was due to func + 3 dictionary items in parameters being implicitly interpreted as arguments.)
When attempting FunctionTool(func, name_string) (2 positional args, based on previous error indicating "takes 2"):
Traceback (most recent call last):
File "C:\Users\sveda\OneDrive\Desktop\compassionate-connect-ai\crisis_response_agent.py", line XX, in <module>
crisis_response_tool = FunctionTool(
^^^^^^^^^^^^^
TypeError: FunctionTool.__init__() takes 2 positional arguments but 3 were given
(Note: This indicates an unexpected third implicit positional argument, or that the error message itself is fundamentally incorrect, making direct instantiation impossible.)
To Reproduce
Steps to reproduce the behavior:
Create a fresh Python virtual environment.
Activate the virtual environment.
Install google-adk==1.2.1 and google-generativeai:
Bash
pip install google-adk==1.2.1 google-generativeai
Create a Python file (e.g., reproduce_tool_error.py) with the following content:
Python
from google.adk.tools import FunctionTool
from google.genai import types
def dummy_func(message: str) -> dict:
return {"response": "dummy"}
tool_schema = {
"name": "dummy_tool",
"description": "A dummy tool.",
"parameters": {
"type": "object",
"properties": {
"message": {"type": "string"}
},
"required": ["message"]
}
}
Attempting the most common/robust pattern for ADK 1.2.1
class MyTestTool(FunctionTool):
def init(self):
super().init(
name=tool_schema["name"],
description=tool_schema["description"],
parameters=tool_schema["parameters"],
func=dummy_func # Using dummy_func here
)
try:
test_tool = MyTestTool()
print("FunctionTool instantiated successfully!")
except TypeError as e:
print(f"Failed to instantiate FunctionTool: {e}")
# Print the full traceback for context
import traceback
traceback.print_exc()
Run the script: python reproduce_tool_error.py
Expected behavior
The FunctionTool instance should be created without errors.
Actual Behaviour
A TypeError is raised, typically TypeError: FunctionTool.init() got an unexpected keyword argument 'name', as shown in the full tracebacks above.
Screenshots
Desktop:
- OS: Windows 11
- Python version(python -V): 3.13
- ADK version(pip show google-adk): google-adk==1.2.1
Additional context
Python 3.13 Incompatibility (Hypothesis): Initially, it was hypothesized that the issue might stem from google-adk==1.2.1 incompatibility with Python 3.13 (an alpha/beta release). While testing was shifted to Python 3.11/3.12, the TypeError persists, indicating either a broader incompatibility or a different underlying problem.
Lack of Version-Locked Documentation/Examples: The rapid evolution of the API (evidenced by the initial AttributeErrors like from_function, get_llm, generator .response access) and the current TypeErrors suggest that the FunctionTool's constructor API might not be consistently documented or has undergone undocumented changes between minor versions or builds. This makes it extremely difficult to determine the correct way to instantiate the tool.
Outdated/Inconsistent Internal Builds: The highly contradictory TypeError messages (e.g., rejecting all keyword arguments, then claiming incorrect positional argument counts even when the visible code provides the exact number stated in the error message) strongly suggest an internal inconsistency or a corrupted/non-standard build of the google-adk==1.2.1 library being installed.