MCPcopy Create free account
hub / github.com/google/adk-python / test_auto_to_loop

Function test_auto_to_loop

tests/unittests/workflow/test_agent_transfer.py:409–528  ·  view source on GitHub ↗
(is_resumable: bool)

Source from the content-addressed store, hash-verified

407
408@pytest.mark.parametrize('is_resumable', [True, False])
409def test_auto_to_loop(is_resumable: bool):
410 response = [
411 transfer_call_part('sub_agent_1'),
412 # sub_agent_1 responds directly instead of transferring.
413 'response1',
414 'response2',
415 'response3',
416 Part.from_function_call(name='exit_loop', args={}),
417 'response4',
418 'response5',
419 ]
420 mock_model = testing_utils.MockModel.create(responses=response)
421 # root (auto) - sub_agent_1 (loop) - sub_agent_1_1 (single)
422 # \ sub_agent_1_2 (single)
423 sub_agent_1_1 = Agent(
424 name='sub_agent_1_1',
425 model=mock_model,
426 disallow_transfer_to_parent=True,
427 disallow_transfer_to_peers=True,
428 )
429 sub_agent_1_2 = Agent(
430 name='sub_agent_1_2',
431 model=mock_model,
432 disallow_transfer_to_parent=True,
433 disallow_transfer_to_peers=True,
434 tools=[exit_loop],
435 )
436 sub_agent_1 = LoopAgent(
437 name='sub_agent_1',
438 sub_agents=[sub_agent_1_1, sub_agent_1_2],
439 )
440 root_agent = Agent(
441 name='root_agent',
442 model=mock_model,
443 sub_agents=[sub_agent_1],
444 )
445 app = App(
446 name='test_app',
447 root_agent=root_agent,
448 resumability_config=ResumabilityConfig(is_resumable=is_resumable),
449 )
450 runner = testing_utils.InMemoryRunner(app=app)
451
452 if not is_resumable:
453 # Asserts the transfer.
454 assert testing_utils.simplify_events(runner.run('test1')) == [
455 # Transfers to sub_agent_1.
456 ('root_agent', transfer_call_part('sub_agent_1')),
457 ('root_agent', TRANSFER_RESPONSE_PART),
458 # Loops.
459 ('sub_agent_1_1', 'response1'),
460 ('sub_agent_1_2', 'response2'),
461 ('sub_agent_1_1', 'response3'),
462 # Exits.
463 ('sub_agent_1_2', Part.from_function_call(name='exit_loop', args={})),
464 (
465 'sub_agent_1_2',
466 Part.from_function_response(

Callers

nothing calls this directly

Calls 8

runMethod · 0.95
LoopAgentClass · 0.90
AppClass · 0.90
ResumabilityConfigClass · 0.90
LoopAgentStateClass · 0.90
transfer_call_partFunction · 0.70
createMethod · 0.45
model_dumpMethod · 0.45

Tested by

no test coverage detected