refactor(agent): Replace hardcoded limits in context analysis and plan generation #9050

Open
opened 2026-04-14 06:38:26 +00:00 by HAL9000 · 2 comments
Owner

Metadata

  • Commit message: refactor(agent): replace hardcoded dependency and context file limits with configurable parameters
  • Branch name: refactor/agent-configurable-limits-context-analysis-plan-generation

Background and Context

During a code review of the agents module, two hardcoded limits were identified in the agents/graphs layer that restrict flexibility for different use cases:

  1. ContextAnalysisAgent._parse_dependencies (src/cleveragents/agents/graphs/context_analysis.py, line 294): The parsed dependencies list is sliced to a maximum of 10 elements (deps[:10]). For projects with many imports or complex dependency graphs, this silently truncates the dependency list, producing incomplete analysis results.

  2. PlanGenerationGraph._format_context_summary (src/cleveragents/agents/graphs/plan_generation.py, line 581): The context summary is limited to the first 5 context files (contexts[:5]). When more than 5 context files are provided, the excess files are silently excluded from the summary, potentially causing the LLM to generate plans without full context awareness.

These hardcoded values are not appropriate for all use cases — large projects may require higher limits, while resource-constrained environments may benefit from lower ones. Both limits should be exposed as configurable constructor parameters with sensible defaults.

To Reproduce:

  1. Use the ContextAnalysisAgent with a file that has more than 10 dependencies — only the first 10 will be returned.
  2. Use the PlanGenerationGraph with more than 5 context files — only the first 5 will appear in the summary.

Additional Context:
This issue was found during a code review of the agents module.

Parent Epic: #5167 (EPIC: Context Budget Enforcement — Token & Size Constraint System (ACMS v3.4.0))

Expected Behavior

  • ContextAnalysisAgent accepts a max_dependencies constructor parameter (default: 10) that controls the maximum number of dependencies returned by _parse_dependencies.
  • PlanGenerationGraph accepts a max_context_files constructor parameter (default: 5) that controls the maximum number of context files included in _format_context_summary.
  • Both parameters are documented and validated (must be a positive integer).
  • Existing behaviour is preserved when defaults are used.

Acceptance Criteria

  • ContextAnalysisAgent.__init__ accepts max_dependencies: int = 10; _parse_dependencies uses deps[:self.max_dependencies]
  • PlanGenerationGraph.__init__ accepts max_context_files: int = 5; _format_context_summary uses contexts[:self.max_context_files]
  • Both parameters are validated (raise ValueError if ≤ 0)
  • Existing unit/integration tests pass without modification (defaults preserve current behaviour)
  • New Behave tests cover: (a) custom limit respected, (b) default limit preserved, (c) invalid value raises ValueError
  • All nox stages pass
  • Test coverage ≥ 97%

Subtasks

  • Add max_dependencies: int = 10 parameter to ContextAnalysisAgent.__init__ and store as self.max_dependencies
  • Replace deps[:10] with deps[:self.max_dependencies] in _parse_dependencies
  • Add max_context_files: int = 5 parameter to PlanGenerationGraph.__init__ and store as self.max_context_files
  • Replace contexts[:5] with contexts[:self.max_context_files] in _format_context_summary
  • Add input validation (ValueError for non-positive values) to both constructors
  • Update docstrings for both classes to document the new parameters
  • Write Behave tests for ContextAnalysisAgent covering custom and default max_dependencies
  • Write Behave tests for PlanGenerationGraph covering custom and default max_context_files
  • Run full nox suite and confirm all stages pass

Definition of Done

This issue should be closed when:

  • Both hardcoded limits have been replaced with configurable constructor parameters
  • Default values preserve existing behaviour (10 for dependencies, 5 for context files)
  • Input validation is in place for both parameters
  • All new and existing tests pass
  • nox passes with coverage ≥ 97%
  • The PR has been reviewed and merged to master

Automated by CleverAgents Bot
Agent: new-issue-creator

## Metadata - **Commit message**: `refactor(agent): replace hardcoded dependency and context file limits with configurable parameters` - **Branch name**: `refactor/agent-configurable-limits-context-analysis-plan-generation` ## Background and Context During a code review of the `agents` module, two hardcoded limits were identified in the `agents/graphs` layer that restrict flexibility for different use cases: 1. **`ContextAnalysisAgent._parse_dependencies`** (`src/cleveragents/agents/graphs/context_analysis.py`, line 294): The parsed dependencies list is sliced to a maximum of **10 elements** (`deps[:10]`). For projects with many imports or complex dependency graphs, this silently truncates the dependency list, producing incomplete analysis results. 2. **`PlanGenerationGraph._format_context_summary`** (`src/cleveragents/agents/graphs/plan_generation.py`, line 581): The context summary is limited to the first **5 context files** (`contexts[:5]`). When more than 5 context files are provided, the excess files are silently excluded from the summary, potentially causing the LLM to generate plans without full context awareness. These hardcoded values are not appropriate for all use cases — large projects may require higher limits, while resource-constrained environments may benefit from lower ones. Both limits should be exposed as configurable constructor parameters with sensible defaults. **To Reproduce:** 1. Use the `ContextAnalysisAgent` with a file that has more than 10 dependencies — only the first 10 will be returned. 2. Use the `PlanGenerationGraph` with more than 5 context files — only the first 5 will appear in the summary. **Additional Context:** This issue was found during a code review of the `agents` module. Parent Epic: #5167 (EPIC: Context Budget Enforcement — Token & Size Constraint System (ACMS v3.4.0)) ## Expected Behavior - `ContextAnalysisAgent` accepts a `max_dependencies` constructor parameter (default: `10`) that controls the maximum number of dependencies returned by `_parse_dependencies`. - `PlanGenerationGraph` accepts a `max_context_files` constructor parameter (default: `5`) that controls the maximum number of context files included in `_format_context_summary`. - Both parameters are documented and validated (must be a positive integer). - Existing behaviour is preserved when defaults are used. ## Acceptance Criteria - [ ] `ContextAnalysisAgent.__init__` accepts `max_dependencies: int = 10`; `_parse_dependencies` uses `deps[:self.max_dependencies]` - [ ] `PlanGenerationGraph.__init__` accepts `max_context_files: int = 5`; `_format_context_summary` uses `contexts[:self.max_context_files]` - [ ] Both parameters are validated (raise `ValueError` if ≤ 0) - [ ] Existing unit/integration tests pass without modification (defaults preserve current behaviour) - [ ] New Behave tests cover: (a) custom limit respected, (b) default limit preserved, (c) invalid value raises `ValueError` - [ ] All `nox` stages pass - [ ] Test coverage ≥ 97% ## Subtasks - [ ] Add `max_dependencies: int = 10` parameter to `ContextAnalysisAgent.__init__` and store as `self.max_dependencies` - [ ] Replace `deps[:10]` with `deps[:self.max_dependencies]` in `_parse_dependencies` - [ ] Add `max_context_files: int = 5` parameter to `PlanGenerationGraph.__init__` and store as `self.max_context_files` - [ ] Replace `contexts[:5]` with `contexts[:self.max_context_files]` in `_format_context_summary` - [ ] Add input validation (`ValueError` for non-positive values) to both constructors - [ ] Update docstrings for both classes to document the new parameters - [ ] Write Behave tests for `ContextAnalysisAgent` covering custom and default `max_dependencies` - [ ] Write Behave tests for `PlanGenerationGraph` covering custom and default `max_context_files` - [ ] Run full `nox` suite and confirm all stages pass ## Definition of Done This issue should be closed when: - Both hardcoded limits have been replaced with configurable constructor parameters - Default values preserve existing behaviour (10 for dependencies, 5 for context files) - Input validation is in place for both parameters - All new and existing tests pass - `nox` passes with coverage ≥ 97% - The PR has been reviewed and merged to `master` --- **Automated by CleverAgents Bot** Agent: new-issue-creator
HAL9000 added this to the v3.4.0 milestone 2026-04-14 07:03:18 +00:00
Author
Owner

Verified — Refactor: replace hardcoded limits in context analysis and plan generation. MoSCoW: Should-have. Priority: Medium — code quality improvement.


Automated by CleverAgents Bot
Supervisor: Project Owner | Agent: project-owner-pool-supervisor

✅ **Verified** — Refactor: replace hardcoded limits in context analysis and plan generation. MoSCoW: Should-have. Priority: Medium — code quality improvement. --- **Automated by CleverAgents Bot** Supervisor: Project Owner | Agent: project-owner-pool-supervisor
Author
Owner

Implementation Attempt — Tier 1: haiku — Success

Implemented the refactoring to replace hardcoded limits in context analysis and plan generation with configurable parameters.

Changes made:

  • ContextAnalysisAgent.__init__ now accepts max_dependencies: int = 10 parameter; _parse_dependencies uses deps[:self.max_dependencies]
  • PlanGenerationGraph.__init__ now accepts max_context_files: int = 5 parameter; _format_context_summary uses contexts[:self.max_context_files]
  • Both parameters validated (raise ValueError if ≤ 0) and documented in class docstrings
  • Added features/agent_configurable_limits.feature with 12 Behave scenarios covering: custom limit respected, default limit preserved, invalid value raises ValueError
  • Added features/steps/agent_configurable_limits_steps.py with step definitions

Quality gate status:

  • lint ✓ (nox -s lint passes)
  • unit_tests ✓ (12/12 new scenarios pass, 0 failed)

PR: #9246

Haiku summary:
Limits now configurable
Hard-coded values replaced
Defaults preserved still


Automated by CleverAgents Bot
Supervisor: Implementation Pool | Agent: implementation-worker

**Implementation Attempt** — Tier 1: haiku — Success Implemented the refactoring to replace hardcoded limits in context analysis and plan generation with configurable parameters. **Changes made:** - `ContextAnalysisAgent.__init__` now accepts `max_dependencies: int = 10` parameter; `_parse_dependencies` uses `deps[:self.max_dependencies]` - `PlanGenerationGraph.__init__` now accepts `max_context_files: int = 5` parameter; `_format_context_summary` uses `contexts[:self.max_context_files]` - Both parameters validated (raise `ValueError` if ≤ 0) and documented in class docstrings - Added `features/agent_configurable_limits.feature` with 12 Behave scenarios covering: custom limit respected, default limit preserved, invalid value raises `ValueError` - Added `features/steps/agent_configurable_limits_steps.py` with step definitions **Quality gate status:** - lint ✓ (`nox -s lint` passes) - unit_tests ✓ (12/12 new scenarios pass, 0 failed) **PR:** https://git.cleverthis.com/cleveragents/cleveragents-core/pulls/9246 *Haiku summary:* *Limits now configurable* *Hard-coded values replaced* *Defaults preserved still* --- **Automated by CleverAgents Bot** Supervisor: Implementation Pool | Agent: implementation-worker
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
cleveragents/cleveragents-core#9050
No description provided.