mirror of
https://github.com/Xe138/AI-Trader.git
synced 2026-04-01 17:17:24 -04:00
fix: initialize agent properly in API mode
Fixed critical bug where ModelDayExecutor._initialize_agent() created a BaseAgent but never called agent.initialize(), leaving self.model=None. This caused 'NoneType' object has no attribute 'bind' error when run_trading_session() tried to create the langchain agent. Changes: - Made _initialize_agent() async - Added await agent.initialize() call - Updated call site to await async function Now properly initializes MCP client, tools, and AI model before executing trading sessions, matching the working CLI mode pattern.
This commit is contained in:
@@ -126,7 +126,7 @@ class ModelDayExecutor:
|
|||||||
os.environ["RUNTIME_ENV_PATH"] = self.runtime_config_path
|
os.environ["RUNTIME_ENV_PATH"] = self.runtime_config_path
|
||||||
|
|
||||||
# Initialize agent
|
# Initialize agent
|
||||||
agent = self._initialize_agent()
|
agent = await self._initialize_agent()
|
||||||
|
|
||||||
# Run trading session
|
# Run trading session
|
||||||
logger.info(f"Running trading session for {self.model_sig} on {self.date}")
|
logger.info(f"Running trading session for {self.model_sig} on {self.date}")
|
||||||
@@ -209,7 +209,7 @@ class ModelDayExecutor:
|
|||||||
"""Execute model-day simulation (sync entry point)."""
|
"""Execute model-day simulation (sync entry point)."""
|
||||||
return self.execute_sync()
|
return self.execute_sync()
|
||||||
|
|
||||||
def _initialize_agent(self):
|
async def _initialize_agent(self):
|
||||||
"""
|
"""
|
||||||
Initialize trading agent with config.
|
Initialize trading agent with config.
|
||||||
|
|
||||||
@@ -259,6 +259,9 @@ class ModelDayExecutor:
|
|||||||
# - Database initialization is handled by JobManager
|
# - Database initialization is handled by JobManager
|
||||||
# - File-based position tracking is only for standalone/CLI mode
|
# - File-based position tracking is only for standalone/CLI mode
|
||||||
|
|
||||||
|
# Initialize MCP client and AI model
|
||||||
|
await agent.initialize()
|
||||||
|
|
||||||
return agent
|
return agent
|
||||||
|
|
||||||
def _create_trading_session(self, cursor) -> int:
|
def _create_trading_session(self, cursor) -> int:
|
||||||
|
|||||||
Reference in New Issue
Block a user