tests: assistant msg validation error (#6536)
* add regression test for dict content in AssistantMessage
Tests the fix for pydantic validation error when send_message tool
returns dict content like {'tofu': 1, 'mofu': 1, 'bofu': 1}.
The test verifies that dict content is properly serialized to JSON
string before creating AssistantMessage.
* improve type annotation for validate_function_response
Changed return type from Any to str | dict[str, Any] to match actual
behavior. This enables static type checkers (pyright, mypy) to catch
type mismatches like the AssistantMessage bug.
With proper type annotations, pyright would have caught:
error: Argument of type "str | dict[str, Any]" cannot be assigned
to parameter "content" of type "str"
This prevents future bugs where dict is passed to string-only fields.
* add regression test for dict content in AssistantMessage
Moved test into existing test_message_manager.py suite alongside other
message conversion tests.
Tests the fix for pydantic validation error when send_message tool
returns dict content like {'tofu': 1, 'mofu': 1, 'bofu': 1}.
The test verifies that dict content is properly serialized to JSON
string before creating AssistantMessage.
This commit is contained in:
@@ -854,7 +854,9 @@ def parse_json(string) -> dict:
|
||||
raise e
|
||||
|
||||
|
||||
def validate_function_response(function_response: Any, return_char_limit: int, strict: bool = False, truncate: bool = True) -> Any:
|
||||
def validate_function_response(
|
||||
function_response: Any, return_char_limit: int, strict: bool = False, truncate: bool = True
|
||||
) -> str | dict[str, Any]:
|
||||
"""Check to make sure that a function used by Letta returned a valid response. Truncates to return_char_limit if necessary.
|
||||
|
||||
This makes sure that we can coerce the function_response into a string or dict that meets our criteria. We handle some soft coercion.
|
||||
|
||||
Reference in New Issue
Block a user