feat: add prfefix to component tool names#1432
Conversation
|
@akihikokuroda, we should create a full proposal for this. I don't know if we want to prefix component tools with an index. I think we need to ensure that performance isn't impacted. We also need to make sure that we can clearly link tools to any given component, which might require more testing / planning. |
|
Small note on just an initial pass, I think this will have conflicts will #1430 adding |
|
@jakelorocco Here is a proposal. Proposed Solution: Object ID-Based PrefixingDesignUse Python object identity as the stable component identifier: component_id = hex(id(component))[-8:] # e.g., "a1b2c3d4"
prefixed_name = f"component_{component_id}.{original_tool_name}"Properties
Example: Multi-Turn Scenario with ID-Based PrefixingAdvantages Over Index-Based1. Multi-Turn Stability
2. Prevents Parallel Tool Collisions
3. Component Context Independence
4. Better Observability
5. Integrates with PR #1430 (Tool Tracing)
Performance ImpactAnalysis
Example with 10 tools:
Token CostName length comparison:
Example with 10 tools in JSON schema:
Conclusion: Performance impact is negligible. No performance concerns.
About concern:
Better Solution: Metadata on TemplateRepresentationInstead of reverse mapping, store component metadata on TemplateRepresentation: @dataclass
class TemplateRepresentation:
obj: Any
args: dict[...]
tools: dict[str, AbstractMelleaTool] | None = None
tool_name_mapping: dict[str, str] | None = None
# NEW: Component identity metadata
component_id: str | None = None # e.g., "a1b2c3d4"
component_type: str | None = None # e.g., "SearchAgent"
component_description: str | None = None # Optional Why This is Better
Usage Example# At tool registration time:
if isinstance(action, Component):
tr = action.format_for_llm()
if isinstance(tr, TemplateRepresentation):
tr.component_id = hex(id(action))[-8:]
tr.component_type = type(action).__name__
# tool_name_mapping already set
# All metadata in one place ✅
# At trace time:
span.set_attribute("mellea.component.id", tr.component_id)
span.set_attribute("mellea.component.type", tr.component_type)
# Metadata available without reverse mapping ✅
# In error messages:
error = f"Tool {tool_name} failed (component: {tr.component_type})"
# Clear attribution without reverse mapping ✅
# For debugging:
# User reads error message, sees component type, can correlate
# No need to reverse-map tool name back to component ✅ |
|
@akihikokuroda, I think this is still a good idea but we probably need some evaluations to indicate that the model can properly track the difference between components. Especially since we don't print component ids when outputting them currently. |
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
|
@jakelorocco I added examples. docs/examples/components/pattern2_context_and_tools.py shows the component tools renaming, executing and telemetry output. |
Signed-off-by: Akihiko Kuroda <akihikokuroda2020@gmail.com>
Pull Request
Issue
Fixes #95
Description
Testing
Attribution
Adding a new component, requirement, sampling strategy, or tool?
If your PR adds or modifies one of the types below, check the matching box. A checklist of type-specific review items will be posted as a comment.
NOTE: Please ensure you have an issue that has been acknowledged by a core contributor and routed you to open a pull request against this repository. Otherwise, please open an issue before continuing with this pull request.