π OpenHands: AI-Driven Development
Remove MAX_CHARS traffic control (#2694)
Boxuan Lie45b311c358e
diff --git a/agenthub/codeact_agent/codeact_agent.py b/agenthub/codeact_agent/codeact_agent.pyindex 5e92c859f9..22515f1105 100644--- a/agenthub/codeact_agent/codeact_agent.py+++ b/agenthub/codeact_agent/codeact_agent.py@@ -226,9 +226,6 @@ class CodeActAgent(Agent):],temperature=0.0,)- state.num_of_chars += sum(- len(message['content']) for message in messages- ) + len(response.choices[0].message.content)return self.action_parser.parse(response)def search_memory(self, query: str) -> list[str]:diff --git a/agenthub/codeact_swe_agent/codeact_swe_agent.py b/agenthub/codeact_swe_agent/codeact_swe_agent.pyindex 358918d322..c31f6d7f2a 100644--- a/agenthub/codeact_swe_agent/codeact_swe_agent.py+++ b/agenthub/codeact_swe_agent/codeact_swe_agent.py@@ -181,9 +181,6 @@ class CodeActSWEAgent(Agent):],temperature=0.0,)- state.num_of_chars += sum(- len(message['content']) for message in messages- ) + len(response.choices[0].message.content)return self.response_parser.parse(response)diff --git a/agenthub/micro/agent.py b/agenthub/micro/agent.pyindex 866e21d4a0..863a6d3ad8 100644--- a/agenthub/micro/agent.py+++ b/agenthub/micro/agent.py@@ -66,7 +66,6 @@ class MicroAgent(Agent):messages = [{'content': prompt, 'role': 'user'}]resp = self.llm.completion(messages=messages)action_resp = resp['choices'][0]['message']['content']- state.num_of_chars += len(prompt) + len(action_resp)action = parse_response(action_resp)return actiondiff --git a/agenthub/monologue_agent/agent.py b/agenthub/monologue_agent/agent.pyindex 1919f452b4..e3b4cf698c 100644--- a/agenthub/monologue_agent/agent.py+++ b/agenthub/monologue_agent/agent.py@@ -183,11 +183,6 @@ class MonologueAgent(Agent):# format all as a single message, a monologueresp = self.llm.completion(messages=messages)- # keep track of max_chars fallback option- state.num_of_chars += len(prompt) + len(- resp['choices'][0]['message']['content']- )-action = self.response_parser.parse(resp)self.latest_action = actionreturn actiondiff --git a/agenthub/planner_agent/agent.py b/agenthub/planner_agent/agent.pyindex 68032b8c0f..1f3d475cbd 100644--- a/agenthub/planner_agent/agent.py+++ b/agenthub/planner_agent/agent.py@@ -48,9 +48,6 @@ class PlannerAgent(Agent):prompt = get_prompt(state)messages = [{'content': prompt, 'role': 'user'}]resp = self.llm.completion(messages=messages)- state.num_of_chars += len(prompt) + len(- resp['choices'][0]['message']['content']- )return self.response_parser.parse(resp)def search_memory(self, query: str) -> list[str]:diff --git a/opendevin/controller/agent_controller.py b/opendevin/controller/agent_controller.pyindex 8577fd058b..b81f792640 100644--- a/opendevin/controller/agent_controller.py+++ b/opendevin/controller/agent_controller.py@@ -9,7 +9,6 @@ from opendevin.core.exceptions import (LLMMalformedActionError,LLMNoActionError,LLMResponseError,- MaxCharsExceedError,)from opendevin.core.logger import opendevin_logger as loggerfrom opendevin.core.schema import AgentState@@ -37,7 +36,6 @@ from opendevin.events.observation import ()MAX_ITERATIONS = config.max_iterations-MAX_CHARS = config.llm.max_charsMAX_BUDGET_PER_TASK = config.max_budget_per_task@@ -58,7 +56,6 @@ class AgentController:event_stream: EventStream,sid: str = 'default',max_iterations: int = MAX_ITERATIONS,- max_chars: int = MAX_CHARS,max_budget_per_task: float | None = MAX_BUDGET_PER_TASK,initial_state: State | None = None,is_delegate: bool = False,@@ -70,7 +67,6 @@ class AgentController:event_stream: The event stream to publish events to.sid: The session ID of the agent.max_iterations: The maximum number of iterations the agent can run.- max_chars: The maximum number of characters the agent can output.max_budget_per_task: The maximum budget (in USD) allowed per task, beyond which the agent will stop.initial_state: The initial state of the controller.is_delegate: Whether this controller is a delegate.@@ -78,7 +74,6 @@ class AgentController:self._step_lock = asyncio.Lock()self.id = sidself.agent = agent- self.max_chars = max_charsif initial_state is None:self.state = State(inputs={}, max_iterations=max_iterations)else:@@ -224,7 +219,6 @@ class AgentController:inputs=action.inputs or {},iteration=0,max_iterations=self.state.max_iterations,- num_of_chars=self.state.num_of_chars,delegate_level=self.state.delegate_level + 1,# metrics should be shared between parent and childmetrics=self.state.metrics,@@ -235,7 +229,6 @@ class AgentController:agent=agent,event_stream=self.event_stream,max_iterations=self.state.max_iterations,- max_chars=self.max_chars,max_budget_per_task=self.max_budget_per_task,initial_state=state,is_delegate=True,@@ -298,9 +291,6 @@ class AgentController:await self.event_stream.add_event(obs, EventSource.AGENT)return- if self.state.num_of_chars > self.max_chars:- raise MaxCharsExceedError(self.state.num_of_chars, self.max_chars)-logger.info(f'{self.agent.name} LEVEL {self.state.delegate_level} STEP {self.state.iteration}',extra={'msg_type': 'STEP'},diff --git a/opendevin/controller/state/state.py b/opendevin/controller/state/state.pyindex 76eb05d9f6..d6053980b9 100644--- a/opendevin/controller/state/state.py+++ b/opendevin/controller/state/state.py@@ -29,8 +29,6 @@ class State:root_task: RootTask = field(default_factory=RootTask)iteration: int = 0max_iterations: int = 100- # number of characters we have sent to and received from LLM so far for current task- num_of_chars: int = 0background_commands_obs: list[CmdOutputObservation] = field(default_factory=list)history: list[tuple[Action, Observation]] = field(default_factory=list)updated_info: list[tuple[Action, Observation]] = field(default_factory=list)diff --git a/opendevin/core/config.py b/opendevin/core/config.pyindex 5f39dc7577..ee7d8b3993 100644--- a/opendevin/core/config.py+++ b/opendevin/core/config.py@@ -39,7 +39,6 @@ class LLMConfig(metaclass=Singleton):retry_min_wait: The minimum time to wait between retries, in seconds. This is exponential backoff minimum. For models with very low limits, this can be set to 15-20.retry_max_wait: The maximum time to wait between retries, in seconds. This is exponential backoff maximum.timeout: The timeout for the API.- max_chars: The maximum number of characters to send to and receive from the API. This is a fallback for token counting, which doesn't work in all cases.temperature: The temperature for the API.top_p: The top p for the API.custom_llm_provider: The custom LLM provider to use. This is undocumented in opendevin, and normally not used. It is documented on the litellm side.@@ -63,7 +62,6 @@ class LLMConfig(metaclass=Singleton):retry_min_wait: int = 3retry_max_wait: int = 60timeout: int | None = None- max_chars: int = 5_000_000 # fallback for token countingtemperature: float = 0top_p: float = 0.5custom_llm_provider: str | None = None@@ -523,13 +521,6 @@ def get_parser():type=float,help='The maximum budget allowed per task, beyond which the agent will stop.',)- parser.add_argument(- '-n',- '--max-chars',- default=config.llm.max_chars,- type=int,- help='The maximum number of characters to send to and receive from LLM per task',- )# --eval configs are for evaluations onlyparser.add_argument('--eval-output-dir',diff --git a/opendevin/core/exceptions.py b/opendevin/core/exceptions.pyindex d0b8a0f086..92064f409c 100644--- a/opendevin/core/exceptions.py+++ b/opendevin/core/exceptions.py@@ -1,12 +1,3 @@-class MaxCharsExceedError(Exception):- def __init__(self, num_of_chars=None, max_chars_limit=None):- if num_of_chars is not None and max_chars_limit is not None:- message = f'Number of characters {num_of_chars} exceeds MAX_CHARS limit: {max_chars_limit}'- else:- message = 'Number of characters exceeds MAX_CHARS limit'- super().__init__(message)--class AgentNoInstructionError(Exception):def __init__(self, message='Instruction must be provided'):super().__init__(message)diff --git a/opendevin/core/main.py b/opendevin/core/main.pyindex 5322e6c0c4..3cfa04d60a 100644--- a/opendevin/core/main.py+++ b/opendevin/core/main.py@@ -89,7 +89,6 @@ async def main(agent=agent,max_iterations=args.max_iterations,max_budget_per_task=args.max_budget_per_task,- max_chars=args.max_chars,event_stream=event_stream,)runtime = ServerRuntime(event_stream=event_stream, sandbox=sandbox)diff --git a/opendevin/core/schema/config.py b/opendevin/core/schema/config.pyindex 1bece3582e..4d210f49f7 100644--- a/opendevin/core/schema/config.py+++ b/opendevin/core/schema/config.py@@ -32,7 +32,6 @@ class ConfigType(str, Enum):AGENT_MEMORY_MAX_THREADS = 'AGENT_MEMORY_MAX_THREADS'AGENT_MEMORY_ENABLED = 'AGENT_MEMORY_ENABLED'MAX_ITERATIONS = 'MAX_ITERATIONS'- MAX_CHARS = 'MAX_CHARS'AGENT = 'AGENT'E2B_API_KEY = 'E2B_API_KEY'SANDBOX_TYPE = 'SANDBOX_TYPE'diff --git a/opendevin/server/session/agent.py b/opendevin/server/session/agent.pyindex b2b1720afc..3e074190e2 100644--- a/opendevin/server/session/agent.py+++ b/opendevin/server/session/agent.py@@ -91,7 +91,6 @@ class AgentSession:api_key = args.get(ConfigType.LLM_API_KEY, config.llm.api_key)api_base = config.llm.base_urlmax_iterations = args.get(ConfigType.MAX_ITERATIONS, config.max_iterations)- max_chars = args.get(ConfigType.MAX_CHARS, config.llm.max_chars)logger.info(f'Creating agent {agent_cls} using LLM {model}')llm = LLM(model=model, api_key=api_key, base_url=api_base)@@ -109,7 +108,6 @@ class AgentSession:event_stream=self.event_stream,agent=agent,max_iterations=int(max_iterations),- max_chars=int(max_chars),)try:agent_state = State.restore_from_session(self.sid)diff --git a/tests/unit/test_arg_parser.py b/tests/unit/test_arg_parser.pyindex 324536ed64..fa4041c9fb 100644--- a/tests/unit/test_arg_parser.py+++ b/tests/unit/test_arg_parser.py@@ -11,7 +11,7 @@ def test_help_message(capsys):expected_help_message = """usage: pytest [-h] [-d DIRECTORY] [-t TASK] [-f FILE] [-c AGENT_CLS][-m MODEL_NAME] [-i MAX_ITERATIONS] [-b MAX_BUDGET_PER_TASK]- [-n MAX_CHARS] [--eval-output-dir EVAL_OUTPUT_DIR]+ [--eval-output-dir EVAL_OUTPUT_DIR][--eval-n-limit EVAL_N_LIMIT][--eval-num-workers EVAL_NUM_WORKERS] [--eval-note EVAL_NOTE][-l LLM_CONFIG]@@ -34,9 +34,6 @@ options:-b MAX_BUDGET_PER_TASK, --max-budget-per-task MAX_BUDGET_PER_TASKThe maximum budget allowed per task, beyond which theagent will stop.- -n MAX_CHARS, --max-chars MAX_CHARS- The maximum number of characters to send to and- receive from LLM per task--eval-output-dir EVAL_OUTPUT_DIRThe directory to save evaluation output--eval-n-limit EVAL_N_LIMIT