@@ -140,36 +140,28 @@ async def shutdown_event():
140140 await jup_validator .close ()
141141 await cow_validator .close ()
142142
143- # Initialize agents (analytics agent gets OKX tools after MCP connects at startup)
144- suggestions_model = create_suggestions_model ()
145- analytics_agent = create_analytics_executor (token_metadata_repo )
146- investor_agent = create_investor_executor ()
147-
148143 # Initialize protocol registry
149144 protocol_registry = ProtocolRegistry (token_metadata_repo )
150145 protocol_registry .register_protocol (OrcaProtocol ())
151146 protocol_registry .register_protocol (SaveProtocol ())
152147 protocol_registry .register_protocol (KaminoProtocol ())
153148
154- # Store agents in app state
149+ # Store in app state (agents created at startup after OKX MCP connects)
150+ suggestions_model = create_suggestions_model ()
151+ investor_agent = create_investor_executor ()
155152 app .state .suggestions_model = suggestions_model
156- app .state .analytics_agent = analytics_agent
157153 app .state .investor_agent = investor_agent
158154 app .state .protocol_registry = protocol_registry
159155
160156 @app .on_event ("startup" )
161157 async def startup_event ():
162158 await protocol_registry .initialize ()
163- try :
164- await okx_mcp_client .connect ()
165- okx_tools = okx_mcp_client .get_tools ()
166- if okx_tools :
167- app .state .analytics_agent = create_analytics_executor (
168- token_metadata_repo , extra_tools = okx_tools
169- )
170- logging .info (f"Analytics agent augmented with { len (okx_tools )} OKX tools" )
171- except Exception as e :
172- logging .warning (f"OKX MCP connection failed, continuing without OKX tools: { e } " )
159+ await okx_mcp_client .connect ()
160+ okx_tools = okx_mcp_client .get_tools ()
161+ app .state .analytics_agent = create_analytics_executor (
162+ token_metadata_repo , extra_tools = okx_tools
163+ )
164+ logging .info (f"Analytics agent created with { len (okx_tools )} OKX market data tools" )
173165
174166 # Exception handlers
175167 @app .exception_handler (ValidationError )
0 commit comments