🙌 OpenHands: AI-Driven Development
feat: Added RateLimitError status on UI and Agent state (#5910)
sai krishna rohith kef2053011dad
diff --git a/frontend/src/components/agent-status-map.constant.ts b/frontend/src/components/agent-status-map.constant.tsindex e3c0dcabd9..d0d68f0a47 100644--- a/frontend/src/components/agent-status-map.constant.ts+++ b/frontend/src/components/agent-status-map.constant.ts@@ -61,4 +61,8 @@ export const AGENT_STATUS_MAP: {message: I18nKey.CHAT_INTERFACE$AGENT_ACTION_USER_REJECTED_MESSAGE,indicator: IndicatorColor.RED,},+ [AgentState.RATE_LIMITED]: {+ message: I18nKey.CHAT_INTERFACE$AGENT_RATE_LIMITED_MESSAGE,+ indicator: IndicatorColor.YELLOW,+ },};diff --git a/frontend/src/components/features/chat/chat-interface.tsx b/frontend/src/components/features/chat/chat-interface.tsxindex 3a73ef77f9..eb934b69b9 100644--- a/frontend/src/components/features/chat/chat-interface.tsx+++ b/frontend/src/components/features/chat/chat-interface.tsx@@ -154,7 +154,8 @@ export function ChatInterface() {onStop={handleStop}isDisabled={curAgentState === AgentState.LOADING ||- curAgentState === AgentState.AWAITING_USER_CONFIRMATION+ curAgentState === AgentState.AWAITING_USER_CONFIRMATION ||+ curAgentState === AgentState.RATE_LIMITED}mode={curAgentState === AgentState.RUNNING ? "stop" : "submit"}value={messageToSend ?? undefined}diff --git a/frontend/src/i18n/translation.json b/frontend/src/i18n/translation.jsonindex 82fc449864..3707ba804b 100644--- a/frontend/src/i18n/translation.json+++ b/frontend/src/i18n/translation.json@@ -1196,6 +1196,20 @@"fr": "L'agent attend l'entrée de l'utilisateur...","tr": "Ajan kullanıcı girdisini bekliyor..."},+ "CHAT_INTERFACE$AGENT_RATE_LIMITED_MESSAGE": {+ "en": "Agent is Rate Limited",+ "zh-CN": "智能体已达到速率限制",+ "zh-TW": "智能體已達到速率限制",+ "de": "Agent ist ratenbegrenzt",+ "ko-KR": "에이전트가 속도 제한되었습니다",+ "no": "Agenten er hastighetsbegrenset",+ "it": "L'agente è limitato dalla frequenza",+ "pt": "O agente está com limite de taxa",+ "es": "El agente está limitado por tasa",+ "ar": "الوكيل مقيد بحد السرعة",+ "fr": "L'agent est limité en fréquence",+ "tr": "Ajan hız sınırına ulaştı"+ },"CHAT_INTERFACE$AGENT_PAUSED_MESSAGE": {"en": "Agent has paused.","de": "Agent pausiert.",diff --git a/frontend/src/types/agent-state.tsx b/frontend/src/types/agent-state.tsxindex 74988e4ef3..2ac3dbe3a9 100644--- a/frontend/src/types/agent-state.tsx+++ b/frontend/src/types/agent-state.tsx@@ -8,6 +8,7 @@ export enum AgentState {FINISHED = "finished",REJECTED = "rejected",ERROR = "error",+ RATE_LIMITED = "rate_limited",AWAITING_USER_CONFIRMATION = "awaiting_user_confirmation",USER_CONFIRMED = "user_confirmed",USER_REJECTED = "user_rejected",diff --git a/openhands/controller/agent_controller.py b/openhands/controller/agent_controller.pyindex 238f9e8ac1..743decc4df 100644--- a/openhands/controller/agent_controller.py+++ b/openhands/controller/agent_controller.py@@ -5,7 +5,11 @@ import tracebackfrom typing import Callable, ClassVar, Typeimport litellm-from litellm.exceptions import BadRequestError, ContextWindowExceededError+from litellm.exceptions import (+ BadRequestError,+ ContextWindowExceededError,+ RateLimitError,+)from openhands.controller.agent import Agentfrom openhands.controller.state.state import State, TrafficControlState@@ -192,6 +196,9 @@ class AgentController:err_id = ''if isinstance(e, litellm.AuthenticationError):err_id = 'STATUS$ERROR_LLM_AUTHENTICATION'+ elif isinstance(e, RateLimitError):+ await self.set_agent_state_to(AgentState.RATE_LIMITED)+ returnself.status_callback('error', err_id, type(e).__name__ + ': ' + str(e))def step(self):diff --git a/openhands/core/schema/agent.py b/openhands/core/schema/agent.pyindex 4ea09d7afc..366bc2c191 100644--- a/openhands/core/schema/agent.py+++ b/openhands/core/schema/agent.py@@ -49,3 +49,7 @@ class AgentState(str, Enum):USER_REJECTED = 'user_rejected'"""The user rejected the agent's action."""++ RATE_LIMITED = 'rate_limited'+ """The agent is rate limited.+ """