Platform for stateful agents: AI with advanced memory that can learn and self-improve over time.
fix: make tool rules enum mapping one to one (#826)
cthomasacc59fd296b8
diff --git a/.composio.lock b/.composio.locknew file mode 100644index 000000000..0967ef424--- /dev/null+++ b/.composio.lock@@ -0,0 +1 @@+{}diff --git a/letta/agent.py b/letta/agent.pyindex fefca2f55..8f1760f87 100644--- a/letta/agent.py+++ b/letta/agent.py@@ -235,6 +235,7 @@ class Agent(BaseAgent):# TODO: This is only temporary, can remove after we publish a pip package with this objectagent_state_copy = self.agent_state.__deepcopy__()agent_state_copy.tools = []+ agent_state_copy.tool_rules = []sandbox_run_result = ToolExecutionSandbox(function_name, function_args, self.user).run(agent_state=agent_state_copy)function_response, updated_agent_state = sandbox_run_result.func_return, sandbox_run_result.agent_statediff --git a/letta/orm/custom_columns.py b/letta/orm/custom_columns.pyindex c551a7d4b..f821f04d6 100644--- a/letta/orm/custom_columns.py+++ b/letta/orm/custom_columns.py@@ -84,11 +84,11 @@ class ToolRulesColumn(TypeDecorator):def deserialize_tool_rule(data: dict) -> Union[ChildToolRule, InitToolRule, TerminalToolRule, ConditionalToolRule]:"""Deserialize a dictionary to the appropriate ToolRule subclass based on the 'type'."""rule_type = ToolRuleType(data.get("type")) # Remove 'type' field if it exists since it is a class var- if rule_type == ToolRuleType.run_first:+ if rule_type == ToolRuleType.run_first or rule_type == "InitToolRule":return InitToolRule(**data)- elif rule_type == ToolRuleType.exit_loop:+ elif rule_type == ToolRuleType.exit_loop or rule_type == "TerminalToolRule":return TerminalToolRule(**data)- elif rule_type == ToolRuleType.constrain_child_tools:+ elif rule_type == ToolRuleType.constrain_child_tools or rule_type == "ToolRule":rule = ChildToolRule(**data)return ruleelif rule_type == ToolRuleType.conditional:diff --git a/letta/schemas/enums.py b/letta/schemas/enums.pyindex 9a3076aea..0b396d5d5 100644--- a/letta/schemas/enums.py+++ b/letta/schemas/enums.py@@ -46,9 +46,13 @@ class ToolRuleType(str, Enum):# note: some of these should be renamed when we do the data migration- run_first = "InitToolRule"- exit_loop = "TerminalToolRule" # reasoning loop should exit- continue_loop = "continue_loop" # reasoning loop should continue+ run_first = "run_first"+ exit_loop = "exit_loop" # reasoning loop should exit+ continue_loop = "continue_loop"conditional = "conditional"- constrain_child_tools = "ToolRule"+ constrain_child_tools = "constrain_child_tools"require_parent_tools = "require_parent_tools"+ # Deprecated+ InitToolRule = "InitToolRule"+ TerminalToolRule = "TerminalToolRule"+ ToolRule = "ToolRule"diff --git a/letta/schemas/tool_rule.py b/letta/schemas/tool_rule.pyindex 1ab313a7e..faf94fe42 100644--- a/letta/schemas/tool_rule.py+++ b/letta/schemas/tool_rule.py@@ -9,7 +9,7 @@ from letta.schemas.letta_base import LettaBaseclass BaseToolRule(LettaBase):__id_prefix__ = "tool_rule"tool_name: str = Field(..., description="The name of the tool. Must exist in the database for the user's organization.")- type: ToolRuleType+ type: ToolRuleType = Field(..., description="The type of the message.")class ChildToolRule(BaseToolRule):diff --git a/tests/integration_test_tool_execution_sandbox.py b/tests/integration_test_tool_execution_sandbox.pyindex 8a6e5d9d0..75c632ffc 100644--- a/tests/integration_test_tool_execution_sandbox.py+++ b/tests/integration_test_tool_execution_sandbox.py@@ -232,6 +232,7 @@ def agent_state():embedding_config=EmbeddingConfig.default_config(provider="openai"),llm_config=LLMConfig.default_config(model_name="gpt-4"),)+ agent_state.tool_rules = []yield agent_state