-
Notifications
You must be signed in to change notification settings - Fork 1.9k
feat(runner, api): allow limiting session events via GetSessionConfig in Runner and FastAPI endpoints #2843
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
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. |
There was a problem hiding this 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 optionalGetSessionConfig
parameter in itsrun
andrun_async
methods, allowing control over session event retrieval. - FastAPI Endpoint Integration: The
/run
and/run_sse
FastAPI endpoints have been updated to accept an optionalget_session_config
field in theRunAgentRequest
, 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
-
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. ↩
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:
You can find more details in our contribution guidelines. This information will help reviewers to review your PR more efficiently. Thanks! |
There was a problem hiding this 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
.
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, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
new_message: types.Content, | ||
state_delta: Optional[dict[str, Any]] = None, | ||
run_config: RunConfig = RunConfig(), | ||
get_session_config: Optional[GetSessionConfig] = None, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
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
get_session_config: Optional[GetSessionConfig]
toRunner.run
andRunner.run_async
.session_service.get_session(..., config=get_session_config)
.adk_web_server.py
)RunAgentRequest
withget_session_config: Optional[GetSessionConfig]
.get_session_config
torunner.run_async(...)
in/run
and/run_sse
.Behavior / API
/run
and/run_sse
:get_session_config.num_recent_events
get_session_config.after_timestamp
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
GetSessionConfig
.Testing
GetSessionConfig
in session services./run
and/run_sse
withget_session_config
.Tags: #non-breaking