From 51439eaeab2caebd8c46f97fb0412a74b830fd4a Mon Sep 17 00:00:00 2001 From: sharath <29162020+tnfssc@users.noreply.github.com> Date: Sat, 24 May 2025 12:41:59 +0000 Subject: [PATCH] refactor(api): remove thread_manager initialization from API and agent background scripts --- backend/api.py | 4 ---- backend/run_agent_background.py | 6 ++---- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/backend/api.py b/backend/api.py index eb53ecf1..48b1b922 100644 --- a/backend/api.py +++ b/backend/api.py @@ -23,7 +23,6 @@ load_dotenv() # Initialize managers db = DBConnection() -thread_manager = None instance_id = "single" # Rate limiter state @@ -33,17 +32,14 @@ MAX_CONCURRENT_IPS = 25 @asynccontextmanager async def lifespan(app: FastAPI): # Startup - global thread_manager logger.info(f"Starting up FastAPI application with instance ID: {instance_id} in {config.ENV_MODE.value} mode") try: # Initialize database await db.initialize() - thread_manager = ThreadManager() # Initialize the agent API with shared resources agent_api.initialize( - thread_manager, db, instance_id ) diff --git a/backend/run_agent_background.py b/backend/run_agent_background.py index 4cb52302..035cd145 100644 --- a/backend/run_agent_background.py +++ b/backend/run_agent_background.py @@ -22,12 +22,11 @@ dramatiq.set_broker(rabbitmq_broker) _initialized = False db = DBConnection() -thread_manager = None instance_id = "single" async def initialize(): """Initialize the agent API with resources from the main API.""" - global thread_manager, db, instance_id, _initialized + global db, instance_id, _initialized if _initialized: return @@ -37,7 +36,6 @@ async def initialize(): instance_id = str(uuid.uuid4())[:8] await redis.initialize_async() await db.initialize() - thread_manager = ThreadManager() _initialized = True logger.info(f"Initialized agent API with instance ID: {instance_id}") @@ -114,7 +112,7 @@ async def run_agent_background( # Initialize agent generator agent_gen = run_agent( thread_id=thread_id, project_id=project_id, stream=stream, - thread_manager=thread_manager, model_name=model_name, + model_name=model_name, enable_thinking=enable_thinking, reasoning_effort=reasoning_effort, enable_context_manager=enable_context_manager, trace=trace