Skip to content

Commit

Permalink
Use configuration system for max_input_tokens
Browse files Browse the repository at this point in the history
- Remove max_input_tokens parameter from AgentController constructor
- Use LLM configuration system to set max_input_tokens through config.toml or environment variables
- Update test to set max_input_tokens directly in LLM config

Users can now set max_input_tokens in two ways:
1. Through config.toml:
   [llm]
   max_input_tokens = 20000

2. Through environment variables:
   export LLM_MAX_INPUT_TOKENS=20000
  • Loading branch information
openhands-agent committed Nov 22, 2024
1 parent c329a2e commit 2d094fe
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
5 changes: 0 additions & 5 deletions openhands/controller/agent_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ def __init__(
is_delegate: bool = False,
headless_mode: bool = True,
status_callback: Callable | None = None,
max_input_tokens: int | None = None,
):
"""Initializes a new instance of the AgentController class.
Expand All @@ -112,10 +111,6 @@ def __init__(
self.agent = agent
self.headless_mode = headless_mode

# Set max input tokens if provided
if max_input_tokens is not None:
self.agent.llm.config.max_input_tokens = max_input_tokens

# subscribe to the event stream
self.event_stream = event_stream
self.event_stream.subscribe(
Expand Down
6 changes: 4 additions & 2 deletions tests/unit/test_truncation.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,16 +190,18 @@ def test_history_restoration_after_truncation(self, mock_event_stream, mock_agen
def test_context_window_parameter_truncation(self, mock_event_stream, mock_agent):
# Configure mock agent's LLM to return specific token counts
mock_agent.llm.get_token_count.return_value = 100

# Set max_input_tokens in LLM config
mock_agent.llm.config.max_input_tokens = 80

# Create controller with context window of 80 tokens
# Create controller
controller = AgentController(
agent=mock_agent,
event_stream=mock_event_stream,
max_iterations=10,
sid='test_truncation',
confirmation_mode=False,
headless_mode=True,
max_input_tokens=80,
)

# Create initial events
Expand Down

0 comments on commit 2d094fe

Please sign in to comment.