|
| 1 | +import asyncio |
| 2 | +from typing import Any, List, Optional, Union |
| 3 | + |
| 4 | +from mcp_agent.llm.augmented_llm import ( |
| 5 | + MessageParamT, |
| 6 | + RequestParams, |
| 7 | +) |
| 8 | +from mcp_agent.llm.augmented_llm_passthrough import PassthroughLLM |
| 9 | +from mcp_agent.llm.provider_types import Provider |
| 10 | +from mcp_agent.mcp.prompt_message_multipart import PromptMessageMultipart |
| 11 | + |
| 12 | + |
| 13 | +class SlowLLM(PassthroughLLM): |
| 14 | + """ |
| 15 | + A specialized LLM implementation that sleeps for 3 seconds before responding like PassthroughLLM. |
| 16 | +
|
| 17 | + This is useful for testing scenarios where you want to simulate slow responses |
| 18 | + or for debugging timing-related issues in parallel workflows. |
| 19 | + """ |
| 20 | + |
| 21 | + def __init__( |
| 22 | + self, provider=Provider.FAST_AGENT, name: str = "Slow", **kwargs: dict[str, Any] |
| 23 | + ) -> None: |
| 24 | + super().__init__(name=name, provider=provider, **kwargs) |
| 25 | + |
| 26 | + async def generate_str( |
| 27 | + self, |
| 28 | + message: Union[str, MessageParamT, List[MessageParamT]], |
| 29 | + request_params: Optional[RequestParams] = None, |
| 30 | + ) -> str: |
| 31 | + """Sleep for 3 seconds then return the input message as a string.""" |
| 32 | + await asyncio.sleep(3) |
| 33 | + return await super().generate_str(message, request_params) |
| 34 | + |
| 35 | + async def _apply_prompt_provider_specific( |
| 36 | + self, |
| 37 | + multipart_messages: List["PromptMessageMultipart"], |
| 38 | + request_params: RequestParams | None = None, |
| 39 | + ) -> PromptMessageMultipart: |
| 40 | + """Sleep for 3 seconds then apply prompt like PassthroughLLM.""" |
| 41 | + await asyncio.sleep(3) |
| 42 | + return await super()._apply_prompt_provider_specific(multipart_messages, request_params) |
0 commit comments