Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: add configurable batch size and lookback (#2666)
cthomasf03830271a7f
diff --git a/letta/jobs/llm_batch_job_polling.py b/letta/jobs/llm_batch_job_polling.pyindex 401860e83..fe986eabf 100644--- a/letta/jobs/llm_batch_job_polling.py+++ b/letta/jobs/llm_batch_job_polling.py@@ -11,6 +11,7 @@ from letta.schemas.letta_response import LettaBatchResponsefrom letta.schemas.llm_batch_job import LLMBatchJobfrom letta.schemas.user import Userfrom letta.server.server import SyncServer+from letta.settings import settingslogger = get_logger(__name__)@@ -180,7 +181,9 @@ async def poll_running_llm_batches(server: "SyncServer") -> List[LettaBatchRespotry:# 1. Retrieve running batch jobs- batches = await server.batch_manager.list_running_llm_batches_async()+ batches = await server.batch_manager.list_running_llm_batches_async(+ weeks=max(settings.batch_job_polling_lookback_weeks, 1), batch_size=settings.batch_job_polling_batch_size+ )metrics.total_batches = len(batches)# TODO: Expand to more providers@@ -235,4 +238,4 @@ async def poll_running_llm_batches(server: "SyncServer") -> List[LettaBatchRespologger.exception("[Poll BatchJob] Unhandled error in poll_running_llm_batches", exc_info=e)finally:# 7. Log metrics summary- metrics.log_summary()+ metrics.log_summary()\ No newline at end of filediff --git a/letta/services/llm_batch_manager.py b/letta/services/llm_batch_manager.pyindex c296a64eb..eeff0673f 100644--- a/letta/services/llm_batch_manager.py+++ b/letta/services/llm_batch_manager.py@@ -205,14 +205,23 @@ class LLMBatchManager:@enforce_types@trace_method- async def list_running_llm_batches_async(self, actor: Optional[PydanticUser] = None) -> List[PydanticLLMBatchJob]:- """Return all running LLM batch jobs, optionally filtered by actor's organization."""+ async def list_running_llm_batches_async(+ self, actor: Optional[PydanticUser] = None, weeks: Optional[int] = None, batch_size: Optional[int] = None+ ) -> List[PydanticLLMBatchJob]:+ """Return all running LLM batch jobs, optionally filtered by actor's organization and recent weeks."""async with db_registry.async_session() as session:query = select(LLMBatchJob).where(LLMBatchJob.status == JobStatus.running)if actor is not None:query = query.where(LLMBatchJob.organization_id == actor.organization_id)+ if weeks is not None:+ cutoff_datetime = datetime.datetime.utcnow() - datetime.timedelta(weeks=weeks)+ query = query.where(LLMBatchJob.created_at >= cutoff_datetime)++ if batch_size is not None:+ query = query.limit(batch_size)+results = await session.execute(query)return [batch.to_pydantic() for batch in results.scalars().all()]diff --git a/letta/settings.py b/letta/settings.pyindex 063114328..2061696a6 100644--- a/letta/settings.py+++ b/letta/settings.py@@ -228,6 +228,8 @@ class Settings(BaseSettings):enable_batch_job_polling: bool = Falsepoll_running_llm_batches_interval_seconds: int = 5 * 60poll_lock_retry_interval_seconds: int = 5 * 60+ batch_job_polling_lookback_weeks: int = 2+ batch_job_polling_batch_size: Optional[int] = None@propertydef letta_pg_uri(self) -> str: