Skip to content

Commit 4027060

Browse files
committed
fix: remove unused keys from Message template args
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 <ajbozart@us.ibm.com>
1 parent 8a835c5 commit 4027060

2 files changed

Lines changed: 1 addition & 41 deletions

File tree

mellea/stdlib/components/chat.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,7 @@ def format_for_llm(self) -> TemplateRepresentation:
8686
"""
8787
return TemplateRepresentation(
8888
obj=self,
89-
args={
90-
"role": self.role,
91-
"content": self._content_cblock,
92-
"images": self._images,
93-
"documents": self._docs,
94-
},
89+
args={"content": self._content_cblock, "documents": self._docs},
9590
template_order=["*", "Message"],
9691
)
9792

@@ -219,21 +214,6 @@ def __init__(
219214
self._tool_output = tool_output
220215
self._tool = tool
221216

222-
def format_for_llm(self) -> TemplateRepresentation:
223-
"""Return the same representation as ``Message`` with a ``name`` field added to the args dict.
224-
225-
Returns:
226-
TemplateRepresentation: Template representation including the tool
227-
name alongside the standard message fields.
228-
"""
229-
message_repr = super().format_for_llm()
230-
args = message_repr.args
231-
args["name"] = self.name
232-
233-
return TemplateRepresentation(
234-
obj=self, args=args, template_order=["*", "Message"]
235-
)
236-
237217
def __repr__(self) -> str:
238218
"""Pretty representation of messages, because they are a special case."""
239219
return f'mellea.ToolMessage(role="{self.role}", content="{self.content}", name="{self.name}")'

test/stdlib/components/test_chat.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,7 @@ def test_message_format_for_llm_structure():
8282
msg = Message("user", "hello")
8383
tr = msg.format_for_llm()
8484
assert isinstance(tr, TemplateRepresentation)
85-
assert tr.args["role"] == "user"
8685
assert tr.args["content"] is msg._content_cblock
87-
assert tr.args["images"] is None
8886
assert tr.args["documents"] is None
8987

9088

@@ -212,24 +210,6 @@ def test_tool_message_fields():
212210
assert tm.arguments == {"x": 1}
213211

214212

215-
def test_tool_message_format_for_llm_includes_name():
216-
from mellea.core import ModelToolCall
217-
218-
fake_tool = type("T", (), {"as_json_tool": {}})()
219-
mtc = ModelToolCall("my_tool", fake_tool, {})
220-
tm = ToolMessage(
221-
role="tool",
222-
content="output",
223-
tool_output="output",
224-
name="my_tool",
225-
args={},
226-
tool=mtc,
227-
)
228-
tr = tm.format_for_llm()
229-
assert isinstance(tr, TemplateRepresentation)
230-
assert tr.args["name"] == "my_tool"
231-
232-
233213
def test_tool_message_repr():
234214
from mellea.core import ModelToolCall
235215

0 commit comments

Comments
 (0)