Skip to content

Commit

Permalink
dual agent
Browse files Browse the repository at this point in the history
  • Loading branch information
Kevin Lin authored and Kevin Lin committed Nov 14, 2024
1 parent 91276c1 commit dfb07d2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
18 changes: 11 additions & 7 deletions letta/offline_memory_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,35 @@

def send_message_offline_agent(self: "Agent", message: str) -> Optional[str]:
"""
Sends a message to the human user.
Sends a message to the human user. The function is the same as the base send_message function, but is used
when we do not include the other base tools.
Args:
message (str): Message contents. All unicode (including emojis) are supported.
Returns:
Optional[str]: None is always returned as this function does not produce a response.
"""
print("hello")
# FIXME passing of msg_obj here is a hack, unclear if guaranteed to be the correct reference
self.interface.assistant_message(message) # , msg_obj=self._messages[-1])
return None


def trigger_rethink_memory(self: "Agent") -> Optional[str]:
def trigger_rethink_memory(self: "Agent", message: Optional[str]) -> Optional[str]:
"""
If the user says the word "rethink_memory" then call this function
Args:
message (Optional[str]): String message to condition what the memory agent should rethink about.
"""
from letta import create_client

client = create_client()
agents = client.get_agents()
agents = client.list_agents()
for agent in agents:
if agent.agent_type == "offline_memory_agent":
agent.rethink_memory()
client.user_message(agent_id=agent.id, message=message)


def rethink_memory(self: "Agent") -> Optional[str]:
Expand All @@ -44,8 +48,8 @@ def rethink_memory(self: "Agent") -> Optional[str]:
"""
for memory_block in self.memory:
print(memory_block)
self.memory.update_block_value(name="rethink", value="Rethinking memory")
print(memory_block.value)
self.memory.update_block_value(name="rethink_memory_block", value="Rethinking memory")
return None


Expand Down
42 changes: 29 additions & 13 deletions tests/test_offline_memory_agent.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,49 @@
# from letta.functions.function_sets.base import send_message
from letta.client.client import Block, create_client
from letta.constants import DEFAULT_HUMAN, DEFAULT_PERSONA
from letta.offline_memory_agent import (
rethink_memory,
send_message_offline_agent,
trigger_rethink_memory,
)
from letta.schemas.agent import AgentType
from letta.schemas.embedding_config import EmbeddingConfig
from letta.schemas.llm_config import LLMConfig
from letta.schemas.memory import ChatMemory
from letta.utils import get_human_text, get_persona_text


def test_offline_memory_agent():
pass
# client = create_client()
# assert client is not None
client = create_client()
assert client is not None

"""
rethink_memory_tool = client.create_tool(rethink_memory)
send_message_offline_agent_tool = client.create_tool(send_message_offline_agent)
trigger_rethink_memory_tool = client.create_tool(trigger_rethink_memory)
send_message_offline_agent_tool = client.create_tool(send_message_offline_agent)

conversation_memory = ChatMemory(human=get_human_text(DEFAULT_HUMAN), persona=get_persona_text(DEFAULT_PERSONA))
new_memory = Block(name="rethink_memory_block", label="rethink_memory_block", value="", limit=2000)
conversation_memory.link_block(new_memory)

conversation_agent = client.create_agent(
agent_type=AgentType.offline_memory_agent,
llm_config=LLMConfig.default_config("gpt-4"),
embedding_config=EmbeddingConfig.default_config("text-embedding-ada-002"),
tools=[send_message_offline_agent.name, trigger_rethink_memory_tool.name],
memory=ChatMemory(human=get_human_text(DEFAULT_HUMAN), persona=get_persona_text(DEFAULT_PERSONA)),
tools=[send_message_offline_agent_tool.name, trigger_rethink_memory_tool.name],
memory=conversation_memory,
include_base_tools=False,
)
assert conversation_agent is not None
memory_rethink_agent = client.create_agent(
assert conversation_agent.memory.list_block_labels() == ["persona", "human", "rethink_memory_block"]

rethink_memory_tool = client.create_tool(rethink_memory)
offline_memory_agent = client.create_agent(
agent_type=AgentType.offline_memory_agent,
memory=ChatMemory(human=get_human_text(DEFAULT_HUMAN), persona=get_persona_text("offline_memory_persona")),
tools=[rethink_memory.name],
llm_config=LLMConfig.default_config("gpt-4"),
embedding_config=EmbeddingConfig.default_config("text-embedding-ada-002"),
tools=[rethink_memory_tool.name],
)
new_memory = Block(name="rethink_memory_block", label="memory_rethink_block", value="", limit=2000)
response = client.user_message(agent_id=conversation_agent.id, message="rethink: Tell me something I don't know about myself.")
print(response)
"""


if __name__ == "__main__":
Expand Down

0 comments on commit dfb07d2

Please sign in to comment.