Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: better error message for llm on agent failure (#5402)
Kian Jones158546414ded
diff --git a/letta/helpers/validators.py b/letta/helpers/validators.pynew file mode 100644index 000000000..8db472b47--- /dev/null+++ b/letta/helpers/validators.py@@ -0,0 +1,16 @@+import uuid+++def is_valid_agent_id(agent_id: str) -> bool:+ """Check if string matches the pattern 'agent-{uuid}'"""++ if not agent_id or not agent_id.startswith("agent-"):+ return False++ uuid_section = agent_id[6:]++ try:+ uuid.UUID(uuid_section)+ return True+ except ValueError:+ return Falsediff --git a/letta/services/agent_manager.py b/letta/services/agent_manager.pyindex e8270bfb1..21d63eb41 100644--- a/letta/services/agent_manager.py+++ b/letta/services/agent_manager.py@@ -27,6 +27,7 @@ from letta.constants import ()from letta.helpers import ToolRulesSolverfrom letta.helpers.datetime_helpers import get_utc_time+from letta.helpers.validators import is_valid_agent_idfrom letta.llm_api.llm_client import LLMClientfrom letta.log import get_loggerfrom letta.orm import (@@ -961,6 +962,9 @@ class AgentManager:include_relationships: Optional[List[str]] = None,) -> PydanticAgentState:"""Fetch an agent by its ID."""+ if not is_valid_agent_id(agent_id):+ raise NoResultFound("Agent id should match agent-{uuid}")+async with db_registry.async_session() as session:try:query = select(AgentModel)