Skip to content

Support role: "tool" / tool_call_id feedback for tool results #1389

Closed

Description

@AngeloDanducci

Follow up to #1349

What: Feed tool results back to OpenAI-compatible providers as role: "tool" messages with a matching tool_call_id, instead of as user text.

Why: Spec-strict providers may still mishandle the result turn even though the assistant tool-call turn is now correct. The PR author flagged this as intentionally out of scope The role: "tool" / tool_call_id feedback half (the reporter currently feeds tool results back as user text) is left as a follow-up.

Scope: ToolMessage/Message serialization in mellea/helpers/openai_compatible_helpers.py, plus wherever tool results are appended to context.

Activity

  1. added
    area/tools
    on Jul 14, 2026
  2. ajbozarth commented on Jul 22, 2026

    @ajbozarth
    Member

    Heads-up from the execute_tool span work (#1430): that PR adds ModelToolCall.tool_call_id, populated with the real provider-supplied call id end-to-end — non-streaming and streaming, across the OpenAI-compatible, LiteLLM, Watsonx, and Ollama backends. It's None only for raw-string tool parsing and providers that don't send an id.

    With that field now available, the threading/serialization work here has two concrete spots:

    1. Result turn (this issue's core): ToolMessage carries its ModelToolCall (_tool), so the result turn can read the genuine id from _tool.tool_call_id instead of inventing one.
    2. Assistant turn: build_tool_calls (mellea/helpers/openai_compatible_helpers.py:407) currently fabricates a fresh random id (f"call_{uuid.uuid4().hex[:24]}") on every replayed tool-call turn, discarding the provider's original. It should use model_tool_call.tool_call_id when present, falling back to a generated id only when it's None.

    These two should land together: threading the real id into the result turn while the assistant turn still uses a fabricated one would leave the call and its result with mismatched ids. #1430 intentionally left build_tool_calls:407 as-is — capturing the id is in scope for the span work, spending it (replay serialization) belongs here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

area/tools

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions