Live input screening: in-place edits to nested config, tools or live_connect_config still reach the live request after 17c4a10af
Maintainer antworten meist innerhalb von 3 Tagen
Bewertung
Dieses Issue wurde noch nicht bewertet.
Beschreibung
🔴 Required Information
Describe the Bug:
17c4a10af made live input screening run before-model callbacks on a copy of the live LlmRequest, and the updated live_model_callbacks.md says: "Changes a callback makes to the request's config and tools are discarded and do not reach the model."
That holds when a callback replaces a field (request.config.tool_config = ...), but not when it edits one in place. screen_live_user_content (live/_live_llm_flow.py:71-88) copies:
configwithcopy_request_scoped_fields, which copies the top-level lists and dicts but shares nested models:tool_config, aContentsystem_instruction, and theFunctionDeclarationobjects inside each tool;- the
function_declarationslists (the lists, not their elements); tools_dict.
live_connect_config isn't copied at all, so any edit to it lands on the live request.
The live request is reused when ADK reconnects (the reconnect loop in _live_llm_flow.py), and Gemini.connect builds the session config from it, e.g. live_connect_config.tools = llm_request.config.tools (google_llm.py:662). So an edited tool description, for example, would reach the model after a reconnect. I checked the state of the live request after screening, not a full reconnect.
None of ADK's built-in plugins edit these fields in place as far as I can see, so this affects user-written callbacks.
Steps to Reproduce:
- Check out main (84cb0742b)
- Run the script below. It calls
screen_live_user_contentdirectly, with a before-model callback that edits the request it receives, then prints the live request.
Expected Behavior:
The live request is unchanged: AUTO, orig, ['orig'], h1, None.
Observed Behavior:
tool_config mode: NONE
fd description: edited
system_instruction parts: ['orig', 'added']
live handle: edited
live temperature: 0.0
The parent of 17c4a10af gives the same output (it also leaked top-level config changes, which 17c4a10af fixed).
Environment Details:
- ADK Library Version: main at 84cb0742b
- Desktop OS: macOS
- Python Version: 3.12.13
Model Information:
- Are you using LiteLLM: No
- Which model is being used: N/A (no model call; the callback runs on the screening copy)
🟡 Optional Information
Regression:
No. It's a gap in the 17c4a10af fix.
Minimal Reproduction Code:
import asyncio
from unittest import mock
from google.genai import types
from google.adk.agents.invocation_context import InvocationContext
from google.adk.agents.llm_agent import LlmAgent
from google.adk.agents.run_config import RunConfig
from google.adk.flows.llm_flows.single_flow import SingleFlow
from google.adk.live import _live_llm_flow
from google.adk.models.llm_request import LlmRequest
from google.adk.sessions.in_memory_session_service import InMemorySessionService
async def main():
svc = InMemorySessionService()
sess = await svc.create_session(app_name='a', user_id='u')
ctx = InvocationContext(session_service=svc, invocation_id='i',
agent=LlmAgent(name='ag', model='gemini-2.0-flash'),
session=sess, run_config=RunConfig())
req = LlmRequest(
config=types.GenerateContentConfig(
tools=[types.Tool(function_declarations=[
types.FunctionDeclaration(name='lookup', description='orig')])],
tool_config=types.ToolConfig(
function_calling_config=types.FunctionCallingConfig(mode='AUTO')),
system_instruction=types.Content(role='system', parts=[types.Part(text='orig')]),
),
live_connect_config=types.LiveConnectConfig(
session_resumption=types.SessionResumptionConfig(handle='h1')),
)
def callback(context, request, event):
# Edits the request the callback receives, in place.
request.config.tool_config.function_calling_config.mode = 'NONE'
request.config.tools[0].function_declarations[0].description = 'edited'
request.config.system_instruction.parts.append(types.Part(text='added'))
request.live_connect_config.session_resumption.handle = 'edited'
request.live_connect_config.temperature = 0.0
return None
flow = SingleFlow()
with mock.patch.object(flow, '_handle_before_model_callback', side_effect=callback):
await _live_llm_flow.screen_live_user_content(
flow, ctx, types.Content(role='user', parts=[types.Part(text='hi')]), req)
print('tool_config mode:', req.config.tool_config.function_calling_config.mode)
print('fd description:', req.config.tools[0].function_declarations[0].description)
print('system_instruction parts:', [p.text for p in req.config.system_instruction.parts])
print('live handle:', req.live_connect_config.session_resumption.handle)
print('live temperature:', req.live_connect_config.temperature)
asyncio.run(main())
Additional Context:
A possible fix is to give the screening copy deep copies: llm_request.config.model_copy(deep=True) and live_connect_config.model_copy(deep=True), instead of the field-by-field copy. That also makes the separate function_declarations copy unnecessary. I'm happy to send a PR if that sounds right.
How often has this issue occurred?:
- Always (100%)
- Vorherrschende Sprache
- Python
- Sterne
- 22.3k
- Forks
- 4.4k
- Ø Merge
- 1 T. 2 Std.
- Gemergte PRs (30 T.)
- 6
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Beitragsleitfaden lesen
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus google/adk-python
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
google/adk-python#8360 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 82/100
google/adk-python#8359 ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Can pin to litellm version be changed?Evtl. vergeben @llalitkumarrr hat das vor 10 Tagen übernommen. Offenmodels
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 65/100
google/adk-python#8129 · 2 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 3 Tagen
-
OpenAPI tools ignore operation- and path-level server overridesEvtl. vergeben @sanketpatil06 hat das vor 14 Tagen übernommen. Offentools
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
google/adk-python#8064 · 4 Kommentare · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 3 Tagen
-
Two docstrings in openapi_tool document parameters the signatures do not acceptEvtl. vergeben @surajksharma07 hat das vor 17 Tagen übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 88/100
google/adk-python#8024 · 1 Kommentar · 1 zugewiesene Person ·
Maintainer antworten meist innerhalb von 3 Tagen
Alle Issues in google/adk-python
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
vllm-project/vllm#70030 ·
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
TigreGotico/tugaphone#408 ·
Maintainer antworten meist innerhalb von 1 Tag
-
needs-triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 74/100
gke-labs/kube-agents#7308 ·
Maintainer antworten meist innerhalb von 1 Tag
-
t: bug
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Maintainer antworten meist innerhalb von 3 Tagen
-
chore
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 88/100
lugassawan/swe-workbench#841 ·