diff --git a/config.template.toml b/config.template.toml index 4da00e5df0..744dfc7953 100644 --- a/config.template.toml +++ b/config.template.toml @@ -234,6 +234,10 @@ codeact_enable_jupyter = true # List of microagents to disable #disabled_microagents = [] +# Whether history should be truncated to continue the session when hitting LLM context +# length limit +enable_history_truncation = true + [agent.RepoExplorerAgent] # Example: use a cheaper model for RepoExplorerAgent to reduce cost, especially # useful when an agent doesn't demand high quality but uses a lot of tokens diff --git a/docs/modules/usage/configuration-options.md b/docs/modules/usage/configuration-options.md index 90050765d6..f1f2f44ef5 100644 --- a/docs/modules/usage/configuration-options.md +++ b/docs/modules/usage/configuration-options.md @@ -340,6 +340,11 @@ The agent configuration options are defined in the `[agent]` and `[agent. 1 and not self.has_errored: + error = ContextWindowExceededError( + message='prompt is too long: 233885 tokens > 200000 maximum', + model='', + llm_provider='', + ) + self.has_errored = True + raise error + + return MessageAction(content=f'STEP {len(state.history)}') + + step_state = StepState() + mock_agent.step = step_state.step + mock_agent.config = AgentConfig() + mock_agent.config.enable_history_truncation = False + + try: + state = await asyncio.wait_for( + run_controller( + config=AppConfig(max_iterations=3), + initial_user_action=MessageAction(content='INITIAL'), + runtime=mock_runtime, + sid='test', + agent=mock_agent, + fake_user_response_fn=lambda _: 'repeat', + ), + timeout=10, + ) + + # A timeout error indicates the run_controller entrypoint is not making + # progress + except asyncio.TimeoutError as e: + raise AssertionError( + 'The run_controller function did not complete in time.' + ) from e + + # Hitting the iteration limit indicates the controller is failing for the + # expected reason + assert state.iteration == 2 + assert state.agent_state == AgentState.ERROR + assert ( + state.last_error + == 'LLMContextWindowExceedError: Conversation history longer than LLM context window limit. Consider turning on enable_history_truncation config to avoid this error' + ) + + # Check that the context window exceeded error was raised during the run + assert step_state.has_errored