Skip to content

automatic function calling fails on lambda generated tools #293

Closed

Description

@mikebz

Describe the bug
I am trying to dynamically generate tools for a Kubernetes agent based on the Kubernetes python client. When using the agent in the adk dev UI I get an error.

To Reproduce
Steps to reproduce the behavior:

  1. Install latest version of adk (as of today)
  2. Run 'adk web`
  3. Ask 'list namespaces on my cluster`
  4. See error
2025-04-19 11:07:11,906 - ERROR - fast_api.py:637 - Error in event_generator: Failed to parse the parameter namespace: 'str' of function namespaced_lister for automatic function calling. Automatic function calling works best with simpler function signature schema,consider manually parse your function declaration for function namespaced_lister.
Traceback (most recent call last):
  File "/Users/mikebz/src/adk-kube/.venv/lib/python3.11/site-packages/google/adk/cli/fast_api.py", line 626, in event_generator
    async for event in runner.run_async(
  File "/Users/mikebz/src/adk-kube/.venv/lib/python3.11/site-packages/google/adk/runners.py", line 197, in run_async
    async for event in invocation_context.agent.run_async(invocation_context):
  File "/Users/mikebz/src/adk-kube/.venv/lib/python3.11/site-packages/google/adk/agents/base_agent.py", line 141, in run_async
    async for event in self._run_async_impl(ctx):
  File "/Users/mikebz/src/adk-kube/.venv/lib/python3.11/site-packages/google/adk/agents/llm_agent.py", line 232, in _run_async_impl
    async for event in self._llm_flow.run_async(ctx):
  File "/Users/mikebz/src/adk-kube/.venv/lib/python3.11/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 231, in run_async
    async for event in self._run_one_step_async(invocation_context):
  File "/Users/mikebz/src/adk-kube/.venv/lib/python3.11/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 245, in _run_one_step_async
    async for event in self._preprocess_async(invocation_context, llm_request):
  File "/Users/mikebz/src/adk-kube/.venv/lib/python3.11/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 283, in _preprocess_async
    await tool.process_llm_request(
  File "/Users/mikebz/src/adk-kube/.venv/lib/python3.11/site-packages/google/adk/tools/base_tool.py", line 96, in process_llm_request
    if (function_declaration := self._get_declaration()) is None:
                                ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mikebz/src/adk-kube/.venv/lib/python3.11/site-packages/google/adk/tools/function_tool.py", line 42, in _get_declaration
    build_function_declaration(
  File "/Users/mikebz/src/adk-kube/.venv/lib/python3.11/site-packages/google/adk/tools/_automatic_function_calling_util.py", line 232, in build_function_declaration
    from_function_with_options(func, variant)
  File "/Users/mikebz/src/adk-kube/.venv/lib/python3.11/site-packages/google/adk/tools/_automatic_function_calling_util.py", line 309, in from_function_with_options
    schema = function_parameter_parse_util._parse_schema_from_parameter(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/mikebz/src/adk-kube/.venv/lib/python3.11/site-packages/google/adk/tools/function_parameter_parse_util.py", line 292, in _parse_schema_from_parameter
    raise ValueError(
ValueError: Failed to parse the parameter namespace: 'str' of function namespaced_lister for automatic function calling. Automatic function calling works best with simpler function signature schema,consider manually parse your function declaration for function namespaced_lister.

Expected behavior
Call happens to my cluster.

Desktop (please complete the following information):

  • OS: MacOS
  • Python version(python -V): Python 3.11.9
  • ADK version(pip show google-adk):
Name: google-adk
Version: 0.2.0
Location: /Users/mikebz/src/adk-kube/.venv/lib/python3.11/site-packages
Requires: authlib, click, fastapi, google-api-python-client, google-cloud-aiplatform, google-cloud-secret-manager, google-cloud-speech, google-cloud-storage, google-genai, graphviz, mcp, opentelemetry-api, opentelemetry-exporter-gcp-trace, opentelemetry-sdk, pydantic, python-dotenv, pyyaml, sqlalchemy, tzlocal, uvicorn
Required-by:

Additional context
Add any other context about the problem here.

Tools are generated like this:

def namespaced_lister_tool(method_name: str) -> Callable[[str], dict]:
    """
    Create a namespaced lister function for a specific Kubernetes resource.

    Args:
        name: The method name to call on the CoreV1Api client.

    Returns:
        An async function that lists the specified resource in a namespace.
    """
    async def namespaced_lister(namespace: str) -> dict:
        """List the specified Kubernetes resource in a namespace.
        Args:
            namespace (str): The namespace to list the resource in.
        Returns:
            A list of resource names.
        """
        v1 = client.CoreV1Api()
        method = getattr(v1, method_name)
        items = method(namespace)
        result = [item.metadata.name for item in items.items]
        return {
            "status": "success",
            "names": result,
        }

    return namespaced_lister

Agent is declared like this:

from google.adk.agents import Agent
import kube as k8s

root_agent = Agent(
    name="kubernetes_agent",
    model="gemini-2.0-flash",
    description=(
        "Agent that can interact with Kubernetes clusters"
    ),
    instruction=(
        "You are a Kubernetes agent. You can interact with Kubernetes "
        "clusters, answer questions about Kubernetes, and provide information "
        "about Kubernetes resources. You can also provide information about "
        "the Kubernetes API and how to use it. You can also provide "
        "information about the Kubernetes CLI and how to use it."
    ),
    tools=k8s.all_tools()
)

Activity

  1. hangfei commented on Apr 28, 2025

    @hangfei
    Collaborator

    Function calling(or tools) only supports dict of primitive types as return value so that models can understand.

    You should convert that into a string or dict for models to understand.

  2. mikebz commented on Apr 28, 2025

    @mikebz
    Author

    @hangfei thank you! This is the function declaration, is the issue that there can be nested dictionaries?

    async def namespaced_lister(namespace: str) -> dict:
    
  3. added
    core
    on Apr 28, 2025
  4. added theissue type on Apr 28, 2025
  5. Ahaskar04 commented on May 14, 2025

    @Ahaskar04

    Hey, I ran into this exact error too, but not with a lambda function.

    In my case, the issue was caused by:

    from __future__ import annotations

    This defers evaluation of type hints (e.g. expression: str becomes 'str' at runtime), which causes ADK’s function parser to choke with the same exact error:

    Failed to parse the parameter expression: 'str' of function ...
    Once I removed that line, the automatic function calling worked perfectly.

    Key points:

    • My function was perfectly valid (expression: str, precision: int = 3) — no lambdas, no nesting.
    • The ADK error message was misleading — it looked like my types were wrong, but the real problem was Python’s delayed annotations.
    • This isn’t documented anywhere in ADK yet, and it took hours to debug.
  6. KaRtHiK-56 commented on May 21, 2025

    @KaRtHiK-56

    i was experimenting to use functional tools using my custom python function to test google ADK, i know we can use google_search tool to get weather too, but to test custom function as tool , i want to know on this
    Ran into this error:

    {"error": "Failed to parse the parameter city of function weather_teller for automatic function calling. Automatic function calling works best with simpler function signature schema, consider manually parsing your function declaration for function weather_teller."}

    import requests
    from dotenv import load_dotenv
    import os
    from typing import Dict
    
    load_dotenv()
    
    api_key = os.getenv("WEATHER_API_KEY")
    print("api_key",api_key)
    
    async def weather_teller(city: str) -> Dict[str, str]:
        complete_url = f"https://api.openweathermap.org/data/2.5/weather?q={city}&appid={api_key}"
        
        response = requests.get(complete_url)
        
        if response.status_code == 200:
            data = response.json()
            temperature = round(data['main']['temp'] - 273.15, 2)
            place = data["name"]
            weather_desc = data['weather'][0]['main']
            return {
                "temperature": f"{temperature}°C",
                "place": place,
                "weather": weather_desc
            }
        else:
            return {
                "temperature": "N/A",
                "place": city,
                "weather": f"Error: {response.status_code}"
            }
    from google.adk.agents import Agent
    from weather_tool_agent.tools.weather import weather_teller
    from google.adk.tools import FunctionTool
    
    weather_tool = FunctionTool(weather_teller)
    
    
    root_agent = Agent(
        name = "weather_search_agent",
        description = "weather search Agent",
        model = "gemini-2.5-flash-preview-05-20",
        instruction = """
        you are a helpful assistant named "weathorology" who can tell about current and weather forecasts to any geographic locations,
        if user asks about you greet user with your name and your functionality.
        identify the location/city name from user query and pass that to weather_tool
        If user ask anything apart from this, politely say that this is out of scope from your nature.
        you have access for the following tool : 
        - weather_tool
        """,
        tools = [weather_tool])
  7. wuliang229 commented on May 28, 2025

    @wuliang229
    Collaborator

    @KaRtHiK-56 I couldn't reproduce your issue with the exact same code using the latest ADK version. I could see the error only if I add from __future__ import annotations like the other users mentioned.

  8. wuliang229 commented on May 28, 2025

    @wuliang229
    Collaborator

    @mikebz I tried copying your code structure with how the tool is defined, but I couldn't reproduce. Did you happen to use from __future__ import annotations in your code too?

  9. added this to the FixIt Week milestone on May 29, 2025
  10. wuliang229 commented on May 29, 2025

    @wuliang229
    Collaborator

    This commit should fix this issue. Please re-open if you see this issue again.

  11. psbanka commented on Aug 12, 2025

    @psbanka

    I'm still seeing this problem as of ADK version 1.10.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

core

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions