-
Notifications
You must be signed in to change notification settings - Fork 2k
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -47,6 +47,7 @@ | |
from .plugins.base_plugin import BasePlugin | ||
from .plugins.plugin_manager import PluginManager | ||
from .sessions.base_session_service import BaseSessionService | ||
from .sessions.base_session_service import GetSessionConfig | ||
from .sessions.in_memory_session_service import InMemorySessionService | ||
from .sessions.session import Session | ||
from .telemetry import tracer | ||
|
@@ -125,6 +126,7 @@ def run( | |
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 commentThe reason will be displayed to describe this comment to others. Learn more. |
||
) -> Generator[Event, None, None]: | ||
"""Runs the agent. | ||
|
||
|
@@ -137,6 +139,8 @@ def run( | |
session_id: The session ID of the session. | ||
new_message: A new message to append to the session. | ||
run_config: The run config for the agent. | ||
get_session_config: Configuration for retrieving the session, allowing for | ||
limiting the number of events returned. | ||
|
||
Yields: | ||
The events generated by the agent. | ||
|
@@ -151,6 +155,7 @@ async def _invoke_run_async(): | |
session_id=session_id, | ||
new_message=new_message, | ||
run_config=run_config, | ||
get_session_config=get_session_config, | ||
) | ||
) as agen: | ||
async for event in agen: | ||
|
@@ -185,6 +190,7 @@ async def run_async( | |
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 commentThe reason will be displayed to describe this comment to others. Learn more. The new For example: get_session_config: Configuration for retrieving the session, allowing for
limiting the number of events returned. |
||
) -> AsyncGenerator[Event, None]: | ||
"""Main entry method to run the agent in this runner. | ||
|
||
|
@@ -193,6 +199,8 @@ async def run_async( | |
session_id: The session ID of the session. | ||
new_message: A new message to append to the session. | ||
run_config: The run config for the agent. | ||
get_session_config: Configuration for retrieving the session, allowing for | ||
limiting the number of events returned. | ||
|
||
Yields: | ||
The events generated by the agent. | ||
|
@@ -203,7 +211,10 @@ async def _run_with_trace( | |
) -> AsyncGenerator[Event, None]: | ||
with tracer.start_as_current_span('invocation'): | ||
session = await self.session_service.get_session( | ||
app_name=self.app_name, user_id=user_id, session_id=session_id | ||
app_name=self.app_name, | ||
user_id=user_id, | ||
session_id=session_id, | ||
config=get_session_config, | ||
) | ||
if not session: | ||
raise ValueError(f'Session not found: {session_id}') | ||
|
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 newget_session_config
field usingpydantic.Field
.