fix: make tool rules enum mapping one to one (#826)

This commit is contained in:
cthomas 2025-01-29 13:49:07 -08:00 committed by GitHub
parent 1bc102e754
commit 1294ff1b7a
6 changed files with 15 additions and 8 deletions

1
.composio.lock Normal file
View File

@ -0,0 +1 @@
{}

View File

@ -235,6 +235,7 @@ class Agent(BaseAgent):
# TODO: This is only temporary, can remove after we publish a pip package with this object
agent_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_state

View File

@ -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 rule
elif rule_type == ToolRuleType.conditional:

View File

@ -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"

View File

@ -9,7 +9,7 @@ from letta.schemas.letta_base import LettaBase
class 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):

View File

@ -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