MCPcopy Index your code
hub / github.com/google/adk-python / test_session_auto_creation

Function test_session_auto_creation

tests/unittests/test_runners.py:625–655  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

623
624@pytest.mark.asyncio
625async def test_session_auto_creation():
626
627 class RunnerWithMismatch(Runner):
628
629 def _infer_agent_origin(
630 self, agent: BaseAgent
631 ) -> tuple[Optional[str], Optional[Path]]:
632 del agent
633 return "expected_app", Path("/workspace/agents/expected_app")
634
635 session_service = InMemorySessionService()
636 runner = RunnerWithMismatch(
637 app_name="expected_app",
638 agent=MockLlmAgent("test_agent"),
639 session_service=session_service,
640 artifact_service=InMemoryArtifactService(),
641 auto_create_session=True,
642 )
643
644 agen = runner.run_async(
645 user_id="user",
646 session_id="missing",
647 new_message=types.Content(role="user", parts=[types.Part(text="hi")]),
648 )
649
650 event = await agen.__anext__()
651 await agen.aclose()
652
653 # Verify that session_id="missing" doesn't error out - session is auto-created
654 assert event.author == "test_agent"
655 assert event.content.parts[0].text == "Test LLM response"
656
657
658@pytest.mark.asyncio

Callers

nothing calls this directly

Calls 7

RunnerWithMismatchClass · 0.85
MockLlmAgentClass · 0.85
run_asyncMethod · 0.45
__anext__Method · 0.45
acloseMethod · 0.45

Tested by

no test coverage detected