feat(core): support AWS Bedrock document content blocks in msg_content_output (#32799)

This commit is contained in:
Adithya1617
2025-09-09 01:10:28 +05:30
committed by GitHub
parent 3486d6c74d
commit f5bd00d1f1
2 changed files with 25 additions and 0 deletions

View File

@@ -81,6 +81,7 @@ TOOL_MESSAGE_BLOCK_TYPES = (
"json",
"search_result",
"custom_tool_call_output",
"document",
)

View File

@@ -52,6 +52,7 @@ from langchain_core.tools import (
tool,
)
from langchain_core.tools.base import (
TOOL_MESSAGE_BLOCK_TYPES,
ArgsSchema,
InjectedToolArg,
InjectedToolCallId,
@@ -1413,6 +1414,29 @@ def test_tool_call_input_tool_message_output() -> None:
tool.invoke(tool_call)
@pytest.mark.parametrize("block_type", [*TOOL_MESSAGE_BLOCK_TYPES, "bad"])
def test_tool_content_block_output(block_type: str) -> None:
@tool
def my_tool(query: str) -> list[dict[str, Any]]:
"""Test tool."""
return [{"type": block_type, "foo": "bar"}]
tool_call = {
"type": "tool_call",
"name": "my_tool",
"args": {"query": "baz"},
"id": "call_abc123",
}
result = my_tool.invoke(tool_call)
assert isinstance(result, ToolMessage)
if block_type in TOOL_MESSAGE_BLOCK_TYPES:
assert result.content == [{"type": block_type, "foo": "bar"}]
else:
assert result.content == '[{"type": "bad", "foo": "bar"}]'
class _MockStructuredToolWithRawOutput(BaseTool):
name: str = "structured_api"
args_schema: type[BaseModel] = _MockSchema