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

[Bug] Preloading memory makes load_artifacts omit an existing file and use the old meeting schedule

Open master1018 opened this issue 6 days ago • 3 comments

🔴 Required Information

Please ensure all items in this section are completed to allow for efficient triaging. Requests without complete information may be rejected / deprioritized. If an item is not applicable to you - please mark it as N/A

Describe the Bug:

load_artifacts returns the requested filename and its usual status, but the next model request contains no file contents when PreloadMemoryTool() appears before LoadArtifactsTool() in Agent.tools.

I was using a reading-club assistant to prepare this month's meeting reminder. It remembers the previous booking, Thursday at 18:00 in Cedar Room, as a fallback. After that first conversation, I upload schedule.csv with the new booking, Thursday at 18:45 in Maple Room. The assistant is allowed to use the old booking only when a single attempt to read the current file provides no content.

The assistant completes the task using 18:00 / Cedar Room, explaining that the CSV was unavailable, even though it exists and can be loaded from the artifact service. Swapping the two built-in tools makes the same task return 18:45 / Maple Room. This is the application's fallback being triggered incorrectly by missing file context, not an unexplained model fabrication.

Steps to Reproduce: Please provide a numbered list of steps to reproduce the behavior:

  1. Install google-adk 2.15.1 and LiteLLM 1.106.2 in Conda, and configure DEEPSEEK_API_KEY.
  2. Save the complete script below as /tmp/adk-reading-club/main.py.
  3. Run it using the command below.
conda create -p /tmp/adk-reading-club-env python=3.11.18 pip -y
conda run -p /tmp/adk-reading-club-env python -m pip install google-adk==2.15.1 litellm==1.106.2
# Save the complete script below as /tmp/adk-reading-club/main.py.
# Set DEEPSEEK_API_KEY in your environment before running; do not put it in the script.
conda run --no-capture-output -p /tmp/adk-reading-club-env python /tmp/adk-reading-club/main.py

Expected Behavior: The request after load_artifacts(artifact_names=['schedule.csv']) should include both the recalled booking and the selected CSV. The assistant should use Thursday, 18:45, Maple Room, because the current file is available. The relative order of these two built-in tools should not suppress the file.

Observed Behavior: The final uninstrumented run completed with:

I'll remember that: fallback reading club time is Thursday 18:00, Cedar Room.
The schedule.csv load returned no CSV content, so I'm using the remembered booking.

**Reading Club Reminder — This Month**
- **When:** Thursday at 18:00
- **Where:** Cedar Room

See you there!

The same prompt and file, with tools=[LoadArtifactsTool(), PreloadMemoryTool()], completed with:

This month's reading club reminder:

**Reading Club — Thursday at 18:45, Maple Room**

(Current schedule used; fallback Thursday 18:00, Cedar Room not needed.)

Environment Details:

  • ADK Library Version (pip show google-adk):google-adk 2.15.1
  • Desktop OS:Ubuntu 20.04.6 LTS, x86_64; Linux 5.15.0-139-generic.
  • Python Version (python -V): 3.11.18

Model Information:

  • Are you using LiteLLM: Yes
  • Which model is being used: deepseek-v4.1-flash

🟡 Optional Information

Providing this information greatly speeds up the resolution process.

Regression: N/A

Logs: Please attach relevant logs. Wrap them in code blocks (```) or attach a text file.

// Paste logs here
Traceback (most recent call last):
  File "/tmp/adk-reading-club/main.py", line 50, in <module>
    asyncio.run(main())
  File "/tmp/context-release-audit/envs/adk-python/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/tmp/context-release-audit/envs/adk-python/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/tmp/context-release-audit/envs/adk-python/lib/python3.11/asyncio/base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/tmp/adk-reading-club/main.py", line 47, in main
    assert "18:45" in answer and "Maple Room" in answer, "The loaded schedule never reached the assistant"
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: The loaded schedule never reached the assistant

Screenshots / Video: N/A

Additional Context: N/A

Minimal Reproduction Code: Please provide a code snippet or a link to a Gist/repo that isolates the issue.

// Code snippet here
import asyncio
import os

from google.adk import Agent, Runner
from google.adk.artifacts import InMemoryArtifactService
from google.adk.memory import InMemoryMemoryService
from google.adk.models.lite_llm import LiteLlm
from google.adk.sessions import InMemorySessionService
from google.adk.tools.load_artifacts_tool import LoadArtifactsTool
from google.adk.tools.preload_memory_tool import PreloadMemoryTool
from google.genai import types


async def main():
    sessions, memory, artifacts = (InMemorySessionService(),
                                  InMemoryMemoryService(), InMemoryArtifactService())
    session = await sessions.create_session(app_name="reading_club", user_id="reader")
    agent = Agent(name="reading_assistant", model=LiteLlm(
        model="openai/deepseek-flash", api_base="https://api.deepseek.com",
        api_key=os.environ["DEEPSEEK_API_KEY"], temperature=0,
        extra_body={"thinking": {"type": "disabled"}}),
        instruction="Help prepare reading club reminders. Keep replies short. "
        "Try the current schedule once per reminder. If its text is unavailable after "
        "that attempt, use the remembered time and room without retrying.",
        tools=[PreloadMemoryTool(), LoadArtifactsTool()])
    runner = Runner(node=agent, app_name="reading_club", session_service=sessions,
                    memory_service=memory, artifact_service=artifacts)
    for turn, question in enumerate([
        "The previous reading club met on Thursday at 18:00 in Cedar Room. "
        "Remember this as a fallback for future reminders.",
        "Prepare this month's meeting reminder. Try schedule.csv once for the current "
        "time and room; if you receive no CSV content, use the remembered booking.",
    ]):
        answer = ""
        async for event in runner.run_async(user_id="reader", session_id=session.id,
            new_message=types.Content(role="user", parts=[types.Part(text=question)])):
            if event.is_final_response() and event.content:
                answer = "".join(p.text or "" for p in event.content.parts or [] if not p.thought)
        print(answer, flush=True)
        await memory.add_session_to_memory(await sessions.get_session(
            app_name="reading_club", user_id="reader", session_id=session.id))
        if turn == 0:
            await artifacts.save_artifact(app_name="reading_club", user_id="reader",
                session_id=session.id, filename="schedule.csv", artifact=types.Part(text=
                    "club,day,time,room\nreading club,Thursday,18:45,Maple Room\n"))

    assert "18:45" in answer and "Maple Room" in answer, "The loaded schedule never reached the assistant"


asyncio.run(main())

How often has this issue occurred?:

  • [x] Always (100%)
  • Often (50%+)
  • Intermittently (<50%)
  • Once / Rare

master1018 avatar Nov 27 '26 07:11 master1018

May I work on this issue (#8398: Bug Preloading memory makes loadartifacts omit an existing file and use the old meeting schedule) and, if I can reproduce it, submit a focused fix with regression coverage? Please let me know if someone is already handling it or if you would prefer a different approach. I would use Codex assistance and disclose that in any PR.

chelsealong avatar Nov 27 '26 07:11 chelsealong

Hi @master1018, Thanks for the clear report. We can confirm this bug on 2.15.1 and on main. When PreloadMemoryTool runs first it adds the memory note as the last message. LoadArtifactsTool only checks the last message for the file request so it never sees it and does not attach the file. For now list the artifacts tool first: tools=[LoadArtifactsTool(), PreloadMemoryTool()].

Hello @Echolonius, Thanks for #8441, it should fix this issue. However it looks like you have not signed the CLA yet. Please sign it so your PR can be processed further. We would also recommend reusing the existing _last_non_transient_content() helper from models/llm_request.py and applying the same fix to load_mcp_resource_tool.py and skill_toolset.py.

@master1018, in the mean time could you please test the fix in #8441 and share your feedback?

llalitkumarrr avatar Dec 02 '26 06:12 llalitkumarrr

Hi @master1018, Thanks for the clear report. We can confirm this bug on 2.15.1 and on main. When PreloadMemoryTool runs first it adds the memory note as the last message. LoadArtifactsTool only checks the last message for the file request so it never sees it and does not attach the file. For now list the artifacts tool first: tools=[LoadArtifactsTool(), PreloadMemoryTool()].

Hello @Echolonius, Thanks for #8441, it should fix this issue. However it looks like you have not signed the CLA yet. Please sign it so your PR can be processed further. We would also recommend reusing the existing _last_non_transient_content() helper from models/llm_request.py and applying the same fix to load_mcp_resource_tool.py and skill_toolset.py.

@master1018, in the mean time could you please test the fix in #8441 and share your feedback?

I tested PR #8441 at commit 7cf0d013 (ADK source version 2.15.1, Python 3.11.18). The original real-agent reproduction now passes with tools=[PreloadMemoryTool(), LoadArtifactsTool()]. The agent correctly uses the current CSV instead of the remembered booking.

Terminal output (excerpt):

I'll remember that: fallback reading club time is Thursday 18:00, Cedar Room.

This month's reading club reminder:

**Reading Club** — Thursday at **18:45** in the **Maple Room**.

(Current schedule used; fallback not needed.)

The script’s assertion passed, with exit code 0.

master1018 avatar Dec 02 '26 11:12 master1018