Skip to content

Commit b58d77a

Browse files
google-genai-botcopybara-github
authored andcommitted
fix: support GetSessionConfig in AdkApp templates and forward it in Runner.run_async
PiperOrigin-RevId: 933400638
1 parent 780b0ab commit b58d77a

2 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/google/adk/runners.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,11 @@ async def _run_node_async(
474474
with tracer.start_as_current_span('invocation'):
475475
# 1. Setup
476476
session = await self._get_or_create_session(
477-
user_id=user_id, session_id=session_id
477+
user_id=user_id,
478+
session_id=session_id,
479+
get_session_config=run_config.get_session_config
480+
if run_config
481+
else None,
478482
)
479483

480484
# Validate and resolve resume inputs
@@ -1000,7 +1004,9 @@ async def run_async(
10001004

10011005
if self.agent.mode == 'chat':
10021006
session = await self._get_or_create_session(
1003-
user_id=user_id, session_id=session_id
1007+
user_id=user_id,
1008+
session_id=session_id,
1009+
get_session_config=run_config.get_session_config,
10041010
)
10051011
# when the chat coordinator has task-mode sub-agents,
10061012
# the wrapper handles delegation via ctx.run_node. Don't let

tests/unittests/test_runners.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1695,9 +1695,28 @@ async def test_run_async_passes_get_session_config():
16951695
),
16961696
)
16971697

1698+
events_seen_by_agent = []
1699+
1700+
class EventCheckingAgent(BaseAgent):
1701+
1702+
def __init__(self, name: str):
1703+
super().__init__(name=name, sub_agents=[])
1704+
1705+
async def _run_async_impl(
1706+
self, invocation_context: InvocationContext
1707+
) -> AsyncGenerator[Event, None]:
1708+
events_seen_by_agent.extend(invocation_context.session.events)
1709+
yield Event(
1710+
invocation_id=invocation_context.invocation_id,
1711+
author=self.name,
1712+
content=types.Content(
1713+
role="model", parts=[types.Part(text="Test response")]
1714+
),
1715+
)
1716+
16981717
runner = Runner(
16991718
app_name=TEST_APP_ID,
1700-
agent=MockAgent("test_agent"),
1719+
agent=EventCheckingAgent("test_agent"),
17011720
session_service=session_service,
17021721
artifact_service=InMemoryArtifactService(),
17031722
)
@@ -1720,6 +1739,13 @@ async def test_run_async_passes_get_session_config():
17201739
assert len(events) >= 1
17211740
assert events[0].author == "test_agent"
17221741

1742+
# The agent should have only seen 3 historical events + 1 new message = 4 events.
1743+
assert len(events_seen_by_agent) == 4
1744+
assert events_seen_by_agent[0].invocation_id == "inv_7"
1745+
assert events_seen_by_agent[1].invocation_id == "inv_8"
1746+
assert events_seen_by_agent[2].invocation_id == "inv_9"
1747+
assert events_seen_by_agent[3].content.parts[0].text == "hello"
1748+
17231749

17241750
@pytest.mark.asyncio
17251751
async def test_run_async_teardown_on_aclose():

0 commit comments

Comments
 (0)