Skip to content

Conversation

dongbin-lunark
Copy link

Motivation

For long-running sessions, fetching the entire event history can be heavy. We want a first-class way to load only a subset of events (e.g., the most recent N or events after a timestamp) when executing an agent run.

What’s changed

  • Runner
    • Added get_session_config: Optional[GetSessionConfig] to Runner.run and Runner.run_async.
    • Forwarded this config to session_service.get_session(..., config=get_session_config).
  • FastAPI server (adk_web_server.py)
    • Extended RunAgentRequest with get_session_config: Optional[GetSessionConfig].
    • Forwarded get_session_config to runner.run_async(...) in /run and /run_sse.

Behavior / API

  • New optional request field for /run and /run_sse:
    • get_session_config.num_recent_events
    • get_session_config.after_timestamp
  • If omitted, behavior is unchanged (all events are returned, as before).

Example payload:
{
"app_name": "my_app",
"user_id": "u1",
"session_id": "s1",
"new_message": {"parts":[{"text":"hello"}]},
"get_session_config": {"num_recent_events": 50}
}

Backwards compatibility

  • Non-breaking; optional-only changes.
  • All session services (InMemory/Database/Vertex AI) already honor GetSessionConfig.

Testing

  • Existing unit tests cover GetSessionConfig in session services.
  • Manual verification through /run and /run_sse with get_session_config.

Tags: #non-breaking

Copy link

google-cla bot commented Sep 4, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Summary of Changes

Hello @dongbin-lunark, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a new capability to efficiently manage session event history for long-running agent sessions. By integrating an optional GetSessionConfig parameter into both the Runner and FastAPI endpoints, it allows users to specify criteria for loading only a subset of events, such as the most recent ones or those occurring after a certain timestamp. This enhancement is designed to reduce the overhead associated with fetching entire event histories, making the system more performant without breaking existing functionality.

Highlights

  • Runner Enhancements: The Runner class now accepts an optional GetSessionConfig parameter in its run and run_async methods, allowing control over session event retrieval.
  • FastAPI Endpoint Integration: The /run and /run_sse FastAPI endpoints have been updated to accept an optional get_session_config field in the RunAgentRequest, which is then passed down to the runner.
  • Session Event Limiting: This change enables users to specify limits on fetched session events, such as retrieving only the most recent N events or events after a specific timestamp, improving performance for long-running sessions.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@adk-bot
Copy link
Collaborator

adk-bot commented Sep 4, 2025

Response from ADK Triaging Agent

Hello @dongbin-lunark, thank you for creating this PR!

Before we can proceed with the review, could you please address the following points from our contribution guidelines:

  • Sign our Contributor License Agreement: It looks like the CLA has not been signed yet. You can sign it at https://cla.developers.google.com/.
  • Associate an Issue: For new features, please create an issue and associate it with this PR. This helps with tracking and discussion.
  • Provide a detailed Testing Plan: Could you please expand the "Testing" section into a "Testing Plan" and include the results of your pytest runs?
  • Include Manual E2E Test Evidence: Please provide screenshots or logs from your manual verification to help reviewers understand and verify the changes.

You can find more details in our contribution guidelines.

This information will help reviewers to review your PR more efficiently. Thanks!

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a get_session_config parameter to limit the number of events fetched for a session, which is a useful optimization for long-running sessions. The changes are well-implemented by plumbing the new parameter through the Runner and FastAPI endpoints. My review includes a few suggestions to improve documentation and API consistency, such as adding a description to the new request field and updating docstrings for the new method parameters.

new_message: types.Content
streaming: bool = False
state_delta: Optional[dict[str, Any]] = None
get_session_config: Optional[GetSessionConfig] = None

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

For better API documentation and consistency with other request models in this file (like CreateSessionRequest), consider adding a description for the new get_session_config field using pydantic.Field.

Suggested change
get_session_config: Optional[GetSessionConfig] = None
get_session_config: Optional[GetSessionConfig] = Field(default=None, description='Configuration for retrieving the session, allowing for limiting the number of events returned.')

session_id: str,
new_message: types.Content,
run_config: RunConfig = RunConfig(),
get_session_config: Optional[GetSessionConfig] = None,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new get_session_config parameter should be documented in the method's docstring to improve maintainability. Please add a description for it in the Args section.

For example:

      get_session_config: Configuration for retrieving the session, allowing for
        limiting the number of events returned.

new_message: types.Content,
state_delta: Optional[dict[str, Any]] = None,
run_config: RunConfig = RunConfig(),
get_session_config: Optional[GetSessionConfig] = None,

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The new get_session_config parameter should be documented in the method's docstring to improve maintainability. Please add a description for it in the Args section. I also noticed state_delta is not documented, which you might want to fix as well, though it's outside the scope of this change.

For example:

      get_session_config: Configuration for retrieving the session, allowing for
        limiting the number of events returned.

… in Runner and FastAPI endpoints #non-breaking

Motivation:
Provide a way to control how many session events are loaded when running an agent to reduce payload size and improve performance for long-running sessions.

What:
- Runner
  - Add optional `get_session_config: Optional[GetSessionConfig]` to `Runner.run` and `Runner.run_async`.
  - Pass `config=get_session_config` to `session_service.get_session(...)`.
- FastAPI server (adk_web_server.py)
  - Add optional `get_session_config` to `RunAgentRequest`.
  - Forward `get_session_config` to `runner.run_async(...)` in `/run` and `/run_sse`.

Why safe:
- The parameter is optional (defaults to `None`), so the change is fully backward-compatible.
- `GetSessionConfig` is already supported by `InMemorySessionService` and `DatabaseSessionService`. The Vertex AI implementation remains unchanged and can be enhanced in a follow-up.

API impact:
- Additive change to the `/run` and `/run_sse` request payloads: clients may now include `get_session_config` with `num_recent_events` and/or `after_timestamp`.

Example:
{
  "app_name": "my_app",
  "user_id": "u1",
  "session_id": "s1",
  "new_message": {"parts":[{"text":"hello"}]},
  "get_session_config": {"num_recent_events": 50}
}

Notes:
- Consider a follow-up PR to apply server-side filtering in `VertexAiSessionService.get_session` if needed.
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.

2 participants