Skip to content

Regression in 1.18.0: Function response cannot find matching function call event when sent via separate SSE request #3531

@srochiramani

Description

@srochiramani

Describe the bug

When sending a function response via a separate /run_sse request (e.g., from an async job completion callback), ADK's event generator raises ValueError: No function call event found for function responses ids even though the function call event exists in the session history. This occurs in ADK 1.18.0 but works correctly in ADK 1.17.0.

The issue is in _rearrange_events_for_latest_function_response function which only searches through events in the current request context, not the full session history. When a function response is sent in a separate SSE request, ADK cannot find the matching function call event because it's not in the current request's event list.

To Reproduce

  1. Install google-adk==1.18.0
  2. Create a LongRunningFunctionTool that returns immediately with a job ID and completes asynchronously
  3. Agent calls the tool in one SSE request (function call event is created)
  4. Later, when the async job completes, send the function response via a separate /run_sse request:
from google.genai import types

# In update_job_status endpoint or similar async callback
function_response = types.FunctionResponse(
    id=function_call_id,  # ID from the original function call
    name='phone_call_tool',
    response=job_metadata
)
content = types.Content(role='model', parts=[types.Part(function_response=function_response)])

# Send via separate SSE request
await send_sse_message(
    user_id, 
    session_id, 
    {'newMessage': content.model_dump()}, 
    state_delta=updated_state
)
  1. Error occurs:
ValueError: No function call event found for function responses ids: {'toolu_01KVJbyjbb9iRvLGq4XysjUA'}

Stack trace:

File "/usr/local/lib/python3.11/site-packages/google/adk/cli/adk_web_server.py", line 1421, in event_generator
    async for event in agen:
File "/usr/local/lib/python3.11/site-packages/google/adk/runners.py", line 443, in run_async
    async for event in agen:
...
File "/usr/local/lib/python3.11/site-packages/google/adk/flows/llm_flows/contents.py", line 402, in _get_contents
    result_events = _rearrange_events_for_latest_function_response(
File "/usr/local/lib/python3.11/site-packages/google/adk/flows/llm_flows/contents.py", line 186, in _rearrange_events_for_latest_function_response
    raise ValueError(
ValueError: No function call event found for function responses ids: {'toolu_01KVJbyjbb9iRvLGq4XysjUA'}

Expected behavior

ADK should be able to find the function call event in the session history when processing a function response sent via a separate request. The _rearrange_events_for_latest_function_response function should search the full session event history, not just the events in the current request context.

Workaround

In ADK 1.17.0, this works correctly. The function response can be sent via a separate SSE request and ADK successfully finds the matching function call in session history.

Desktop (please complete the following information):

  • OS: Linux (Google Cloud Run), macOS (local development)
  • Python version: Python 3.11
  • ADK version:
    • Broken: google-adk==1.18.0
    • Working: google-adk==1.17.0

Model Information:

  • Are you using LiteLLM: Yes
  • Which model is being used: Sonnet 4.5

Additional context

  • Using FunctionTool for kicking off an async operations
  • Production environment uses Vertex AI Agent Engine for session storage (--session_service_uri with agentengine://)
  • Local development uses in-memory session service
  • The function call is made in one SSE request, and the function response is delivered later via a separate /run_sse request when the async job completes
  • The function call event exists in the session history (verified by fetching session data), but ADK's event generator cannot find it when processing the function response in a separate request
  • This is a regression from ADK 1.17.0 to 1.18.0

Code reference:

The issue is in google/adk/flows/llm_flows/contents.py in the _rearrange_events_for_latest_function_response function. It searches backwards through the events list parameter, but when a function response is sent via a separate request, this list only contains the function response event, not the full session history.

The function should either:

  1. Load the full session history before searching for the function call event, or
  2. Have access to the session's event history through the invocation context

Metadata

Metadata

Labels

core[Component] This issue is related to the core interface and implementationrequest clarification[Status] The maintainer need clarification or more information from the authorservices[Component] This issue is related to runtime services, e.g. sessions, memory, artifacts, etc

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions