Refactor: Decompose context_fragment.py into smaller modules #4164

Closed
opened 2026-04-06 12:10:42 +00:00 by freemo · 1 comment
Owner

The src/cleveragents/domain/models/core/context_fragment.py file has been identified as a violation of the Single Responsibility Principle.

Issues:

The file mixes several distinct concerns:

  1. Data Models: FragmentProvenance, ContextFragment, ContextBudget, ContextPayload, and ScoredFragment.
  2. Business Logic: The compute_context_hash and build_provenance_map functions contain business logic for processing context fragments.

Recommendation:

Refactor the context_fragment.py file by splitting it into smaller, more focused modules:

  • Keep the data models in src/cleveragents/domain/models/core/context_fragment.py.
  • Move the helper functions (compute_context_hash, build_provenance_map) to the src/cleveragents/application layer, possibly in a new context package or a utils module.

This refactoring will improve the modularity, maintainability, and testability of the context fragment functionality.


Automated by CleverAgents Bot
Supervisor: Architecture Guard | Agent: ca-architecture-guard

The `src/cleveragents/domain/models/core/context_fragment.py` file has been identified as a violation of the Single Responsibility Principle. **Issues:** The file mixes several distinct concerns: 1. **Data Models:** `FragmentProvenance`, `ContextFragment`, `ContextBudget`, `ContextPayload`, and `ScoredFragment`. 2. **Business Logic:** The `compute_context_hash` and `build_provenance_map` functions contain business logic for processing context fragments. **Recommendation:** Refactor the `context_fragment.py` file by splitting it into smaller, more focused modules: * Keep the data models in `src/cleveragents/domain/models/core/context_fragment.py`. * Move the helper functions (`compute_context_hash`, `build_provenance_map`) to the `src/cleveragents/application` layer, possibly in a new `context` package or a `utils` module. This refactoring will improve the modularity, maintainability, and testability of the context fragment functionality. --- **Automated by CleverAgents Bot** Supervisor: Architecture Guard | Agent: ca-architecture-guard
Author
Owner

DUPLICATE: Consolidated into Epic #4179 "Code Architecture Cleanup - Single Responsibility Principle Violations"

This refactoring task for decomposing context_fragment.py into smaller modules is part of the broader architectural cleanup effort. All Single Responsibility Principle violation fixes are being tracked collectively in the epic.

Action: Closing as duplicate in favor of Epic #4179

**DUPLICATE**: Consolidated into Epic #4179 "Code Architecture Cleanup - Single Responsibility Principle Violations" This refactoring task for decomposing `context_fragment.py` into smaller modules is part of the broader architectural cleanup effort. All Single Responsibility Principle violation fixes are being tracked collectively in the epic. **Action**: Closing as duplicate in favor of Epic #4179
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#4164
No description provided.