dmpantiu commited on
Commit
53b38bc
·
verified ·
1 Parent(s): b0bd6c6

Upload folder using huggingface_hub

Browse files
Files changed (1) hide show
  1. web/agent_wrapper.py +7 -3
web/agent_wrapper.py CHANGED
@@ -310,10 +310,14 @@ _sessions: Dict[str, AgentSession] = {}
310
 
311
 
312
  def create_session(connection_id: str, api_keys: Optional[Dict[str, str]] = None) -> AgentSession:
313
- """Create a new session for a connection."""
314
  if connection_id in _sessions:
315
- # Close existing session first
316
- _sessions[connection_id].close()
 
 
 
 
317
  session = AgentSession(api_keys=api_keys)
318
  _sessions[connection_id] = session
319
  logger.info(f"Created session for connection: {connection_id}")
 
310
 
311
 
312
  def create_session(connection_id: str, api_keys: Optional[Dict[str, str]] = None) -> AgentSession:
313
+ """Create a new session for a connection (reuses if already ready)."""
314
  if connection_id in _sessions:
315
+ existing = _sessions[connection_id]
316
+ if existing.is_ready():
317
+ logger.info(f"Reusing existing ready session for: {connection_id}")
318
+ return existing
319
+ # Close broken session before replacing
320
+ existing.close()
321
  session = AgentSession(api_keys=api_keys)
322
  _sessions[connection_id] = session
323
  logger.info(f"Created session for connection: {connection_id}")