You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Builtin tools that have tool_context as a parameter don't get a description from the doc-string #551
Describe the bug
If you add a built-in tool (python function) to your agent and that tool contains one of the 'ignored parameters', such as tool_context, in its parameters, the ADK will rebuild that function without that parameter. When it does this, it neglects to copy the doc attribute to the new function. Then when the tool declaration is built for the LLM API call, its description is empty. This is particularly bad if you are calling an Anthropic model on Bedrock because it demands a description.
To Reproduce
Steps to reproduce the behavior:
Create a very basic agent with a single 'python' tool type
Create a python function that has a 'tool_context' parameter
Run an inference and look at the tool list that is sent to the LLM (your tool will have 'description: ""'
Expected behavior
The tool list will contain a description for each tool
Desktop (please complete the following information):
OS: [e.g. iOS]
Python version(python -V): 3.11.10
ADK version(pip show google-adk): 0.4.0
Possible Fix
def build_function_declaration(
func: Union[Callable, BaseModel],
ignore_params: Optional[list[str]] = None,
variant: Literal['GOOGLE_AI', 'VERTEX_AI', 'DEFAULT'] = 'GOOGLE_AI',
) -> types.FunctionDeclaration:
signature = inspect.signature(func)
new_func = None
if not ignore_params:
ignore_params = []
for name, _ in signature.parameters.items():
if name in ignore_params:
should_update_signature = True
break
if should_update_signature:
new_params = [
param
for name, param in signature.parameters.items()
if name not in ignore_params
]
if isinstance(func, type):
fields = {
name: (param.annotation, param.default)
for name, param in signature.parameters.items()
if name not in ignore_params
}
new_func = create_model(func.__name__, **fields)
else:
new_sig = signature.replace(parameters=new_params)
new_func = FunctionType(
func.__code__,
func.__globals__,
func.__name__,
func.__defaults__,
func.__closure__,
)
new_func.__signature__ = new_sig
# FIX
new_func.__doc__ = func.__doc__
return (
from_function_with_options(func, variant)
if not should_update_signature
else from_function_with_options(new_func, variant)
)
@hangfei - just curious about an update for this and whether you need more from me. I keep having to repatch the ADK library to allow Sonnet models to work. Also, even Gemini models suffer in that the description of the tool is not included. The model does an okay job of guessing at the purpose based on the function and parameter names, but it still is a large limitation to lose the description of the tool
I just want to raise the priority of this issue. This prevents the use of functions requiring tool_context to work with Anthropic models and silently makes the performance worse for Gemini ones. The system performs much better with this very small fix in place.
Activity
efunneko commentedon May 4, 2025
PR submitted: #552
efunneko commentedon May 22, 2025
@hangfei - just curious about an update for this and whether you need more from me. I keep having to repatch the ADK library to allow Sonnet models to work. Also, even Gemini models suffer in that the description of the tool is not included. The model does an okay job of guessing at the purpose based on the function and parameter names, but it still is a large limitation to lose the description of the tool
efunneko commentedon May 24, 2025
I just want to raise the priority of this issue. This prevents the use of functions requiring tool_context to work with Anthropic models and silently makes the performance worse for Gemini ones. The system performs much better with this very small fix in place.
seanzhou1023 commentedon May 31, 2025
fixed in 7fdc6b4