fix: fix client injection code (#6421)
This commit is contained in:
committed by
Caren Thomas
parent
4d5be22d14
commit
0a0cf391fc
@@ -1287,7 +1287,7 @@ async def test_local_sandbox_with_client_injection(disable_e2b_api_key, list_too
|
||||
# Verify the script contains Letta client initialization
|
||||
assert "from letta_client import Letta" in script, "Script should import Letta client"
|
||||
assert "LETTA_API_KEY" in script, "Script should check for LETTA_API_KEY"
|
||||
assert "letta_client = Letta(" in script or "letta_client = None" in script, "Script should initialize Letta client"
|
||||
assert "client = Letta(" in script or "client = None" in script, "Script should initialize Letta client"
|
||||
|
||||
# Run the tool and verify it works
|
||||
result = await sandbox.run(agent_state=None)
|
||||
@@ -1345,6 +1345,6 @@ async def test_e2b_sandbox_with_client_injection(check_e2b_key_is_set, list_tool
|
||||
# Verify the script contains Letta client initialization
|
||||
assert "from letta_client import Letta" in script, "Script should import Letta client"
|
||||
assert "LETTA_API_KEY" in script, "Script should check for LETTA_API_KEY"
|
||||
assert "letta_client = Letta(" in script or "letta_client = None" in script, "Script should initialize Letta client"
|
||||
assert "client = Letta(" in script or "client = None" in script, "Script should initialize Letta client"
|
||||
|
||||
# Cannot run the tool since E2B is remote
|
||||
|
||||
@@ -401,6 +401,30 @@ def agent_state_ok(agent_state, value: int) -> str:
|
||||
return "ok"
|
||||
|
||||
|
||||
def client_ok(client, value: int) -> str:
|
||||
"""Ignores client param (injected Letta client).
|
||||
|
||||
Args:
|
||||
value (int): Some value.
|
||||
|
||||
Returns:
|
||||
str: Status.
|
||||
"""
|
||||
return "ok"
|
||||
|
||||
|
||||
def all_reserved_params_ok(agent_state, client, value: int) -> str:
|
||||
"""Ignores all reserved params.
|
||||
|
||||
Args:
|
||||
value (int): Some value.
|
||||
|
||||
Returns:
|
||||
str: Status.
|
||||
"""
|
||||
return "ok"
|
||||
|
||||
|
||||
class Dummy:
|
||||
def method(self, bar: int) -> str: # keeps an explicit self
|
||||
"""Bound-method example.
|
||||
@@ -446,6 +470,8 @@ def missing_param_doc(x: int, y: int) -> str:
|
||||
[
|
||||
(good_function, None),
|
||||
(agent_state_ok, None),
|
||||
(client_ok, None), # client is a reserved param (injected Letta client)
|
||||
(all_reserved_params_ok, None), # all reserved params together
|
||||
(Dummy.method, None), # unbound method keeps `self`
|
||||
(good_function_no_return, None),
|
||||
(no_doc, "has no docstring"),
|
||||
@@ -457,6 +483,28 @@ def test_google_style_docstring_validation(fn, regex):
|
||||
_check(fn, regex)
|
||||
|
||||
|
||||
def test_reserved_params_excluded_from_schema():
|
||||
"""Test that reserved params (agent_state, client) are excluded from generated schema."""
|
||||
from letta.functions.schema_generator import generate_schema
|
||||
|
||||
# Test with client param
|
||||
schema = generate_schema(client_ok)
|
||||
assert "client" not in schema["parameters"]["properties"], "client should be excluded from schema"
|
||||
assert "value" in schema["parameters"]["properties"], "value should be in schema"
|
||||
|
||||
# Test with agent_state param
|
||||
schema = generate_schema(agent_state_ok)
|
||||
assert "agent_state" not in schema["parameters"]["properties"], "agent_state should be excluded from schema"
|
||||
assert "value" in schema["parameters"]["properties"], "value should be in schema"
|
||||
|
||||
# Test with all reserved params
|
||||
schema = generate_schema(all_reserved_params_ok)
|
||||
assert "agent_state" not in schema["parameters"]["properties"], "agent_state should be excluded from schema"
|
||||
assert "client" not in schema["parameters"]["properties"], "client should be excluded from schema"
|
||||
assert "value" in schema["parameters"]["properties"], "value should be in schema"
|
||||
assert schema["parameters"]["required"] == ["value"], "only value should be required"
|
||||
|
||||
|
||||
def test_complex_nested_anyof_schema_to_structured_output():
|
||||
"""Test that complex nested anyOf schemas with inlined $refs can be converted to structured outputs.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user