|
9 | 9 | AgentCapabilities, |
10 | 10 | AgentCard, |
11 | 11 | Message, |
| 12 | + MessageSendConfiguration, |
12 | 13 | Part, |
13 | 14 | Role, |
14 | 15 | Task, |
@@ -125,3 +126,78 @@ async def test_send_message_non_streaming_agent_capability_false( |
125 | 126 | assert not mock_transport.send_message_streaming.called |
126 | 127 | assert len(events) == 1 |
127 | 128 | assert events[0][0].id == 'task-789' |
| 129 | + |
| 130 | + |
| 131 | +@pytest.mark.asyncio |
| 132 | +async def test_send_message_callsite_config_overrides_non_streaming( |
| 133 | + base_client: BaseClient, mock_transport: MagicMock, sample_message: Message |
| 134 | +): |
| 135 | + base_client._config.streaming = False |
| 136 | + mock_transport.send_message.return_value = Task( |
| 137 | + id='task-cfg-ns-1', |
| 138 | + context_id='ctx-cfg-ns-1', |
| 139 | + status=TaskStatus(state=TaskState.completed), |
| 140 | + ) |
| 141 | + |
| 142 | + cfg = MessageSendConfiguration( |
| 143 | + history_length=2, |
| 144 | + blocking=False, |
| 145 | + accepted_output_modes=['application/json'], |
| 146 | + ) |
| 147 | + events = [ |
| 148 | + event |
| 149 | + async for event in base_client.send_message( |
| 150 | + sample_message, configuration=cfg |
| 151 | + ) |
| 152 | + ] |
| 153 | + |
| 154 | + mock_transport.send_message.assert_called_once() |
| 155 | + assert not mock_transport.send_message_streaming.called |
| 156 | + assert len(events) == 1 |
| 157 | + task, _ = events[0] |
| 158 | + assert task.id == 'task-cfg-ns-1' |
| 159 | + |
| 160 | + params = mock_transport.send_message.call_args[0][0] |
| 161 | + assert params.configuration.history_length == 2 |
| 162 | + assert params.configuration.blocking is False |
| 163 | + assert params.configuration.accepted_output_modes == ['application/json'] |
| 164 | + |
| 165 | + |
| 166 | +@pytest.mark.asyncio |
| 167 | +async def test_send_message_callsite_config_overrides_streaming( |
| 168 | + base_client: BaseClient, mock_transport: MagicMock, sample_message: Message |
| 169 | +): |
| 170 | + base_client._config.streaming = True |
| 171 | + base_client._card.capabilities.streaming = True |
| 172 | + |
| 173 | + async def create_stream(*args, **kwargs): |
| 174 | + yield Task( |
| 175 | + id='task-cfg-s-1', |
| 176 | + context_id='ctx-cfg-s-1', |
| 177 | + status=TaskStatus(state=TaskState.completed), |
| 178 | + ) |
| 179 | + |
| 180 | + mock_transport.send_message_streaming.return_value = create_stream() |
| 181 | + |
| 182 | + cfg = MessageSendConfiguration( |
| 183 | + history_length=0, |
| 184 | + blocking=True, |
| 185 | + accepted_output_modes=['text/plain'], |
| 186 | + ) |
| 187 | + events = [ |
| 188 | + event |
| 189 | + async for event in base_client.send_message( |
| 190 | + sample_message, configuration=cfg |
| 191 | + ) |
| 192 | + ] |
| 193 | + |
| 194 | + mock_transport.send_message_streaming.assert_called_once() |
| 195 | + assert not mock_transport.send_message.called |
| 196 | + assert len(events) == 1 |
| 197 | + task, _ = events[0] |
| 198 | + assert task.id == 'task-cfg-s-1' |
| 199 | + |
| 200 | + params = mock_transport.send_message_streaming.call_args[0][0] |
| 201 | + assert params.configuration.history_length == 0 |
| 202 | + assert params.configuration.blocking is True |
| 203 | + assert params.configuration.accepted_output_modes == ['text/plain'] |
0 commit comments