Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: throw `404` for missing `agent_id` (#4804)
Sarah Wooders3593e7cda6f0
diff --git a/letta/services/helpers/agent_manager_helper.py b/letta/services/helpers/agent_manager_helper.pyindex fffe6ccd8..bd317697c 100644--- a/letta/services/helpers/agent_manager_helper.py+++ b/letta/services/helpers/agent_manager_helper.py@@ -19,6 +19,7 @@ from letta.constants import (MULTI_AGENT_TOOLS,STRUCTURED_OUTPUT_MODELS,)+from letta.errors import LettaAgentNotFoundErrorfrom letta.helpers import ToolRulesSolverfrom letta.helpers.datetime_helpers import get_local_timefrom letta.llm_api.llm_client import LLMClient@@ -1238,4 +1239,4 @@ async def validate_agent_exists_async(session, agent_id: str, actor: User) -> Noresult = await session.execute(agent_exists_query)if not result.scalar():- raise NoResultFound(f"Agent with ID {agent_id} not found")+ raise LettaAgentNotFoundError(f"Agent with ID {agent_id} not found")diff --git a/letta/services/job_manager.py b/letta/services/job_manager.pyindex cd1dccb80..572ae6ba0 100644--- a/letta/services/job_manager.py+++ b/letta/services/job_manager.py@@ -25,6 +25,7 @@ from letta.schemas.step import Step as PydanticStepfrom letta.schemas.usage import LettaUsageStatisticsfrom letta.schemas.user import User as PydanticUserfrom letta.server.db import db_registry+from letta.services.helpers.agent_manager_helper import validate_agent_exists_asyncfrom letta.utils import enforce_typeslogger = get_logger(__name__)@@ -48,6 +49,9 @@ class JobManager:# Get agent_id if presentagent_id = getattr(pydantic_job, "agent_id", None)+ # Verify agent exists before creating the job+ await validate_agent_exists_async(session, agent_id, actor)+job_data = pydantic_job.model_dump(to_orm=True)# Remove agent_id from job_data as it's not a field in the Job ORM model# The relationship is handled through the AgentsRuns association table@@ -79,6 +83,9 @@ class JobManager:# Get agent_id if presentagent_id = getattr(pydantic_job, "agent_id", None)+ # Verify agent exists before creating the job+ await validate_agent_exists_async(session, agent_id, actor)+job_data = pydantic_job.model_dump(to_orm=True)# Remove agent_id from job_data as it's not a field in the Job ORM model# The relationship is handled through the AgentsRuns association table