Skip to content

Add fixes for InMemorySessionService behavior across long-lived agent requests #1569

Closed

Description

@ParinAcharyaGit

Issue Summary

The current implementation of InMemorySessionService in google.adk.sessions lacks documentation on its behavior in long-lived or asynchronous agent pipelines. When agents rely on session memory across multi-minute workflows (e.g., polling bid portals or processing large files), the in-memory context is reset between invocations — leading to unexpected loss of conversation or task state.

How the Issue Arises

In our project, we’re orchestrating multiple agents (DiscoveryAgent → DownloadAgent → AnalysisAgent) using Runner.run(...) calls in a Flask backend. We initially used InMemorySessionService() to persist session data across the agent lifecycle.

However, during testing, we observed that:

  1. When workflows span multiple POST requests or Cloud Run invocations (e.g., step-by-step bid processing), InMemorySessionService resets the session between requests.

  2. This breaks continuity in agent state — for example, the DiscoveryAgent may store portal metadata in session.memory, which becomes unavailable when passed to the DownloadAgent.

Possible solution

Raise a warning in Runner.run() if InMemorySessionService is used in asynchronous environments or repeated contexts (e.g., longer than X seconds or multiple threads/processes).

Activity

  1. added
    services
    on Jun 22, 2025
  2. added theissue type on Jul 2, 2025
  3. DeanChensj commented on Jul 7, 2025

    @DeanChensj
    Collaborator

    Hi @ParinAcharyaGit , thanks for your suggestion, we will add docstring to the InMemorySerivces to clarify that they are not suitable for running in multi-thread/process environments, you might use DatabaseSessionService or VertexAiSessionService which are more production ready.

  4. self-assigned this
    on Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

services

Type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions