Summary
praisonaiagents/agent/agent.py is 8,915 lines with 189 methods. Decompose into focused mixins while maintaining 100% backward compatibility.
Current State
Existing mixins already extracted: chat_handler.py, tool_execution.py, session_manager.py, autonomy.py. But agent.py still has 8,915 lines.
Requirements
Round 1 — Extract chat/LLM methods → agent/chat_mixin.py
Move these methods from agent.py into a new ChatMixin class:
chat(), achat(), _process_agent_output(), _format_response(), _handle_tool_calls(), all streaming-related methods
- Agent class inherits from ChatMixin
- Target: ~1500 lines extracted
Round 2 — Extract run/execution methods → agent/execution_mixin.py
Move: run(), arun(), start(), astart(), run_until(), related helpers
- Target: ~1200 lines extracted
Round 3 — Extract memory/cache methods → agent/memory_mixin.py
Move: _cache_put(), _cache_get(), _add_to_chat_history(), _truncate_chat_history(), related methods
- Target: ~500 lines extracted
Architecture Rules (MUST follow)
- Use
from praisonaiagents._logging import get_logger for logging (NOT logging.getLogger)
- Agent class MUST remain the single public API — users import
from praisonaiagents import Agent
- All 34
__init__ params MUST remain unchanged
- All existing public methods MUST remain on Agent (via mixin inheritance)
- Zero features removed. 100% backward compatible.
- Type hints preserved on all methods
Verification (MUST run before creating PR)
# All tests must pass
pytest tests/unit/ -q --timeout=30
pytest tests/integration/test_agent_decomposition_real.py -v
# Real agentic test
python -c "
from praisonaiagents import Agent
agent = Agent(name=\"test\", instructions=\"You are helpful\")
result = agent.start(\"Say hello in one sentence\")
print(result)
"
# Import time check
python -c "import time; t=time.time(); import praisonaiagents; print(f'{(time.time()-t)*1000:.0f}ms')"
Success Criteria
Replaces old PR #977 approach. References issue #1161.
Summary
praisonaiagents/agent/agent.pyis 8,915 lines with 189 methods. Decompose into focused mixins while maintaining 100% backward compatibility.Current State
Existing mixins already extracted:
chat_handler.py,tool_execution.py,session_manager.py,autonomy.py. But agent.py still has 8,915 lines.Requirements
Round 1 — Extract chat/LLM methods →
agent/chat_mixin.pyMove these methods from agent.py into a new ChatMixin class:
chat(),achat(),_process_agent_output(),_format_response(),_handle_tool_calls(), all streaming-related methodsRound 2 — Extract run/execution methods →
agent/execution_mixin.pyMove:
run(),arun(),start(),astart(),run_until(), related helpersRound 3 — Extract memory/cache methods →
agent/memory_mixin.pyMove:
_cache_put(),_cache_get(),_add_to_chat_history(),_truncate_chat_history(), related methodsArchitecture Rules (MUST follow)
from praisonaiagents._logging import get_loggerfor logging (NOTlogging.getLogger)from praisonaiagents import Agent__init__params MUST remain unchangedVerification (MUST run before creating PR)
Success Criteria
__init__params removedReplaces old PR #977 approach. References issue #1161.