From 4027060d03b30835b65c6efd01ecd7c22eebf40e Mon Sep 17 00:00:00 2001 From: Alex Bozarth Date: Mon, 4 May 2026 17:33:46 -0500 Subject: [PATCH] fix: remove unused keys from Message template args MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit role, images, and name were included in Message/ToolMessage.format_for_llm() args but are never consumed by any template — backends read them directly from the Message object. Their presence caused a false-positive warning from the unused-keys check added in #975. Since name was the only thing ToolMessage.format_for_llm() added, the override is now redundant and has been removed. Assisted-by: Claude Code Signed-off-by: Alex Bozarth --- mellea/stdlib/components/chat.py | 22 +--------------------- test/stdlib/components/test_chat.py | 20 -------------------- 2 files changed, 1 insertion(+), 41 deletions(-) diff --git a/mellea/stdlib/components/chat.py b/mellea/stdlib/components/chat.py index 41d397f95..a5837da6e 100644 --- a/mellea/stdlib/components/chat.py +++ b/mellea/stdlib/components/chat.py @@ -86,12 +86,7 @@ def format_for_llm(self) -> TemplateRepresentation: """ return TemplateRepresentation( obj=self, - args={ - "role": self.role, - "content": self._content_cblock, - "images": self._images, - "documents": self._docs, - }, + args={"content": self._content_cblock, "documents": self._docs}, template_order=["*", "Message"], ) @@ -219,21 +214,6 @@ def __init__( self._tool_output = tool_output self._tool = tool - def format_for_llm(self) -> TemplateRepresentation: - """Return the same representation as ``Message`` with a ``name`` field added to the args dict. - - Returns: - TemplateRepresentation: Template representation including the tool - name alongside the standard message fields. - """ - message_repr = super().format_for_llm() - args = message_repr.args - args["name"] = self.name - - return TemplateRepresentation( - obj=self, args=args, template_order=["*", "Message"] - ) - def __repr__(self) -> str: """Pretty representation of messages, because they are a special case.""" return f'mellea.ToolMessage(role="{self.role}", content="{self.content}", name="{self.name}")' diff --git a/test/stdlib/components/test_chat.py b/test/stdlib/components/test_chat.py index dae7a787c..e4ecb87dd 100644 --- a/test/stdlib/components/test_chat.py +++ b/test/stdlib/components/test_chat.py @@ -82,9 +82,7 @@ def test_message_format_for_llm_structure(): msg = Message("user", "hello") tr = msg.format_for_llm() assert isinstance(tr, TemplateRepresentation) - assert tr.args["role"] == "user" assert tr.args["content"] is msg._content_cblock - assert tr.args["images"] is None assert tr.args["documents"] is None @@ -212,24 +210,6 @@ def test_tool_message_fields(): assert tm.arguments == {"x": 1} -def test_tool_message_format_for_llm_includes_name(): - from mellea.core import ModelToolCall - - fake_tool = type("T", (), {"as_json_tool": {}})() - mtc = ModelToolCall("my_tool", fake_tool, {}) - tm = ToolMessage( - role="tool", - content="output", - tool_output="output", - name="my_tool", - args={}, - tool=mtc, - ) - tr = tm.format_for_llm() - assert isinstance(tr, TemplateRepresentation) - assert tr.args["name"] == "my_tool" - - def test_tool_message_repr(): from mellea.core import ModelToolCall