Skip to content

feat(live): update system instruction and tools in-session via LiveRquestQueue - #7945

Open
rfan-debug wants to merge 3 commits into
google:mainfrom
rfan-debug:rfan-dev
Open

rfan-debug wants to merge 3 commits into
google:mainfrom
rfan-debug:rfan-dev

Conversation

@rfan-debug

@rfan-debug rfan-debug commented Nov 2, 2026 •

Copy link
Copy Markdown

Link to Issue or Description of Change

1. Link to an existing issue (if applicable):

Proposed change

  • google-genai==2.32 added AsyncSession.send_context_update, but the live runner offered no way to use it: callers reached into the private _gemini_session, which left the new tools unknown to ADK's function-call dispatch and reverted the update on every reconnect.

This change adds LiveContextUpdate and LiveRequestQueue.send_context_update. The flow rewrites the LlmRequest first, registering the tools in tools_dict and storing the instruction where Gemini.connect reads it, so function calls execute and reconnects replay the latest context, then forwards the update through BaseLlmConnection.send_context_update.

    live_request_queue.send_context_update(
        system_instruction=CHECKOUT_INSTRUCTION,
        tools=[FunctionTool(lookup_order)],
    )

Both fields are part of the model preamble, so an update invalidates the Live prefix cache; the docstrings say so and point per-turn context to send_content(partial=True) or tool responses instead.

Testing Plan

Unit tests (all under tests/unittests/):

  • live/test_live_request_queue.py: queueing, [] vs None, missing-field ValueError, extra='forbid'.
  • live/test_live_llm_flow.py: tools replaced in tools_dict / config.tools / live_connect_config.tools and sent; [] clears; instruction stored where Gemini.connect reads it and sent as role='system' Content; send_to_model applies the update before content in the same request.
  • models/test_gemini_llm_connection.py: SDK forwarding (incl. empty list), unset fields stay None, SDK-floor error.
pytest tests/unittests/live tests/unittests/models/test_gemini_llm_connection.py \
       tests/unittests/test_import_loading.py tests/unittests/agents
pre-commit run --files <touched files>   # all hooks pass
mypy <touched src files>                  # Success: no issues found
tox                                        # py311 OK, py312 OK, py313 OK, py314 OK

Unit Tests:

  • I have added or updated unit tests for my change.
  • All unit tests pass locally.

Please include a summary of passed pytest results.

Manual End-to-End (E2E) Tests:

Manual E2E (to do before opening the PR): adk web with a live agent, send a context update from a tool callback, confirm (a) the model follows the new instruction, (b) a call to a swapped-in tool is executed by ADK, (c) after a forced reconnect the new tools are still declared.

Doc change: google/adk-docs#2545

Checklist

  • I have read the CONTRIBUTING.md document.
  • I have performed a self-review of my own code.
  • I have commented my code, particularly in hard-to-understand areas.
  • I have added tests that prove my fix is effective or that my feature works.
  • New and existing unit tests pass locally with my changes.
  • I have manually tested my changes end-to-end.
  • Any dependent changes have been merged and published in downstream modules.

rfan-debug and others added 2 commits November 2, 2026 18:03
…questQueue

google-genai 2.32 added AsyncSession.send_context_update, but the live
runner offered no way to use it: callers reached into the private
_gemini_session, which left the new tools unknown to ADK's function-call
dispatch and reverted the update on every reconnect.

Add LiveContextUpdate and LiveRequestQueue.send_context_update. The flow
rewrites the LlmRequest first, registering the tools in tools_dict and
storing the instruction where Gemini.connect reads it, so function calls
execute and reconnects replay the latest context, then forwards the update
through BaseLlmConnection.send_context_update.

    live_request_queue.send_context_update(
        system_instruction=CHECKOUT_INSTRUCTION,
        tools=[FunctionTool(lookup_order)],
    )

Both fields are part of the model preamble, so an update invalidates the
Live prefix cache; the docstrings say so and point per-turn context to
send_content(partial=True) or tool responses instead.
…questQueue

google-genai 2.32 added AsyncSession.send_context_update, but the live
runner offered no way to use it: callers reached into the private
_gemini_session, which left the new tools unknown to ADK's function-call
dispatch and reverted the update on every reconnect.

Add LiveContextUpdate and LiveRequestQueue.send_context_update. The flow
rewrites the LlmRequest first, registering the tools in tools_dict and
storing the instruction where Gemini.connect reads it, so function calls
execute and reconnects replay the latest context, then forwards the update
through BaseLlmConnection.send_context_update.

    live_request_queue.send_context_update(
        system_instruction=CHECKOUT_INSTRUCTION,
        tools=[FunctionTool(lookup_order)],
    )

Both fields are part of the model preamble, so an update invalidates the
Live prefix cache; the docstrings say so and point per-turn context to
send_content(partial=True) or tool responses instead.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

run_live: change instruction/tools or transfer agents on the open Live connection (send_context_update, in-session transfer)

2 participants