Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
feat: Add index to agent environment variables (#2405)
Matthew Zhoub9d79f52295a
diff --git a/alembic/versions/dd049fbec729_add_index_on_agent_id_for_agent_env_var.py b/alembic/versions/dd049fbec729_add_index_on_agent_id_for_agent_env_var.pynew file mode 100644index 000000000..e995caeed--- /dev/null+++ b/alembic/versions/dd049fbec729_add_index_on_agent_id_for_agent_env_var.py@@ -0,0 +1,29 @@+"""Add index on agent_id for agent env var++Revision ID: dd049fbec729+Revises: 9ecbdbaa409f+Create Date: 2025-05-23 17:41:48.235405++"""++from typing import Sequence, Union++from alembic import op++# revision identifiers, used by Alembic.+revision: str = "dd049fbec729"+down_revision: Union[str, None] = "9ecbdbaa409f"+branch_labels: Union[str, Sequence[str], None] = None+depends_on: Union[str, Sequence[str], None] = None+++def upgrade() -> None:+ # ### commands auto generated by Alembic - please adjust! ###+ op.create_index("idx_agent_environment_variables_agent_id", "agent_environment_variables", ["agent_id"], unique=False)+ # ### end Alembic commands ###+++def downgrade() -> None:+ # ### commands auto generated by Alembic - please adjust! ###+ op.drop_index("idx_agent_environment_variables_agent_id", table_name="agent_environment_variables")+ # ### end Alembic commands ###diff --git a/letta/orm/sandbox_config.py b/letta/orm/sandbox_config.pyindex 164814c51..44fad1921 100644--- a/letta/orm/sandbox_config.py+++ b/letta/orm/sandbox_config.py@@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, Dict, List, Optionalfrom sqlalchemy import JSONfrom sqlalchemy import Enum as SqlEnum-from sqlalchemy import String, UniqueConstraint+from sqlalchemy import Index, String, UniqueConstraintfrom sqlalchemy.orm import Mapped, mapped_column, relationshipfrom letta.orm.mixins import AgentMixin, OrganizationMixin, SandboxConfigMixin@@ -61,7 +61,10 @@ class AgentEnvironmentVariable(SqlalchemyBase, OrganizationMixin, AgentMixin):__tablename__ = "agent_environment_variables"# We cannot have duplicate key names for the same agent, the env var would get overwritten- __table_args__ = (UniqueConstraint("key", "agent_id", name="uix_key_agent"),)+ __table_args__ = (+ UniqueConstraint("key", "agent_id", name="uix_key_agent"),+ Index("idx_agent_environment_variables_agent_id", "agent_id"),+ )# agent_env_var generates its own id# TODO: We want to migrate all the ORM models to do this, so we will need to move this to the SqlalchemyBase