Skip to content

Commit

Permalink
Merge branch 'main' into mindy/passages-separate-tables
Browse files Browse the repository at this point in the history
  • Loading branch information
mlong93 authored Dec 15, 2024
2 parents e1a5d04 + 577a5d5 commit 1ba3378
Show file tree
Hide file tree
Showing 22 changed files with 235 additions and 524 deletions.
42 changes: 42 additions & 0 deletions alembic/versions/4e88e702f85e_drop_api_tokens_table_in_oss.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
"""Drop api tokens table in OSS
Revision ID: 4e88e702f85e
Revises: d05669b60ebe
Create Date: 2024-12-13 17:19:55.796210
"""

from typing import Sequence, Union

import sqlalchemy as sa

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "4e88e702f85e"
down_revision: Union[str, None] = "d05669b60ebe"
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.drop_index("tokens_idx_key", table_name="tokens")
op.drop_index("tokens_idx_user", table_name="tokens")
op.drop_table("tokens")
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"tokens",
sa.Column("id", sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column("user_id", sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column("key", sa.VARCHAR(), autoincrement=False, nullable=False),
sa.Column("name", sa.VARCHAR(), autoincrement=False, nullable=True),
sa.PrimaryKeyConstraint("id", name="tokens_pkey"),
)
op.create_index("tokens_idx_user", "tokens", ["user_id"], unique=False)
op.create_index("tokens_idx_key", "tokens", ["key"], unique=False)
# ### end Alembic commands ###
10 changes: 5 additions & 5 deletions alembic/versions/9a505cc7eca9_create_a_baseline_migrations.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

import letta.metadata
import letta.orm
from alembic import op

# revision identifiers, used by Alembic.
Expand Down Expand Up @@ -43,8 +43,8 @@ def upgrade() -> None:
sa.Column("memory", sa.JSON(), nullable=True),
sa.Column("system", sa.String(), nullable=True),
sa.Column("agent_type", sa.String(), nullable=True),
sa.Column("llm_config", letta.metadata.LLMConfigColumn(), nullable=True),
sa.Column("embedding_config", letta.metadata.EmbeddingConfigColumn(), nullable=True),
sa.Column("llm_config", letta.orm.custom_columns.LLMConfigColumn(), nullable=True),
sa.Column("embedding_config", letta.orm.custom_columns.EmbeddingConfigColumn(), nullable=True),
sa.Column("metadata_", sa.JSON(), nullable=True),
sa.Column("tools", sa.JSON(), nullable=True),
sa.PrimaryKeyConstraint("id"),
Expand Down Expand Up @@ -119,7 +119,7 @@ def upgrade() -> None:
sa.Column("agent_id", sa.String(), nullable=True),
sa.Column("source_id", sa.String(), nullable=True),
sa.Column("embedding", pgvector.sqlalchemy.Vector(dim=4096), nullable=True),
sa.Column("embedding_config", letta.metadata.EmbeddingConfigColumn(), nullable=True),
sa.Column("embedding_config", letta.orm.custom_columns.EmbeddingConfigColumn(), nullable=True),
sa.Column("metadata_", sa.JSON(), nullable=True),
sa.Column("created_at", sa.DateTime(timezone=True), nullable=True),
sa.PrimaryKeyConstraint("id"),
Expand All @@ -131,7 +131,7 @@ def upgrade() -> None:
sa.Column("user_id", sa.String(), nullable=False),
sa.Column("name", sa.String(), nullable=False),
sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.text("now()"), nullable=True),
sa.Column("embedding_config", letta.metadata.EmbeddingConfigColumn(), nullable=True),
sa.Column("embedding_config", letta.orm.custom_columns.EmbeddingConfigColumn(), nullable=True),
sa.Column("description", sa.String(), nullable=True),
sa.Column("metadata_", sa.JSON(), nullable=True),
sa.PrimaryKeyConstraint("id"),
Expand Down
10 changes: 1 addition & 9 deletions letta/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
from letta.llm_api.llm_api_tools import create
from letta.local_llm.utils import num_tokens_from_functions, num_tokens_from_messages
from letta.memory import summarize_messages
from letta.metadata import MetadataStore
from letta.orm import User
from letta.schemas.agent import AgentState, AgentStepResponse, UpdateAgent
from letta.schemas.block import BlockUpdate
Expand Down Expand Up @@ -889,18 +888,14 @@ def step(
# additional args
chaining: bool = True,
max_chaining_steps: Optional[int] = None,
ms: Optional[MetadataStore] = None,
**kwargs,
) -> LettaUsageStatistics:
"""Run Agent.step in a loop, handling chaining via heartbeat requests and function failures"""
# assert ms is not None, "MetadataStore is required"

next_input_message = messages if isinstance(messages, list) else [messages]
counter = 0
total_usage = UsageStatistics()
step_count = 0
while True:
kwargs["ms"] = ms
kwargs["first_message"] = False
step_response = self.inner_step(
messages=next_input_message,
Expand All @@ -918,8 +913,7 @@ def step(

# logger.debug("Saving agent state")
# save updated state
if ms:
save_agent(self)
save_agent(self)

# Chain stops
if not chaining:
Expand Down Expand Up @@ -978,7 +972,6 @@ def inner_step(
first_message_retry_limit: int = FIRST_MESSAGE_ATTEMPTS,
skip_verify: bool = False,
stream: bool = False, # TODO move to config?
ms: Optional[MetadataStore] = None,
) -> AgentStepResponse:
"""Runs a single step in the agent loop (generates at most one LLM call)"""

Expand Down Expand Up @@ -1098,7 +1091,6 @@ def inner_step(
first_message_retry_limit=first_message_retry_limit,
skip_verify=skip_verify,
stream=stream,
ms=ms,
)

else:
Expand Down
5 changes: 1 addition & 4 deletions letta/chat_only_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from letta.agent import Agent
from letta.interface import AgentInterface
from letta.metadata import MetadataStore
from letta.prompts import gpt_system
from letta.schemas.agent import AgentState, AgentType
from letta.schemas.embedding_config import EmbeddingConfig
Expand Down Expand Up @@ -36,11 +35,9 @@ def step(
messages: Union[Message, List[Message]],
chaining: bool = True,
max_chaining_steps: Optional[int] = None,
ms: Optional[MetadataStore] = None,
**kwargs,
) -> LettaUsageStatistics:
# assert ms is not None, "MetadataStore is required"
letta_statistics = super().step(messages=messages, chaining=chaining, max_chaining_steps=max_chaining_steps, ms=ms, **kwargs)
letta_statistics = super().step(messages=messages, chaining=chaining, max_chaining_steps=max_chaining_steps, **kwargs)

if self.always_rethink_memory:

Expand Down
3 changes: 0 additions & 3 deletions letta/cli/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
)
from letta.local_llm.constants import ASSISTANT_MESSAGE_CLI_SYMBOL
from letta.log import get_logger
from letta.metadata import MetadataStore
from letta.schemas.enums import OptionState
from letta.schemas.memory import ChatMemory, Memory
from letta.server.server import logger as server_logger
Expand Down Expand Up @@ -138,7 +137,6 @@ def run(
config = LettaConfig.load()

# read user id from config
ms = MetadataStore(config)
client = create_client()

# determine agent to use, if not provided
Expand Down Expand Up @@ -332,7 +330,6 @@ def run(
letta_agent=letta_agent,
config=config,
first=first,
ms=ms,
no_verify=no_verify,
stream=stream,
) # TODO: add back no_verify
Expand Down
5 changes: 0 additions & 5 deletions letta/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from letta.cli.cli_load import app as load_app
from letta.config import LettaConfig
from letta.constants import FUNC_FAILED_HEARTBEAT_MESSAGE, REQ_HEARTBEAT_MESSAGE
from letta.metadata import MetadataStore

# from letta.interface import CLIInterface as interface # for printing to terminal
from letta.streaming_interface import AgentRefreshStreamingInterface
Expand Down Expand Up @@ -62,7 +61,6 @@ def run_agent_loop(
letta_agent: agent.Agent,
config: LettaConfig,
first: bool,
ms: MetadataStore,
no_verify: bool = False,
strip_ui: bool = False,
stream: bool = False,
Expand Down Expand Up @@ -92,7 +90,6 @@ def run_agent_loop(

# create client
client = create_client()
ms = MetadataStore(config) # TODO: remove

# run loops
while True:
Expand Down Expand Up @@ -378,15 +375,13 @@ def process_agent_step(user_message, no_verify):
first_message=False,
skip_verify=no_verify,
stream=stream,
ms=ms,
)
else:
step_response = letta_agent.step_user_message(
user_message_str=user_message,
first_message=False,
skip_verify=no_verify,
stream=stream,
ms=ms,
)
new_messages = step_response.messages
heartbeat_request = step_response.heartbeat_request
Expand Down
157 changes: 0 additions & 157 deletions letta/metadata.py

This file was deleted.

Loading

0 comments on commit 1ba3378

Please sign in to comment.