Remove MAX_CHARS traffic control (#2694)

* Remove MAX_CHARS limiting

* More cleanup
This commit is contained in:
Boxuan Li 2024-06-29 12:59:41 -07:00 committed by GitHub
parent 75f3181c08
commit e45b311c35
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 1 additions and 53 deletions

View File

@ -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]:

View File

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

View File

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

View File

@ -183,11 +183,6 @@ class MonologueAgent(Agent):
# format all as a single message, a monologue
resp = 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 = action
return action

View File

@ -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]:

View File

@ -9,7 +9,6 @@ from opendevin.core.exceptions import (
LLMMalformedActionError,
LLMNoActionError,
LLMResponseError,
MaxCharsExceedError,
)
from opendevin.core.logger import opendevin_logger as logger
from opendevin.core.schema import AgentState
@ -37,7 +36,6 @@ from opendevin.events.observation import (
)
MAX_ITERATIONS = config.max_iterations
MAX_CHARS = config.llm.max_chars
MAX_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 = sid
self.agent = agent
self.max_chars = max_chars
if 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 child
metrics=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'},

View File

@ -29,8 +29,6 @@ class State:
root_task: RootTask = field(default_factory=RootTask)
iteration: int = 0
max_iterations: int = 100
# number of characters we have sent to and received from LLM so far for current task
num_of_chars: int = 0
background_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)

View File

@ -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 = 3
retry_max_wait: int = 60
timeout: int | None = None
max_chars: int = 5_000_000 # fallback for token counting
temperature: float = 0
top_p: float = 0.5
custom_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 only
parser.add_argument(
'--eval-output-dir',

View File

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

View File

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

View File

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

View File

@ -91,7 +91,6 @@ class AgentSession:
api_key = args.get(ConfigType.LLM_API_KEY, config.llm.api_key)
api_base = config.llm.base_url
max_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)

View File

@ -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_TASK
The maximum budget allowed per task, beyond which the
agent 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_DIR
The directory to save evaluation output
--eval-n-limit EVAL_N_LIMIT