Collapse `Message`/`ToolMessage` handling into generic `Component` handling
メンテナーはふだん 3 日以内に返信
@AngeloDanducci がすでに取り組んでいます。
2026年8月17日 から。
評価
この issue はまだ評価されていません。
説明
Context
Follow-up to #1542 (allow components to declare their chat role via format_for_llm) and its umbrella #1030 (message serialization). During that work we explored whether the special-cased Message/ToolMessage handling could be collapsed into the generic Component handling - i.e. move message serialization entirely onto the TemplateRepresentation -> Message path so a plain custom Component could express everything a Message can.
The blocker: collapsing Message into Component would regress the #1389 ToolMessage work.
#1389 made tool results round-trip to OpenAI-compatible providers as spec-strict role: "tool" messages with a matching tool_call_id. TemplateRepresentation has since grown role, tool_calls, tool_call_id, and thinking, so a plain Component can already produce a serialization-shaped role: "tool" Message via message_from_template_representation. But ToolMessage still carries live, typed, non-serializable state that TemplateRepresentation cannot express, and that state is consumed by code paths other than the OpenAI serializer.
-
mellea/stdlib/components/chat.pylines 261-296 (ToolMessage) -ToolMessagestores_tool(the fullModelToolCall),_tool_output(the raw Python return value of the tool, not a string),arguments, andname.TemplateRepresentationonly carries serialization (tool_calls: list[dict],tool_call_id: str) - it has no channel for a liveModelToolCallor a typed tool-output object. AComponent->Messageconversion therefore cannot reconstruct aToolMessage; the typed state is lost. -
mellea/stdlib/functional.py(transform/atransform, ~lines 484, 498-507, 1263, 1277-1286, 1377, 1408) - these paths depend on the liveToolMessagestate, not on its serialized form:type(output._tool_output) is type(obj)matches the raw return value by Python type, andchosen_tool._tool.args/chosen_tool._tool.nameread theModelToolCalldirectly. If tool results were only ever plainMessages reconstructed from aTemplateRepresentation,transformwould lose its type-matching and argument-introspection and regress. -
mellea/formatters/chat_formatter.py(case Message(): return c) andmellea/stdlib/components/chat.py(as_chat_history/as_generic_chat_history) - theMessageshort-circuit returns the object verbatim, soToolMessagesubtype identity (and its_tool.tool_call_id) survives to the backend payload. A collapse that routed every turn throughTemplateRepresentationwould drop this short-circuit and, with it, the subtype.
What a real collapse would require (for the future design discussion)
- A way for the intermediate representation to carry live objects, not just serialization - e.g. an optional
ModelToolCall/ raw tool-output slot onTemplateRepresentation, or a separate live-state channel. This is a departure from theimages/audio/roleprecedent, which are all serialization-shaped - A decision on whether a component declaring tool semantics should materialize a
ToolMessage(sofunctional.transform's type-matching keeps working) rather than a plainMessage, and how it would supply the raw_tool_output - Keeping the
functional.pytransform/atransformcontract (_tool_outputtype-match,_tool.args/_tool.nameintrospection) intact through whatever new path replaces theMessageshort-circuit
Notes
- Open question for the design discussion: is
TemplateRepresentationthe right home for live/typed state at all, or shouldMessage/ToolMessageremain a deliberately-special "already-materialized" case that bypasses the intermediate representation (the currentcase Message(): return cshort-circuit)? The exploration leans toward the latter being intentional, not accidental - Related: #1030 (umbrella), #1389 (tool-result
role: "tool"/tool_call_id), #1542 (component-declared role)
- 主要言語
- Python
- スター
- 1.8k
- フォーク
- 161
- 平均マージ
- 4日 3時間
- マージ済み PR(30日)
- 45
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
generative-computing/mellea のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
generative-computing/mellea#1864 ·
メンテナーはふだん 3 日以内に返信
-
bug: instruct() and react() replay tool-call turns without tool_calls対応中かも @simonyang08 が 21 日前に担当しました。 オープンbug
難易度 2/5 1〜3時間 初心者へのやさしさ 85/100
generative-computing/mellea#1784 · コメント 1 件 ·
メンテナーはふだん 3 日以内に返信
-
Silently mangled docstrings: lone backslash line-continuations in non-raw docstrings collapse command examples対応中かも @madhusudhan1260 が 18 日前に担当しました。 オープンgood first issue p2
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
generative-computing/mellea#1780 · コメント 2 件 · 担当者 1 名 ·
メンテナーはふだん 3 日以内に返信
-
area/telemetry enhancement p2
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
generative-computing/mellea#1210 ·
メンテナーはふだん 3 日以内に返信
-
area/requirement area/stdlib enhancement p2
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
generative-computing/mellea#31 · コメント 2 件 ·
メンテナーはふだん 3 日以内に返信
generative-computing/mellea の issue をすべて見る
似ている issue
-
bug game: 0100FF500E34A000 game: 0400FF500E34A001 mac packing
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
メンテナーはふだん 2 日以内に返信
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 74/100
jxxghp/MoviePilot#7576 ·
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 88/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 64/100
jbaruch/software-factory#266 ·
メンテナーはふだん 1 日以内に返信
-
cron: raise a distinct error when next_fire finds no match in its search bound (from #813 item 5)オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 1 日以内に返信