fix: Allow ChildToolRule to work without support for structured outputs (#2270)
Co-authored-by: Mindy Long <mindy@letta.com>
This commit is contained in:
@@ -64,6 +64,7 @@ def setup_agent(
|
||||
tool_ids: Optional[List[str]] = None,
|
||||
tool_rules: Optional[List[BaseToolRule]] = None,
|
||||
agent_uuid: str = agent_uuid,
|
||||
include_base_tools: bool = True,
|
||||
) -> AgentState:
|
||||
config_data = json.load(open(filename, "r"))
|
||||
llm_config = LLMConfig(**config_data)
|
||||
@@ -77,7 +78,7 @@ def setup_agent(
|
||||
|
||||
memory = ChatMemory(human=memory_human_str, persona=memory_persona_str)
|
||||
agent_state = client.create_agent(
|
||||
name=agent_uuid, llm_config=llm_config, embedding_config=embedding_config, memory=memory, tool_ids=tool_ids, tool_rules=tool_rules
|
||||
name=agent_uuid, llm_config=llm_config, embedding_config=embedding_config, memory=memory, tool_ids=tool_ids, tool_rules=tool_rules, include_base_tools=include_base_tools,
|
||||
)
|
||||
|
||||
return agent_state
|
||||
|
||||
@@ -234,3 +234,51 @@ def test_claude_initial_tool_rule_enforced(mock_e2b_api_key_none):
|
||||
if i < 2:
|
||||
backoff_time = 10 * (2 ** i)
|
||||
time.sleep(backoff_time)
|
||||
|
||||
@pytest.mark.timeout(60) # Sets a 60-second timeout for the test since this could loop infinitely
|
||||
def test_agent_no_structured_output_with_one_child_tool(mock_e2b_api_key_none):
|
||||
client = create_client()
|
||||
cleanup(client=client, agent_uuid=agent_uuid)
|
||||
|
||||
send_message = client.server.tool_manager.get_tool_by_name(tool_name="send_message", actor=client.user)
|
||||
archival_memory_search = client.server.tool_manager.get_tool_by_name(tool_name="archival_memory_search", actor=client.user)
|
||||
archival_memory_insert = client.server.tool_manager.get_tool_by_name(tool_name="archival_memory_insert", actor=client.user)
|
||||
|
||||
# Make tool rules
|
||||
tool_rules = [
|
||||
InitToolRule(tool_name="archival_memory_search"),
|
||||
ChildToolRule(tool_name="archival_memory_search", children=["archival_memory_insert"]),
|
||||
ChildToolRule(tool_name="archival_memory_insert", children=["send_message"]),
|
||||
TerminalToolRule(tool_name="send_message"),
|
||||
]
|
||||
tools = [send_message, archival_memory_search, archival_memory_insert]
|
||||
|
||||
config_files = [
|
||||
"tests/configs/llm_model_configs/claude-3-sonnet-20240229.json",
|
||||
"tests/configs/llm_model_configs/openai-gpt-4o.json",
|
||||
]
|
||||
|
||||
for config in config_files:
|
||||
agent_state = setup_agent(client, config, agent_uuid=agent_uuid, tool_ids=[t.id for t in tools], tool_rules=tool_rules)
|
||||
response = client.user_message(agent_id=agent_state.id, message="hi. run archival memory search")
|
||||
|
||||
# Make checks
|
||||
assert_sanity_checks(response)
|
||||
|
||||
# Assert the tools were called
|
||||
assert_invoked_function_call(response.messages, "archival_memory_search")
|
||||
assert_invoked_function_call(response.messages, "archival_memory_insert")
|
||||
assert_invoked_function_call(response.messages, "send_message")
|
||||
|
||||
# Check ordering of tool calls
|
||||
tool_names = [t.name for t in [archival_memory_search, archival_memory_insert, send_message]]
|
||||
for m in response.messages:
|
||||
if isinstance(m, FunctionCallMessage):
|
||||
# Check that it's equal to the first one
|
||||
assert m.function_call.name == tool_names[0]
|
||||
|
||||
# Pop out first one
|
||||
tool_names = tool_names[1:]
|
||||
|
||||
print(f"Got successful response from client: \n\n{response}")
|
||||
cleanup(client=client, agent_uuid=agent_uuid)
|
||||
|
||||
Reference in New Issue
Block a user