feat! Update session service interface to be async.

Also keep the sync version in the InMemorySessionService as create_session_sync() as a temporary migration option.

PiperOrigin-RevId: 759252188
This commit is contained in:
Google Team Member
2025-05-15 12:23:33 -07:00
committed by Copybara-Service
parent 5b3204c356
commit 1804ca39a6
23 changed files with 268 additions and 264 deletions

View File

@@ -37,9 +37,9 @@ class _TestingTool(BaseTool):
return self.declaration
async def _create_tool_context() -> ToolContext:
def _create_tool_context() -> ToolContext:
session_service = InMemorySessionService()
session = await session_service.create_session(
session = session_service.create_session(
app_name='test_app', user_id='test_user'
)
agent = SequentialAgent(name='test_agent')
@@ -55,7 +55,7 @@ async def _create_tool_context() -> ToolContext:
@pytest.mark.asyncio
async def test_process_llm_request_no_declaration():
tool = _TestingTool()
tool_context = await _create_tool_context()
tool_context = _create_tool_context()
llm_request = LlmRequest()
await tool.process_llm_request(
@@ -77,7 +77,7 @@ async def test_process_llm_request_with_declaration():
)
tool = _TestingTool(declaration)
llm_request = LlmRequest()
tool_context = await _create_tool_context()
tool_context = _create_tool_context()
await tool.process_llm_request(
tool_context=tool_context, llm_request=llm_request
@@ -102,7 +102,7 @@ async def test_process_llm_request_with_builtin_tool():
tools=[types.Tool(google_search=types.GoogleSearch())]
)
)
tool_context = await _create_tool_context()
tool_context = _create_tool_context()
await tool.process_llm_request(
tool_context=tool_context, llm_request=llm_request
@@ -131,7 +131,7 @@ async def test_process_llm_request_with_builtin_tool_and_another_declaration():
]
)
)
tool_context = await _create_tool_context()
tool_context = _create_tool_context()
await tool.process_llm_request(
tool_context=tool_context, llm_request=llm_request