[Refactor] Split conversational.py into Modular Structure #63
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Detailed Guideline for Refactoring conversational.py
Objective
Split
conversational.py(2271 lines) into modular files to improve:Current Structure
Target Structure
Implementation Steps
Phase 1: Create New Files
1.1 Create
tools.pyCheck: Verify imports still work (no circular imports)
1.2 Create
help.pyCheck: Test each function independently
1.3 Create
client.pyCheck: Test API calls with mock data
1.4 Create
agent.pyCheck: Import and use help.py and client.py
1.5 Create
__init__.pyPhase 2: Update Import Sites
Find all files that import from conversational.py:
Expected files to update (verify by searching):
api/ave.pyapi/config.pyservices/backtest/engine.py(if used there)ConversationalAgentUpdate imports to:
Phase 3: Delete Old File
After all imports updated:
What to Check/Verify
Per Module
tools.pypython -c "from app.services.ai_agent import tools"help.pyclient.pyagent.py__init__.pyfrom app.services.ai_agent import *Integration
/help, verify responseagent.process_message("hello")How to Test
Unit Tests
Integration Tests
How to Debug
If Import Fails
If Agent Not Working
If Slash Commands Fail
What NOT to Change (Invariants)
ConversationalAgentclass API__init__,process_message()signature unchanged/,/help,/tooloutput same as beforeprocess_message()returns same dict structureIf tests fail because response format changed, that's a bug — fix the refactor, not the tests.
Rollback Plan
If refactor breaks something:
git checkout conversational.pyAcceptance Criteria
tools.pyexists withTOOL_REGISTRYandget_tool_registry()help.pyexists with allformat_*functionsclient.pyexists withMiniMaxClientclassagent.pyexists withConversationalAgentclass__init__.pyexports everything correctlyconversational.pydeleted/,/help,/search, etc.)Files to Modify/Create
ai_agent/tools.pyai_agent/help.pyai_agent/client.pyai_agent/agent.pyai_agent/__init__.pyconversational.pyai_agent/conversational.pyDependencies
Priority
HIGH — Should be done BEFORE implementing #59 (Backend Chat System)
Notes for Developer