Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/google/adk/cli/adk_web_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
from ..memory.base_memory_service import BaseMemoryService
from ..runners import Runner
from ..sessions.base_session_service import BaseSessionService
from ..sessions.base_session_service import GetSessionConfig
from ..sessions.session import Session
from ..utils.context_utils import Aclosing
from .cli_eval import EVAL_SESSION_ID_PREFIX
Expand Down Expand Up @@ -164,6 +165,7 @@ class RunAgentRequest(common.BaseModel):
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.')



class CreateSessionRequest(common.BaseModel):
Expand Down Expand Up @@ -1021,6 +1023,7 @@ async def run_agent(req: RunAgentRequest) -> list[Event]:
session_id=req.session_id,
new_message=req.new_message,
state_delta=req.state_delta,
get_session_config=req.get_session_config,
)
) as agen:
events = [event async for event in agen]
Expand Down Expand Up @@ -1051,6 +1054,7 @@ async def event_generator():
new_message=req.new_message,
state_delta=req.state_delta,
run_config=RunConfig(streaming_mode=stream_mode),
get_session_config=req.get_session_config,
)
) as agen:
async for event in agen:
Expand Down
13 changes: 12 additions & 1 deletion src/google/adk/runners.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -125,6 +126,7 @@ def run(
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.

) -> Generator[Event, None, None]:
"""Runs the agent.

Expand All @@ -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.
Expand All @@ -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:
Expand Down Expand Up @@ -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,

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.

) -> AsyncGenerator[Event, None]:
"""Main entry method to run the agent in this runner.

Expand All @@ -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.
Expand All @@ -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}')
Expand Down