mirror of https://github.com/kortix-ai/suna.git
refactor(api): remove thread_manager initialization from API and agent background scripts
This commit is contained in:
parent
e4de538c23
commit
51439eaeab
|
@ -23,7 +23,6 @@ load_dotenv()
|
||||||
|
|
||||||
# Initialize managers
|
# Initialize managers
|
||||||
db = DBConnection()
|
db = DBConnection()
|
||||||
thread_manager = None
|
|
||||||
instance_id = "single"
|
instance_id = "single"
|
||||||
|
|
||||||
# Rate limiter state
|
# Rate limiter state
|
||||||
|
@ -33,17 +32,14 @@ MAX_CONCURRENT_IPS = 25
|
||||||
@asynccontextmanager
|
@asynccontextmanager
|
||||||
async def lifespan(app: FastAPI):
|
async def lifespan(app: FastAPI):
|
||||||
# Startup
|
# Startup
|
||||||
global thread_manager
|
|
||||||
logger.info(f"Starting up FastAPI application with instance ID: {instance_id} in {config.ENV_MODE.value} mode")
|
logger.info(f"Starting up FastAPI application with instance ID: {instance_id} in {config.ENV_MODE.value} mode")
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Initialize database
|
# Initialize database
|
||||||
await db.initialize()
|
await db.initialize()
|
||||||
thread_manager = ThreadManager()
|
|
||||||
|
|
||||||
# Initialize the agent API with shared resources
|
# Initialize the agent API with shared resources
|
||||||
agent_api.initialize(
|
agent_api.initialize(
|
||||||
thread_manager,
|
|
||||||
db,
|
db,
|
||||||
instance_id
|
instance_id
|
||||||
)
|
)
|
||||||
|
|
|
@ -22,12 +22,11 @@ dramatiq.set_broker(rabbitmq_broker)
|
||||||
|
|
||||||
_initialized = False
|
_initialized = False
|
||||||
db = DBConnection()
|
db = DBConnection()
|
||||||
thread_manager = None
|
|
||||||
instance_id = "single"
|
instance_id = "single"
|
||||||
|
|
||||||
async def initialize():
|
async def initialize():
|
||||||
"""Initialize the agent API with resources from the main API."""
|
"""Initialize the agent API with resources from the main API."""
|
||||||
global thread_manager, db, instance_id, _initialized
|
global db, instance_id, _initialized
|
||||||
if _initialized:
|
if _initialized:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
@ -37,7 +36,6 @@ async def initialize():
|
||||||
instance_id = str(uuid.uuid4())[:8]
|
instance_id = str(uuid.uuid4())[:8]
|
||||||
await redis.initialize_async()
|
await redis.initialize_async()
|
||||||
await db.initialize()
|
await db.initialize()
|
||||||
thread_manager = ThreadManager()
|
|
||||||
|
|
||||||
_initialized = True
|
_initialized = True
|
||||||
logger.info(f"Initialized agent API with instance ID: {instance_id}")
|
logger.info(f"Initialized agent API with instance ID: {instance_id}")
|
||||||
|
@ -114,7 +112,7 @@ async def run_agent_background(
|
||||||
# Initialize agent generator
|
# Initialize agent generator
|
||||||
agent_gen = run_agent(
|
agent_gen = run_agent(
|
||||||
thread_id=thread_id, project_id=project_id, stream=stream,
|
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_thinking=enable_thinking, reasoning_effort=reasoning_effort,
|
||||||
enable_context_manager=enable_context_manager,
|
enable_context_manager=enable_context_manager,
|
||||||
trace=trace
|
trace=trace
|
||||||
|
|
Loading…
Reference in New Issue