adk-python icon indicating copy to clipboard operation
adk-python copied to clipboard

opentelemetry ValueError: "Token was created in a different Context" with ParallelAgent and LlmAgent

Open divanshu-goyal-rc opened this issue 1 year ago • 27 comments

When using google.adk.agents.ParallelAgent with multiple google.adk.agents.LlmAgent instances as sub-agents, ValueError exceptions from the opentelemetry.context module are consistently logged. These errors occur after each sub-agent completes its processing. While the core functionality of the agents (e.g., LLM calls and output generation) appears to be unaffected, these errors create noise in the logs and suggest a potential issue with context management within the ADK framework or its interaction with opentelemetry.

Steps to Reproduce:

  1. Define multiple LlmAgent instances, each with its own model, instructions, and output schema.
  2. Define an AsyncExitStack and initialize tools (e.g., MCPToolset).
  3. Instantiate a ParallelAgent, providing the LlmAgent instances to its sub_agents parameter.
  4. The root agent setup returns the ParallelAgent instance and the AsyncExitStack.
  5. Run the agent (e.g., by making a request to the FastAPI endpoint if using google.adk.cli.fast_api).

Expected Behavior: The ParallelAgent and its sub-agents should execute without opentelemetry context errors being logged.

Actual Behavior: After each sub-agent finishes its execution and its output is generated, the following type of error is logged multiple times:

ERROR - __init__.py:157 - Failed to detach context
Traceback (most recent call last):
  File "/path/to/your/env/lib/pythonX.Y/site-packages/opentelemetry/context/__init__.py", line 155, in detach
    _RUNTIME_CONTEXT.detach(token)
  File "/path/to/your/env/lib/pythonX.Y/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach
    self._current_context.reset(token)
ValueError: <Token var=<ContextVar name='current_context' default={} at 0xXXXXXXXXX> at 0xYYYYYYYYY> was created in a different Context

(Note: Replace /path/to/your/env/lib/pythonX.Y/ and memory addresses with actuals from your logs if desired)

Environment:

  • Operating System: macOS (darwin 23.5.0)
  • Python Version: 3.12
  • Google ADK Version: 0.4.0
  • Minimal Reproducible Code (agent.py):
    import asyncio
    from google.adk.agents import LlmAgent, BaseAgent, ParallelAgent
    from pydantic import BaseModel, Field
    from google.adk.tools.mcp_tool.mcp_toolset import MCPToolset, SseServerParams
    from contextlib import AsyncExitStack
    import enum
    
    # ... (Out_of_office_category, Out_of_office_output_schema definitions) ...
    # ... (New_lead_category, New_lead_output_schema definitions) ...
    # ... (Book_meeting_category, Book_meeting_output_schema definitions) ...
    # ... (General_type_reply_category, General_type_reply_output_schema definitions) ...
    
    # [PASTE YOUR Enum and BaseModel Schema definitions here for completeness]
    
    class Out_of_office_category(enum.Enum):
        resignation = "resignation"
        holiday = "holiday"
        other = "other"
        not_out_of_office = "not_out_of_office"
    
    class Out_of_office_output_schema(BaseModel):
        out_of_office: bool = Field(description="Whether the email is out of office or not")
        category: Out_of_office_category = Field(description="The category of the email")
        reason: str = Field(description="The reason for the email being out of office")
    
    class New_lead_category(enum.Enum):
        not_right_person_add_new_lead_new_email = "not_right_person_add_new_lead_new_email"
        right_person_add_new_lead_new_email = "right_person_add_new_lead_new_email"
        right_person_add_new_lead_existing_email = "right_person_add_new_lead_existing_email"
        not_add_new_lead = "not_add_new_lead"
    
    class New_lead_output_schema(BaseModel):
        new_lead: bool = Field(description="Whether the email contains a new lead or not")
        new_lead_category: New_lead_category = Field(description="The category of the email")
        reason: str = Field(description="The reason for the email being a new lead or not")
    
    class Book_meeting_category(enum.Enum):
        book_meeting = "book_meeting"
        book_meeting_details = "book_meeting_details"
        not_book_meeting = "not_book_meeting"
    
    class Book_meeting_output_schema(BaseModel):
        book_meeting: bool = Field(description="Whether the email contains a request to book a meeting or not")
        book_meeting_category: Book_meeting_category = Field(description="The category of the email")
        reason: str = Field(description="The reason for the email being a book meeting or not")
    
    class General_type_reply_category(enum.Enum):
        positive = "positive"
        negative = "negative"
    
    class General_type_reply_output_schema(BaseModel):
        general_type_reply_category: General_type_reply_category = Field(description="The category of the email")
        reason: str = Field(description="The reason for the email being a positive or negative reply")
    
    
    async def reply_agent():
        common_exit_stack = AsyncExitStack()
        tools, _ = await MCPToolset.from_server(
            connection_params=SseServerParams(
              url="http://44.214.120.160:8002/sse" # Example URL
          ),
          async_exit_stack=common_exit_stack
        )
    
        out_of_office_agent = LlmAgent(
                model="gemini-2.0-flash",
                name="out_of_office_agent",
                description="check whether the email is out of office or not...",
                instruction=\"\"\"...\"\"\", # Shorten for brevity or refer to full agent code
                output_schema=Out_of_office_output_schema,
                output_key="out_of_office_agent"
            )
    
        new_lead_agent = LlmAgent(
            model="gemini-2.0-flash",
            name="new_lead_agent",
            description="Check whether the email contains a new lead...",
            instruction=\"\"\"...\"\"\",
            output_schema=New_lead_output_schema,
            output_key="new_lead_agent"
        )
    
        book_meeting_agent = LlmAgent(
            model="gemini-2.0-flash",
            name="book_meeting_agent",
            description="Check whether the email contains a request to book a meeting...",
            instruction=\"\"\"...\"\"\",
            output_schema=Book_meeting_output_schema,
            output_key="book_meeting_agent"
        )
    
        general_type_reply_agent = LlmAgent(
            model="gemini-2.0-flash",
            name="general_type_reply_agent",
            description="Classify the email into 'positive', 'negative'...",
            instruction=\"\"\"...\"\"\",
            output_schema=General_type_reply_output_schema,
            output_key="general_type_reply_agent"
        )
    
        return out_of_office_agent, new_lead_agent, book_meeting_agent, general_type_reply_agent, common_exit_stack
    
    
    async def main():
        out_of_office_agent, new_lead_agent, book_meeting_agent, general_type_reply_agent, common_exit_stack = await reply_agent()
        reply_intent_agent = ParallelAgent(
                name="replyagent",
                description="Analyze the email and determine the intent of the email.",
                sub_agents=[out_of_office_agent, new_lead_agent, book_meeting_agent, general_type_reply_agent]
            )
        return reply_intent_agent, common_exit_stack
    
    root_agent = main()
    

Additional Context:

  • The sub-agents themselves successfully process inputs and produce the expected outputs via LLM calls. The opentelemetry errors seem to occur around the completion/logging phase of each sub-agent's lifecycle within the ParallelAgent.

divanshu-goyal-rc avatar May 22 '25 07:05 divanshu-goyal-rc

Disclaimer: not googler.

We have seen this, and it seems to be caused by another error, and the trace error is masking the underlying error.

calvingiles avatar May 23 '25 06:05 calvingiles

similar issue reproduced on my local, it would be great if we could fix this issue.

Colstuwjx avatar May 26 '25 10:05 Colstuwjx

Could you retry with 1.0.0. I think we've fixed this already at head.

Jacksunwei avatar May 28 '25 07:05 Jacksunwei

Hi @Jacksunwei , unfortuantely, I had just reproduced this issue by using 1.0.0 . See the error logs below:

Error in event_generator: 403 PERMISSION_DENIED. {'error': {'code': 403, 'message': 'Permission denied on resource project XXX.', 'status': 'PERMISSION_DENIED', 'details': [{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'CONSUMER_INVALID', 'domain': 'googleapis.com', 'metadata': {'containerInfo': 'XXX', 'consumer': 'projects/XXX', 'service': 'aiplatform.googleapis.com'}}, {'@type': 'type.googleapis.com/google.rpc.LocalizedMessage', 'locale': 'en-US', 'message': 'Permission denied on resource project XXX.'}, {'@type': 'type.googleapis.com/google.rpc.Help', 'links': [{'description': 'Google developers console', 'url': 'https://console.developers.google.com'}]}]}}
Traceback (most recent call last):
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/cli/fast_api.py", line 697, in event_generator
    async for event in runner.run_async(
    ...<8 lines>...
      yield f"data: {sse_event}\n\n"
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/runners.py", line 197, in run_async
    async for event in invocation_context.agent.run_async(invocation_context):
    ...<2 lines>...
      yield event
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/agents/base_agent.py", line 147, in run_async
    async for event in self._run_async_impl(ctx):
      yield event
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/agents/llm_agent.py", line 278, in _run_async_impl
    async for event in self._llm_flow.run_async(ctx):
      self.__maybe_save_output_to_state(event)
      yield event
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 279, in run_async
    async for event in self._run_one_step_async(invocation_context):
      last_event = event
      yield event
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 309, in _run_one_step_async
    async for event in self._postprocess_async(
    ...<4 lines>...
      yield event
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 381, in _postprocess_async
    async for event in self._postprocess_handle_function_calls_async(
    ...<2 lines>...
      yield event
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 471, in _postprocess_handle_function_calls_async
    async for event in agent_to_run.run_async(invocation_context):
      yield event
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/agents/base_agent.py", line 147, in run_async
    async for event in self._run_async_impl(ctx):
      yield event
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/agents/llm_agent.py", line 278, in _run_async_impl
    async for event in self._llm_flow.run_async(ctx):
      self.__maybe_save_output_to_state(event)
      yield event
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 279, in run_async
    async for event in self._run_one_step_async(invocation_context):
      last_event = event
      yield event
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 305, in _run_one_step_async
    async for llm_response in self._call_llm_async(
    ...<8 lines>...
        yield event
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 520, in _call_llm_async
    async for llm_response in llm.generate_content_async(
    ...<16 lines>...
      yield llm_response
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/models/google_llm.py", line 146, in generate_content_async
    response = await self.api_client.aio.models.generate_content(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    ...<3 lines>...
    )
    ^
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/genai/models.py", line 7124, in generate_content
    response = await self._generate_content(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        model=model, contents=contents, config=parsed_config
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/genai/models.py", line 6118, in _generate_content
    response_dict = await self._api_client.async_request(
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        'post', path, request_dict, http_options
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/genai/_api_client.py", line 789, in async_request
    result = await self._async_request(http_request=http_request, stream=False)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/genai/_api_client.py", line 733, in _async_request
    await errors.APIError.raise_for_async_response(response)
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/genai/errors.py", line 129, in raise_for_async_response
    raise ClientError(status_code, response_json, response)
google.genai.errors.ClientError: 403 PERMISSION_DENIED. {'error': {'code': 403, 'message': 'Permission denied on resource project XXX.', 'status': 'PERMISSION_DENIED', 'details': [{'@type': 'type.googleapis.com/google.rpc.ErrorInfo', 'reason': 'CONSUMER_INVALID', 'domain': 'googleapis.com', 'metadata': {'containerInfo': 'XXX', 'consumer': 'projects/XXX', 'service': 'aiplatform.googleapis.com'}}, {'@type': 'type.googleapis.com/google.rpc.LocalizedMessage', 'locale': 'en-US', 'message': 'Permission denied on resource project XXX.'}, {'@type': 'type.googleapis.com/google.rpc.Help', 'links': [{'description': 'Google developers console', 'url': 'https://console.developers.google.com'}]}]}}
Failed to detach context
Traceback (most recent call last):
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/opentelemetry/trace/__init__.py", line 587, in use_span
    yield span
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/opentelemetry/sdk/trace/__init__.py", line 1105, in start_as_current_span
    yield span
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/opentelemetry/trace/__init__.py", line 452, in start_as_current_span
    yield span
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 537, in _call_llm_async
    yield llm_response
GeneratorExit

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/opentelemetry/context/__init__.py", line 155, in detach
    _RUNTIME_CONTEXT.detach(token)
    ~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
  File "/opt/homebrew/anaconda3/envs/adk-local/lib/python3.13/site-packages/opentelemetry/context/contextvars_context.py", line 53, in detach
    self._current_context.reset(token)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^
ValueError: <Token var=<ContextVar name='current_context' default={} at 0x102417970> at 0x11f7caec0> was created in a different Context

As we could see, while the llm invocation failed, the tracing job has also thrown panic.

Colstuwjx avatar May 28 '25 07:05 Colstuwjx

I'm getting the same on 1.1.1.

stefanadelbert avatar May 30 '25 00:05 stefanadelbert

Have same issue without parallel agent just some tools and an AgentTool.

antonpp avatar Jun 02 '25 18:06 antonpp

This is problem with google opentelemetry-exporter-gcp-trace that works with OpenTelemetry 1.34.x. The latest available version is still 1.9.0, which is incompatible with the newer OpenTelemetry API. I tested the temporary patch that works. You can disable that telemetry with code below in file where you have root agent.

# Disable OpenTelemetry to avoid context management issues with incompatible GCP exporter
os.environ["OTEL_SDK_DISABLED"] = "true"

# Suppress OpenTelemetry warnings
logging.getLogger("opentelemetry").setLevel(logging.ERROR)

This is only temp fix.

petitoff avatar Jun 11 '25 18:06 petitoff

I'm also seeing it randomly with 1.42 and had not before.

rcleveng avatar Jun 25 '25 19:06 rcleveng

This is problem with google opentelemetry-exporter-gcp-trace that works with OpenTelemetry 1.34.x. The latest available version is still 1.9.0, which is incompatible with the newer OpenTelemetry API. I tested the temporary patch that works. You can disable that telemetry with code below in file where you have root agent.

What is the issue number to track the opentelemetry-exporter-gcp-trace issue?

rcleveng avatar Jun 26 '25 01:06 rcleveng

I'm seeing this issue in 1.5 when using ParallelAgents

pyralix avatar Jun 29 '25 22:06 pyralix

Having this issue not when using parallel agents, but just using two agents and AgentTool.

lsgordon avatar Jul 02 '25 19:07 lsgordon

Here is my code

generate_content_config={'http_options': {
                          "base_url": "<OURAPIGATEWAY>/",
                          "api_version": "v1",
                          "headers": headers,
                          "timeout": 300000
                      }
                    }

root_agent = Agent(
    name="shrink_ai_agent",
    model="gemini-2.5-pro",
    description=(
        "Agent to answer questions about retail shrink descrepancies. It can also tell you the time and weather in a city (wrongly)"
    ),
    instruction=(
        f"""
<Instructions not included>
        """
    ),
    generate_content_config=generate_content_config,
    tools=[get_current_time, execute_query, get_table_info],
    sub_agents=[analyst_plotter]

and here is the subagent

def save_generated_plot_py(context: CallbackContext, plot_object: plt.figure) -> None:
    """Saves generated PDF bytes plot as an artifact.
    """
    report_artifact = types.Part.from_data(
        data=bytes(plot_object),
        mime_type="application/pdf"
    )
    filename = "generated_report.pdf"

    try:
        version = context.save_artifact(filename=filename, artifact=report_artifact)
        print(f"Successfully saved Python artifact '{filename}' as version {version}.")
        # The event generated after this callback will contain:
        # event.actions.artifact_delta == {"generated_report.pdf": version}
    except ValueError as e:
        print(f"Error saving Python artifact: {e}. Is ArtifactService configured in Runner?")
    except Exception as e:
        # Handle potential storage errors (e.g., GCS permissions)
        print(f"An unexpected error occurred during Python artifact save: {e}")

analyst_plotter = LlmAgent(
    name="analyst_plotter",
    model="gemini-2.5-pro",
    generate_content_config=generate_content_config,
    code_executor=BuiltInCodeExecutor(),
    description=(
        "Agent to draw insights from query results using python."
    ),
    instruction=(
        """You are a helpful agent who is a skilled data analyst, who can use python  \
        to answer questions. You should emphasize the following:

        Making graphs using matplotlib, by converting the JSON into pandas.

        Then save using the save function
                """
    ),
    tools=[save_generated_plot_py],
    sub_agents=[]
)

With this setup I get this error:

2025-07-02 15:55:01,512 - ERROR - fast_api.py:820 - Error in event_generator: Failed to parse the parameter context: google.adk.agents.callback_context.CallbackContext of function save_generated_plot_py for automatic function calling. Automatic function calling works best with simpler function signature schema, consider manually parsing your function declaration for function save_generated_plot_py.
Traceback (most recent call last):
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/cli/fast_api.py", line 809, in event_generator
    async for event in runner.run_async(
    ...<8 lines>...
      yield f"data: {sse_event}\n\n"
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/runners.py", line 203, in run_async
    async for event in invocation_context.agent.run_async(invocation_context):
    ...<2 lines>...
      yield event
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/agents/base_agent.py", line 147, in run_async
    async for event in self._run_async_impl(ctx):
      yield event
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/agents/llm_agent.py", line 275, in _run_async_impl
    async for event in self._llm_flow.run_async(ctx):
      self.__maybe_save_output_to_state(event)
      yield event
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 282, in run_async
    async for event in self._run_one_step_async(invocation_context):
      last_event = event
      yield event
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 318, in _run_one_step_async
    async for event in self._postprocess_async(
    ...<4 lines>...
      yield event
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 390, in _postprocess_async
    async for event in self._postprocess_handle_function_calls_async(
    ...<2 lines>...
      yield event
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 480, in _postprocess_handle_function_calls_async
    async for event in agent_to_run.run_async(invocation_context):
      yield event
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/agents/base_agent.py", line 147, in run_async
    async for event in self._run_async_impl(ctx):
      yield event
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/agents/llm_agent.py", line 275, in _run_async_impl
    async for event in self._llm_flow.run_async(ctx):
      self.__maybe_save_output_to_state(event)
      yield event
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 282, in run_async
    async for event in self._run_one_step_async(invocation_context):
      last_event = event
      yield event
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 302, in _run_one_step_async
    async for event in self._preprocess_async(invocation_context, llm_request):
      yield event
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/flows/llm_flows/base_llm_flow.py", line 344, in _preprocess_async
    await tool.process_llm_request(
        tool_context=tool_context, llm_request=llm_request
    )
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/tools/base_tool.py", line 96, in process_llm_request
    if (function_declaration := self._get_declaration()) is None:
                                ~~~~~~~~~~~~~~~~~~~~~^^
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/tools/function_tool.py", line 65, in _get_declaration
    build_function_declaration(
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^
        func=self.func,
        ^^^^^^^^^^^^^^^
    ...<3 lines>...
        variant=self._api_variant,
        ^^^^^^^^^^^^^^^^^^^^^^^^^^
    )
    ^
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/tools/_automatic_function_calling_util.py", line 236, in build_function_declaration
    from_function_with_options(func, variant)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/tools/_automatic_function_calling_util.py", line 310, in from_function_with_options
    schema = _function_parameter_parse_util._parse_schema_from_parameter(
        variant, param, func.__name__
    )
  File "/Users/l0g0idz/Desktop/scratch/shrink-ai-bot/.venv/lib/python3.13/site-packages/google/adk/tools/_function_parameter_parse_util.py", line 306, in _parse_schema_from_parameter
    raise ValueError(
    ...<4 lines>...
    )
ValueError: Failed to parse the parameter context: google.adk.agents.callback_context.CallbackContext of function save_generated_plot_py for automatic function calling. Automatic function calling works best with simpler function signature schema, consider manually parsing your function declaration for function save_generated_plot_py.

@selcukgun

lsgordon avatar Jul 02 '25 21:07 lsgordon

I am getting this issue with just one agent. I have tried following versions - 1.5.0, 1.4.2

anupmanekar avatar Jul 03 '25 00:07 anupmanekar

This is problem with google opentelemetry-exporter-gcp-trace that works with OpenTelemetry 1.34.x. The latest available version is still 1.9.0, which is incompatible with the newer OpenTelemetry API. I tested the temporary patch that works. You can disable that telemetry with code below in file where you have root agent.

# Disable OpenTelemetry to avoid context management issues with incompatible GCP exporter
os.environ["OTEL_SDK_DISABLED"] = "true"

# Suppress OpenTelemetry warnings
logging.getLogger("opentelemetry").setLevel(logging.ERROR)

This is only temp fix.

But this temp fix have worked. Thanks

anupmanekar avatar Jul 03 '25 00:07 anupmanekar

This is problem with google opentelemetry-exporter-gcp-trace that works with OpenTelemetry 1.34.x. The latest available version is still 1.9.0, which is incompatible with the newer OpenTelemetry API. I tested the temporary patch that works. You can disable that telemetry with code below in file where you have root agent.

@petitoff Do you happen to know if https://github.com/GoogleCloudPlatform/opentelemetry-operations-python/issues/406 the bug that's fixed and just waiting for a newer release (newer than 1.9.0)?

rcleveng avatar Jul 03 '25 15:07 rcleveng

+1

maxbaluev avatar Jul 18 '25 12:07 maxbaluev

+1

tuanchris avatar Jul 20 '25 13:07 tuanchris

+1

mykytaterentiev avatar Jul 22 '25 08:07 mykytaterentiev

+1 Have the same issue will try the temp fix. thanks

idreamsahan avatar Jul 22 '25 10:07 idreamsahan

+1

pallaoro avatar Jul 23 '25 12:07 pallaoro