refactor(api): remove thread_manager initialization from API and agent background scripts

This commit is contained in:
sharath 2025-05-24 12:41:59 +00:00
parent e4de538c23
commit 51439eaeab
No known key found for this signature in database
2 changed files with 2 additions and 8 deletions

View File

@ -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
)

View File

@ -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