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

Co-authored-by: Matt Zhou <mattzh1314@gmail.com>
This commit is contained in:
Sarah Wooders
2024-11-27 16:04:13 -08:00
committed by GitHub
parent 122faa78ea
commit 07bb536018
44 changed files with 1326 additions and 1219 deletions

View File

@@ -2,7 +2,7 @@ import pytest
from letta.helpers import ToolRulesSolver
from letta.helpers.tool_rule_solver import ToolRuleValidationError
from letta.schemas.tool_rule import InitToolRule, TerminalToolRule, ToolRule
from letta.schemas.tool_rule import ChildToolRule, InitToolRule, TerminalToolRule
# Constants for tool names used in the tests
START_TOOL = "start_tool"
@@ -30,7 +30,7 @@ def test_get_allowed_tool_names_with_init_rules():
def test_get_allowed_tool_names_with_subsequent_rule():
# Setup: Tool rule sequence
init_rule = InitToolRule(tool_name=START_TOOL)
rule_1 = ToolRule(tool_name=START_TOOL, children=[NEXT_TOOL, HELPER_TOOL])
rule_1 = ChildToolRule(tool_name=START_TOOL, children=[NEXT_TOOL, HELPER_TOOL])
solver = ToolRulesSolver(init_tool_rules=[init_rule], tool_rules=[rule_1], terminal_tool_rules=[])
# Action: Update usage and get allowed tools
@@ -84,8 +84,8 @@ def test_get_allowed_tool_names_no_matching_rule_error():
def test_update_tool_usage_and_get_allowed_tool_names_combined():
# Setup: More complex rule chaining
init_rule = InitToolRule(tool_name=START_TOOL)
rule_1 = ToolRule(tool_name=START_TOOL, children=[NEXT_TOOL])
rule_2 = ToolRule(tool_name=NEXT_TOOL, children=[FINAL_TOOL])
rule_1 = ChildToolRule(tool_name=START_TOOL, children=[NEXT_TOOL])
rule_2 = ChildToolRule(tool_name=NEXT_TOOL, children=[FINAL_TOOL])
terminal_rule = TerminalToolRule(tool_name=FINAL_TOOL)
solver = ToolRulesSolver(init_tool_rules=[init_rule], tool_rules=[rule_1, rule_2], terminal_tool_rules=[terminal_rule])
@@ -107,10 +107,10 @@ def test_update_tool_usage_and_get_allowed_tool_names_combined():
def test_tool_rules_with_cycle_detection():
# Setup: Define tool rules with both connected, disconnected nodes and a cycle
init_rule = InitToolRule(tool_name=START_TOOL)
rule_1 = ToolRule(tool_name=START_TOOL, children=[NEXT_TOOL])
rule_2 = ToolRule(tool_name=NEXT_TOOL, children=[HELPER_TOOL])
rule_3 = ToolRule(tool_name=HELPER_TOOL, children=[START_TOOL]) # This creates a cycle: start -> next -> helper -> start
rule_4 = ToolRule(tool_name=FINAL_TOOL, children=[END_TOOL]) # Disconnected rule, no cycle here
rule_1 = ChildToolRule(tool_name=START_TOOL, children=[NEXT_TOOL])
rule_2 = ChildToolRule(tool_name=NEXT_TOOL, children=[HELPER_TOOL])
rule_3 = ChildToolRule(tool_name=HELPER_TOOL, children=[START_TOOL]) # This creates a cycle: start -> next -> helper -> start
rule_4 = ChildToolRule(tool_name=FINAL_TOOL, children=[END_TOOL]) # Disconnected rule, no cycle here
terminal_rule = TerminalToolRule(tool_name=END_TOOL)
# Action & Assert: Attempt to create the ToolRulesSolver with a cycle should raise ValidationError
@@ -118,7 +118,7 @@ def test_tool_rules_with_cycle_detection():
ToolRulesSolver(tool_rules=[init_rule, rule_1, rule_2, rule_3, rule_4, terminal_rule])
# Extra setup: Define tool rules without a cycle but with hanging nodes
rule_5 = ToolRule(tool_name=PREP_TOOL, children=[FINAL_TOOL]) # Hanging node with no connection to start_tool
rule_5 = ChildToolRule(tool_name=PREP_TOOL, children=[FINAL_TOOL]) # Hanging node with no connection to start_tool
# Assert that a configuration without cycles does not raise an error
try: