|
12 | 12 | from functools import wraps
|
13 | 13 | from pathlib import Path
|
14 | 14 | from typing import cast
|
15 |
| -from unittest.mock import AsyncMock, patch |
| 15 | +from unittest.mock import AsyncMock, MagicMock, patch |
16 | 16 | from uuid import uuid4
|
17 | 17 |
|
18 | 18 | import ldp.agent
|
@@ -466,15 +466,27 @@ async def llm_model_call(*args, **kwargs):
|
466 | 466 | @pytest.mark.asyncio
|
467 | 467 | async def test_timeout(agent_test_settings: Settings, agent_type: str | type) -> None:
|
468 | 468 | agent_test_settings.prompts.pre = None
|
469 |
| - agent_test_settings.agent.timeout = 0.001 |
| 469 | + agent_test_settings.agent.timeout = 0.05 # Give time for Environment.reset() |
470 | 470 | agent_test_settings.llm = "gpt-4o-mini"
|
471 | 471 | agent_test_settings.agent.tool_names = {"gen_answer", "complete"}
|
472 |
| - response = await agent_query( |
473 |
| - query="Are COVID-19 vaccines effective?", |
474 |
| - settings=agent_test_settings, |
475 |
| - agent_type=agent_type, |
476 |
| - ) |
477 |
| - # ensure that GenerateAnswerTool was called |
| 472 | + docs = Docs() |
| 473 | + |
| 474 | + async def custom_aget_evidence(*_, **kwargs) -> PQASession: # noqa: RUF029 |
| 475 | + return kwargs["query"] |
| 476 | + |
| 477 | + with ( |
| 478 | + patch.object(docs, "docs", {"stub_key": MagicMock(spec_set=Doc)}), |
| 479 | + patch.multiple( |
| 480 | + Docs, clear_docs=MagicMock(), aget_evidence=custom_aget_evidence |
| 481 | + ), |
| 482 | + ): |
| 483 | + response = await agent_query( |
| 484 | + query="Are COVID-19 vaccines effective?", |
| 485 | + settings=agent_test_settings, |
| 486 | + docs=docs, |
| 487 | + agent_type=agent_type, |
| 488 | + ) |
| 489 | + # Ensure that GenerateAnswerTool was called in truncation's failover |
478 | 490 | assert response.status == AgentStatus.TRUNCATED, "Agent did not timeout"
|
479 | 491 | assert CANNOT_ANSWER_PHRASE in response.session.answer
|
480 | 492 |
|
|
0 commit comments