-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add ability to add tags to agents (#1984)
- Loading branch information
Showing
14 changed files
with
465 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
"""Add agents tags table | ||
Revision ID: b6d7ca024aa9 | ||
Revises: d14ae606614c | ||
Create Date: 2024-11-06 10:48:08.424108 | ||
""" | ||
|
||
from typing import Sequence, Union | ||
|
||
import sqlalchemy as sa | ||
|
||
from alembic import op | ||
|
||
# revision identifiers, used by Alembic. | ||
revision: str = "b6d7ca024aa9" | ||
down_revision: Union[str, None] = "d14ae606614c" | ||
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_table( | ||
"agents_tags", | ||
sa.Column("agent_id", sa.String(), nullable=False), | ||
sa.Column("tag", sa.String(), nullable=False), | ||
sa.Column("id", sa.String(), nullable=False), | ||
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True), | ||
sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True), | ||
sa.Column("is_deleted", sa.Boolean(), server_default=sa.text("FALSE"), nullable=False), | ||
sa.Column("_created_by_id", sa.String(), nullable=True), | ||
sa.Column("_last_updated_by_id", sa.String(), nullable=True), | ||
sa.Column("organization_id", sa.String(), nullable=False), | ||
sa.ForeignKeyConstraint( | ||
["agent_id"], | ||
["agents.id"], | ||
), | ||
sa.ForeignKeyConstraint( | ||
["organization_id"], | ||
["organizations.id"], | ||
), | ||
sa.PrimaryKeyConstraint("agent_id", "id"), | ||
sa.UniqueConstraint("agent_id", "tag", name="unique_agent_tag"), | ||
) | ||
# ### end Alembic commands ### | ||
|
||
|
||
def downgrade() -> None: | ||
# ### commands auto generated by Alembic - please adjust! ### | ||
op.drop_table("agents_tags") | ||
# ### end Alembic commands ### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
from typing import TYPE_CHECKING | ||
|
||
from sqlalchemy import ForeignKey, String, UniqueConstraint | ||
from sqlalchemy.orm import Mapped, mapped_column, relationship | ||
|
||
from letta.orm.mixins import OrganizationMixin | ||
from letta.orm.sqlalchemy_base import SqlalchemyBase | ||
from letta.schemas.agents_tags import AgentsTags as PydanticAgentsTags | ||
|
||
if TYPE_CHECKING: | ||
from letta.orm.organization import Organization | ||
|
||
|
||
class AgentsTags(SqlalchemyBase, OrganizationMixin): | ||
"""Associates tags with agents, allowing agents to have multiple tags and supporting tag-based filtering.""" | ||
|
||
__tablename__ = "agents_tags" | ||
__pydantic_model__ = PydanticAgentsTags | ||
__table_args__ = (UniqueConstraint("agent_id", "tag", name="unique_agent_tag"),) | ||
|
||
# The agent associated with this tag | ||
agent_id = mapped_column(String, ForeignKey("agents.id"), primary_key=True) | ||
|
||
# The name of the tag | ||
tag: Mapped[str] = mapped_column(String, nullable=False, doc="The name of the tag associated with the agent.") | ||
|
||
# relationships | ||
organization: Mapped["Organization"] = relationship("Organization", back_populates="agents_tags") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from datetime import datetime | ||
from typing import Optional | ||
|
||
from pydantic import Field | ||
|
||
from letta.schemas.letta_base import LettaBase | ||
|
||
|
||
class AgentsTagsBase(LettaBase): | ||
__id_prefix__ = "agents_tags" | ||
|
||
|
||
class AgentsTags(AgentsTagsBase): | ||
""" | ||
Schema representing the relationship between tags and agents. | ||
Parameters: | ||
agent_id (str): The ID of the associated agent. | ||
tag_id (str): The ID of the associated tag. | ||
tag_name (str): The name of the tag. | ||
created_at (datetime): The date this relationship was created. | ||
""" | ||
|
||
id: str = AgentsTagsBase.generate_id_field() | ||
agent_id: str = Field(..., description="The ID of the associated agent.") | ||
tag: str = Field(..., description="The name of the tag.") | ||
created_at: Optional[datetime] = Field(None, description="The creation date of the association.") | ||
updated_at: Optional[datetime] = Field(None, description="The update date of the tag.") | ||
is_deleted: bool = Field(False, description="Whether this tag is deleted or not.") | ||
|
||
|
||
class AgentsTagsCreate(AgentsTagsBase): | ||
tag: str = Field(..., description="The tag name.") |
Oops, something went wrong.