Skip to content

Collapse orphaned 1,983-line memory/workflows.py duplicate into a backward-compatible re-export shim #2136

Description

@MervinPraison

Summary

praisonaiagents/memory/workflows.py (1,983 lines) is a stale, standalone re-implementation of the canonical workflow engine that already lives in praisonaiagents/workflows/workflows.py. It is no longer reachable through any public API path — every production import already resolves to praisonaiagents.workflows. This is duplicate logic (and wrong-layer: a full workflow engine sitting under memory/) that can be reduced to a thin re-export shim with no behaviour change and no loss of the backward-compatible import path.

Current behaviour

  • praisonaiagents/memory/workflows.py defines full standalone copies of Workflow (line 182), WorkflowManager (line 720, ~1,250 lines), WorkflowContext, StepResult, Route, Parallel, Loop, Repeat, route/parallel/loop/repeat, and create_workflow_manager (line 1969).
  • The canonical copy of every one of those symbols lives in praisonaiagents/workflows/workflows.py.
  • memory/__init__.py already re-exports each workflow name from ..workflows (the canonical package), e.g. line 96 from ..workflows import WorkflowManager, line 99 from ..workflows import Workflow, line 155 from ..workflows.workflows import create_workflow_manager. It never imports its sibling .workflows module.
  • The top-level praisonaiagents/__init__.py maps all workflow symbols to 'praisonaiagents.workflows'.
  • memory/workflows.py is the older subset: it lacks AgentFlow, If, Include, when, if_, include that the canonical module now provides — so any code reaching it would silently get a less capable engine.
  • A repository-wide search confirms no production module imports memory.workflows. The only importers are two backward-compatibility tests:
    • tests/test_workflow_patterns.py:462 (from praisonaiagents.memory.workflows import ..., docstring: "still work")
    • tests/unit/test_paths_wiring.py:407

Why it matters

Maintenance: ~1,980 lines of duplicated WorkflowManager/Workflow/pattern logic must be kept in sync by hand. Because the duplicate is the older subset, the two copies have already diverged — a latent correctness risk if anything ever resolves to the memory copy. Independently confirmed by two reviewers.

Category

Duplicate / Dead code / Wrong layer

Capability preserved

  • The praisonaiagents.memory.workflows import path keeps resolving (both backward-compat tests stay green).
  • Every workflow symbol (Workflow, WorkflowManager, Route, Parallel, Loop, Repeat, route, parallel, loop, repeat, create_workflow_manager, WorkflowContext, StepResult, Pipeline) remains importable from memory.workflows.
  • All public workflow behaviour is unchanged — it already runs through praisonaiagents.workflows.
  • Path wiring assertions in test_paths_wiring.py continue to hold (canonical WorkflowManager uses the same DEFAULT_DIR_NAME / WORKFLOWS_DIR / _get_checkpoints_dir wiring).

Proposed approach

Replace the 1,983-line body of memory/workflows.py with a re-export shim pointing at the canonical module:

Resolution sketch

# Before: memory/workflows.py — 1,983 lines re-implementing the engine
class WorkflowManager: ...   # ~1,250 lines
class Workflow: ...
class Route: ...
# ...etc

# After: memory/workflows.py — thin backward-compat shim
from ..workflows.workflows import (  # noqa: F401
    Workflow, WorkflowManager, WorkflowContext, StepResult,
    Route, Parallel, Loop, Repeat, route, parallel, loop, repeat,
    create_workflow_manager,
)
Pipeline = Workflow  # preserve legacy alias

Severity

Medium

Validation

  • Traced: no production module imports memory.workflows; only tests/test_workflow_patterns.py:462 and tests/unit/test_paths_wiring.py:407 (both backward-compat checks).
  • Confirmed memory/__init__.py and top-level __init__.py route every workflow name to praisonaiagents.workflows, not the memory copy.
  • Cross-confirmed by two independent reviewers.
  • No public API removed; the legacy import path is retained via the shim.

Keep unchanged

  • The canonical praisonaiagents/workflows/workflows.py engine — single source of truth, do not touch.
  • memory/__init__.py workflow re-exports (already correct).
  • Both backward-compat tests (they should keep passing against the shim).

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingclaudeAuto-trigger Claude analysisdocumentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions