Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: refactor agent memory representation and modify routes for editing blocks #2094

Merged
merged 60 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
c2e8a4b
scaffold initial agent changes
sarahwooders Nov 22, 2024
30d946b
update schemas
sarahwooders Nov 22, 2024
8ab9cae
modify create agent
sarahwooders Nov 22, 2024
1757630
move to using a richer type of agent state internally
sarahwooders Nov 22, 2024
c35cd9a
working agent create and update
sarahwooders Nov 23, 2024
4498c73
merge with main
sarahwooders Nov 23, 2024
bf2f94d
add table for block linking
sarahwooders Nov 23, 2024
7092d91
passing agent interactions
sarahwooders Nov 23, 2024
94bdcd6
passing memory
sarahwooders Nov 23, 2024
e9bb1ba
working core memory update
sarahwooders Nov 23, 2024
bce8a38
working shared memory blocks
sarahwooders Nov 23, 2024
ab60f4a
most local tests passing
sarahwooders Nov 23, 2024
464d8be
modify some stuff with tool rules
sarahwooders Nov 25, 2024
98e88d6
passing local client tests
sarahwooders Nov 25, 2024
8cc8298
passing shared blocks
sarahwooders Nov 25, 2024
29ee602
fully passing local client tests
sarahwooders Nov 25, 2024
02b3d7a
update tests
sarahwooders Nov 25, 2024
5dca196
Merge branch 'main' into refactor-memory
sarahwooders Nov 25, 2024
c5ed2a9
working test_client
sarahwooders Nov 25, 2024
6ebad76
Add alembic migration script
mattzh72 Nov 25, 2024
d6894df
add tests
sarahwooders Nov 25, 2024
c94dbac
passing REST test_client
sarahwooders Nov 25, 2024
19c069b
fix tool rules test
sarahwooders Nov 26, 2024
dbc0b97
more fixes
sarahwooders Nov 26, 2024
815f4bc
fix more tests
sarahwooders Nov 26, 2024
c1fdef8
fix o1 agent
sarahwooders Nov 26, 2024
430880a
maybe fix idk
sarahwooders Nov 26, 2024
670cedb
add composio scrape tool
sarahwooders Nov 26, 2024
38e7e40
fix a few things in server
sarahwooders Nov 26, 2024
7a7e179
fix sources error
sarahwooders Nov 26, 2024
28c361d
fix summarizer
sarahwooders Nov 26, 2024
a729209
validate model before returning
sarahwooders Nov 26, 2024
e28b308
fix cli
sarahwooders Nov 26, 2024
e610f0a
merge
sarahwooders Nov 26, 2024
e92735e
dont pass in blocks manaer to agents
sarahwooders Nov 26, 2024
4afdf79
actually save
sarahwooders Nov 26, 2024
4ab40b8
half fix cli
sarahwooders Nov 26, 2024
4a0695a
Add AgentState to __init__
mattzh72 Nov 26, 2024
3b823a4
fix test_client
sarahwooders Nov 26, 2024
46d3908
fix
sarahwooders Nov 26, 2024
d2ae20f
save
sarahwooders Nov 26, 2024
42a8ce3
fix interface passing
mattzh72 Nov 26, 2024
a9df9d4
fix server
sarahwooders Nov 27, 2024
45b0b12
remove incorrect saves
sarahwooders Nov 27, 2024
d33ba9b
get rid of initialize_agent to fix cli tests
sarahwooders Nov 27, 2024
857d1ab
forgot to save agent
sarahwooders Nov 27, 2024
427646f
fix message test
sarahwooders Nov 27, 2024
6967d9d
fix legacy tests
sarahwooders Nov 27, 2024
55dcd00
pass interface down
sarahwooders Nov 27, 2024
4ab9eb0
fix legacy tests
sarahwooders Nov 27, 2024
911791e
Merge branch 'main' into refactor-memory
sarahwooders Nov 27, 2024
b792132
disable e2b for legacy tests
sarahwooders Nov 27, 2024
c6b2a17
fix e2b setting
sarahwooders Nov 27, 2024
236dbb5
add mock_e2b_api_key_none
sarahwooders Nov 27, 2024
499a760
Merge branch 'main' into refactor-memory
sarahwooders Nov 27, 2024
4070147
cleanup
sarahwooders Nov 27, 2024
d5c693c
fix test_memory
sarahwooders Nov 27, 2024
2883855
fix summarizer tests
sarahwooders Nov 27, 2024
77d4c5c
fix error
sarahwooders Nov 27, 2024
80112f9
cleanup comments and prints
sarahwooders Nov 27, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions alembic/versions/5987401b40ae_refactor_agent_memory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
"""Refactor agent memory
Revision ID: 5987401b40ae
Revises: 1c8880d671ee
Create Date: 2024-11-25 14:35:00.896507
"""

from typing import Sequence, Union

import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "5987401b40ae"
down_revision: Union[str, None] = "1c8880d671ee"
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.alter_column("agents", "tools", new_column_name="tool_names")
op.drop_column("agents", "memory")
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.alter_column("agents", "tool_names", new_column_name="tools")
op.add_column("agents", sa.Column("memory", postgresql.JSON(astext_type=sa.Text()), autoincrement=False, nullable=True))
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion examples/docs/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def roll_d20() -> str:
TerminalToolRule(tool_name="send_message"),
],
)
print(f"Created agent with name {agent_state.name} with tools {agent_state.tools}")
print(f"Created agent with name {agent_state.name} with tools {agent_state.tool_names}")

# Message an agent
response = client.send_message(agent_id=agent_state.id, role="user", message="roll a dice")
Expand Down
4 changes: 2 additions & 2 deletions examples/swarm/swarm.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import typer

from letta import AgentState, EmbeddingConfig, LLMConfig, create_client
from letta import EmbeddingConfig, LLMConfig, PersistedAgentState, create_client
from letta.schemas.agent import AgentType
from letta.schemas.memory import BasicBlockMemory, Block

Expand Down Expand Up @@ -32,7 +32,7 @@ def create_agent(
include_base_tools: Optional[bool] = True,
# instructions
instructions: str = "",
) -> AgentState:
) -> PersistedAgentState:

# todo: process tools for agent handoff
persona_value = (
Expand Down
10 changes: 5 additions & 5 deletions examples/tool_rule_usage.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from letta import create_client
from letta.schemas.letta_message import FunctionCallMessage
from letta.schemas.tool_rule import InitToolRule, TerminalToolRule, ToolRule
from letta.schemas.tool_rule import ChildToolRule, InitToolRule, TerminalToolRule
from tests.helpers.endpoints_helper import (
assert_invoked_send_message_with_keyword,
setup_agent,
Expand Down Expand Up @@ -100,10 +100,10 @@ def main():
# 3. Create the tool rules. It must be called in this order, or there will be an error thrown.
tool_rules = [
InitToolRule(tool_name="first_secret_word"),
ToolRule(tool_name="first_secret_word", children=["second_secret_word"]),
ToolRule(tool_name="second_secret_word", children=["third_secret_word"]),
ToolRule(tool_name="third_secret_word", children=["fourth_secret_word"]),
ToolRule(tool_name="fourth_secret_word", children=["send_message"]),
ChildToolRule(tool_name="first_secret_word", children=["second_secret_word"]),
ChildToolRule(tool_name="second_secret_word", children=["third_secret_word"]),
ChildToolRule(tool_name="third_secret_word", children=["fourth_secret_word"]),
ChildToolRule(tool_name="fourth_secret_word", children=["send_message"]),
TerminalToolRule(tool_name="send_message"),
]

Expand Down
2 changes: 1 addition & 1 deletion letta/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from letta.client.client import LocalClient, RESTClient, create_client

# imports for easier access
from letta.schemas.agent import AgentState
from letta.schemas.agent import AgentState, PersistedAgentState
from letta.schemas.block import Block
from letta.schemas.embedding_config import EmbeddingConfig
from letta.schemas.enums import JobStatus
Expand Down
Loading
Loading