Allow CallToolResult to be returned directly to support _meta field for OpenAI Apps (#1459)
Co-authored-by: Max Isbey <224885523+maxisbey@users.noreply.github.com>
This commit is contained in:
parent
40acbc596c
commit
1200ba0082
1 changed files with 445 additions and 5 deletions
|
|
@ -391,6 +391,47 @@ async def test_both_content_and_valid_dict_with_output_schema():
|
|||
assert result.structuredContent == {"sentiment": "positive", "confidence": 0.95}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_tool_call_result():
|
||||
"""Test returning ToolCallResult when no outputSchema is defined."""
|
||||
tools = [
|
||||
Tool(
|
||||
name="get_info",
|
||||
description="Get structured information",
|
||||
inputSchema={
|
||||
"type": "object",
|
||||
"properties": {},
|
||||
},
|
||||
# No outputSchema for direct return of tool call result
|
||||
)
|
||||
]
|
||||
|
||||
async def call_tool_handler(name: str, arguments: dict[str, Any]) -> CallToolResult:
|
||||
if name == "get_info":
|
||||
return CallToolResult(
|
||||
content=[TextContent(type="text", text="Results calculated")],
|
||||
structuredContent={"status": "ok", "data": {"value": 42}},
|
||||
_meta={"some": "metadata"},
|
||||
)
|
||||
else:
|
||||
raise ValueError(f"Unknown tool: {name}")
|
||||
|
||||
async def test_callback(client_session: ClientSession) -> CallToolResult:
|
||||
return await client_session.call_tool("get_info", {})
|
||||
|
||||
result = await run_tool_test(tools, call_tool_handler, test_callback)
|
||||
|
||||
# Verify results
|
||||
assert result is not None
|
||||
assert not result.isError
|
||||
assert len(result.content) == 1
|
||||
assert result.content[0].type == "text"
|
||||
assert result.content[0].text == "Results calculated"
|
||||
assert isinstance(result.content[0], TextContent)
|
||||
assert result.structuredContent == {"status": "ok", "data": {"value": 42}}
|
||||
assert result.meta == {"some": "metadata"}
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_output_schema_type_validation():
|
||||
"""Test outputSchema validates types correctly."""
|
||||
|
|
|
|||
Loading…
Reference in a new issue