(is_resumable: bool)
| 99 | |
| 100 | @pytest.mark.parametrize('is_resumable', [True, False]) |
| 101 | def test_auto_to_single(is_resumable: bool): |
| 102 | response = [ |
| 103 | transfer_call_part('sub_agent_1'), |
| 104 | 'response1', |
| 105 | 'response2', |
| 106 | ] |
| 107 | mock_model = testing_utils.MockModel.create(responses=response) |
| 108 | # root (auto) - sub_agent_1 (single) |
| 109 | sub_agent_1 = Agent( |
| 110 | name='sub_agent_1', |
| 111 | model=mock_model, |
| 112 | disallow_transfer_to_parent=True, |
| 113 | disallow_transfer_to_peers=True, |
| 114 | ) |
| 115 | root_agent = Agent( |
| 116 | name='root_agent', model=mock_model, sub_agents=[sub_agent_1] |
| 117 | ) |
| 118 | app = App( |
| 119 | name='test_app', |
| 120 | root_agent=root_agent, |
| 121 | resumability_config=ResumabilityConfig(is_resumable=is_resumable), |
| 122 | ) |
| 123 | runner = testing_utils.InMemoryRunner(app=app) |
| 124 | |
| 125 | if not is_resumable: |
| 126 | # Asserts the responses. |
| 127 | assert testing_utils.simplify_events(runner.run('test1')) == [ |
| 128 | ('root_agent', transfer_call_part('sub_agent_1')), |
| 129 | ('root_agent', TRANSFER_RESPONSE_PART), |
| 130 | ('sub_agent_1', 'response1'), |
| 131 | ] |
| 132 | |
| 133 | # root_agent should still be the current agent, because sub_agent_1 is |
| 134 | # single. |
| 135 | assert testing_utils.simplify_events(runner.run('test2')) == [ |
| 136 | ('root_agent', 'response2'), |
| 137 | ] |
| 138 | else: |
| 139 | assert testing_utils.simplify_resumable_app_events(runner.run('test1')) == [ |
| 140 | ('root_agent', transfer_call_part('sub_agent_1')), |
| 141 | ('root_agent', TRANSFER_RESPONSE_PART), |
| 142 | ('root_agent', END_OF_AGENT), |
| 143 | ('sub_agent_1', 'response1'), |
| 144 | ('sub_agent_1', END_OF_AGENT), |
| 145 | ] |
| 146 | # Same session, different invocation. |
| 147 | assert testing_utils.simplify_resumable_app_events(runner.run('test2')) == [ |
| 148 | ('root_agent', 'response2'), |
| 149 | ('root_agent', END_OF_AGENT), |
| 150 | ] |
| 151 | |
| 152 | |
| 153 | @pytest.mark.parametrize('is_resumable', [True, False]) |
nothing calls this directly
no test coverage detected