From dfbf85863b00c12891108d39652693916db5619a Mon Sep 17 00:00:00 2001 From: Mateusz Poliwczak Date: Thu, 16 Apr 2026 10:51:22 +0200 Subject: [PATCH] Change ToolResult.content to str --- splunklib/ai/engines/langchain.py | 7 ++----- splunklib/ai/tools.py | 4 ++-- tests/unit/ai/test_tool_settings.py | 2 +- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/splunklib/ai/engines/langchain.py b/splunklib/ai/engines/langchain.py index bd103724..80a87905 100644 --- a/splunklib/ai/engines/langchain.py +++ b/splunklib/ai/engines/langchain.py @@ -1354,10 +1354,7 @@ async def _tool_call( "ToolException from LangChain should not be raised in tool.func" ) - # TODO: Should we change the splunklib.ai.tools.ToolResult.content to a str, instead of list[str]? - text_content = "\n".join(result.content) - - artifact = ToolResult(text_content, result.structured_content) + artifact = ToolResult(result.content, result.structured_content) if result.structured_content: # For both local tools and remote tools (Splunk MCP Server App), the primary @@ -1371,7 +1368,7 @@ async def _tool_call( # this assumption may need to be revisited. For now, this approach is fine. # Worst-case scenario is the same information is provided to the LLM twice. return asdict(result), artifact # both content + structured_content - return text_content, artifact + return result.content, artifact return StructuredTool( name=_normalize_tool_name(tool.name, tool.type), diff --git a/splunklib/ai/tools.py b/splunklib/ai/tools.py index 3826221f..5846f08e 100644 --- a/splunklib/ai/tools.py +++ b/splunklib/ai/tools.py @@ -40,7 +40,7 @@ class ToolException(Exception): @dataclass(frozen=True) class ToolResult: - content: list[str] + content: str structured_content: dict[str, Any] | None @@ -243,7 +243,7 @@ def _convert_tool_result( text_contents.append(content.text) return ToolResult( - content=text_contents, structured_content=result.structuredContent + content="\n".join(text_contents), structured_content=result.structuredContent ) diff --git a/tests/unit/ai/test_tool_settings.py b/tests/unit/ai/test_tool_settings.py index 4715da5c..e6d5ac7f 100644 --- a/tests/unit/ai/test_tool_settings.py +++ b/tests/unit/ai/test_tool_settings.py @@ -7,7 +7,7 @@ async def no_op() -> ToolResult: - return ToolResult(content=[], structured_content={}) + return ToolResult(content="", structured_content={}) LOCAL_TOOL_1 = Tool(