feat: Added RateLimitError status on UI and Agent state (#5910)

This commit is contained in:
sai krishna rohith k
2025-01-04 11:07:07 -06:00
committed by GitHub
parent e6499a68f6
commit ef2053011d
6 changed files with 33 additions and 2 deletions

View File

@@ -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,
},
};

View File

@@ -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}

View File

@@ -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.",

View File

@@ -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",

View File

@@ -5,7 +5,11 @@ import traceback
from typing import Callable, ClassVar, Type
import litellm
from litellm.exceptions import BadRequestError, ContextWindowExceededError
from litellm.exceptions import (
BadRequestError,
ContextWindowExceededError,
RateLimitError,
)
from openhands.controller.agent import Agent
from 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)
return
self.status_callback('error', err_id, type(e).__name__ + ': ' + str(e))
def step(self):

View File

@@ -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.
"""