[Parked pending adopter evidence] Support user-defined execution phases
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 9
- Forks
- 17
- Avg merge
- 21h 36m
- Merged PRs (30d)
- 22
Description
Summary
Allow callers to define custom execution phases (e.g. plan, critique, reflect, summarize) with their own token budgets and candidate-scope preferences, while keeping the four built-in phases as defaults.
Why this matters
The phase-specific budget is contextweaver's core differentiator, but real agent loops increasingly have more than four phases (planner/critic loops, reflection steps, sub-agent handoffs). Today Phase is a closed str Enum, so a planner step must masquerade as route or answer, inheriting the wrong budget and scope preferences. Opening the phase vocabulary makes the library fit modern agent architectures without forking.
Current evidence
src/contextweaver/types.py:45-51—Phase(str, Enum)with exactly four members.src/contextweaver/config.py—ContextBudgetkeyed by these phases.src/contextweaver/context/memory_types.py—PHASE_SCOPE_PREFERENCESconstants are keyed by the same four phases.docs/concepts.mdand README document the 4-phase loop as the model.
External context
Agent frameworks (LangGraph nodes, CrewAI task stages, OpenAI Agents SDK handoffs) model arbitrary named stages; a context compiler that only knows four stage names creates an impedance mismatch at integration boundaries.
Proposed implementation
- Design decision first: either (a) widen APIs to accept
Phase | strwith a registry ofPhaseSpec(name, budget, scope_preferences, kind_priorities), or (b) keepPhasefor built-ins and addContextManager.register_phase(PhaseSpec). Prefer (b): explicit registry, no enum changes. - Add
PhaseSpecdataclass (budget default, scope preference, optional kind-priority overrides) inconfig.pyor a new small module respecting the ≤300-line rule. - Thread custom phases through
ContextBudget,context/candidates.py(scope selection),context/build.py, and thebuild/build_syncsignatures (phase: Phase | str). - Keep serialization stable: phases serialize as strings already (
strEnum), soto_dictpaths mostly work; verify schema impact (_schema_gen.pyenum handling). - CLI:
replay --phaseshould accept registered custom phase names.
AI-agent execution notes
- Inspect first:
types.py,config.py,context/candidates.py,context/build.py,context/memory_types.py,_schema_gen.py(enum → JSON Schema),tests/test_manager.py,tests/test_config.py. - Edge cases: unknown phase name →
ConfigError; custom phase with no budget → documented default;PHASE_SCOPE_PREFERENCESfallback for unregistered phases. - Do not reorder pipeline stages; do not change defaults for the four built-in phases (byte-stable outputs for existing tests).
Acceptance criteria
- A registered custom phase can be passed to
build_sync(phase="plan", ...)and receives its own budget and scope preference. - All existing 4-phase behavior is byte-identical (regression tests pass unchanged).
- Unknown/unregistered phase names raise
ConfigErrorwith the available names listed. - Schemas (
schemas/,docs/schemas/v0/) regenerate cleanly and CIschemas-checkpasses.
Test plan
New tests/test_config.py/tests/test_manager.py cases (registration, budgets, scope fallback, error path); serde round-trip with a custom phase; CLI replay test with a custom phase; full make ci.
Documentation plan
docs/concepts.md Phase section, docs/quickstart.md advanced snippet, AGENTS.md key-types note, CHANGELOG.md.
Migration and compatibility notes
Additive. Built-in enum stays; existing payloads unaffected. If option (a) is chosen instead, audit all Phase isinstance checks before widening — flag any behavioral change in the PR.
Risks and tradeoffs
Widening a closed enum risks stringly-typed sprawl; the registry approach contains it. Custom phases increase the test matrix — document that built-ins remain the supported happy path. Alternative: keep enum closed and document "map your stages onto the four phases" (rejected: real adopter friction).
Suggested labels
product, architecture, developer-experience
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading src/contextweaver/types.py, config.py, context/candidates.py, context/build.py, context/memory_types.py, and _schema_gen.py, then inspect tests/test_manager.py and tests/test_config.py. The design choice between a registry and widened APIs must be resolved first; done means custom phases work without changing built-in outputs, schemas and CLI behavior remain valid, and the listed regression and CI checks pass.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- ai-infra-agents, developer-experience
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100