Skip to content

GenAI handle tool message embedded within user message #1883

@aabmass

Description

@aabmass

Area(s)

area:gen-ai

What's missing?

OpenAI treats tool call responses as a separate "role" with its own type. VertexAI instead represents tool responses as another variant of Part which can appear without a role or within a user role (function calling docs), for example

{
  "role": "user",
  "parts": [
    {
      "functionResponse": {
        "name": "get_current_weather",
        "response": {
          "content": "{\"temperature\": 35, \"unit\": \"C\"}"
        }
      }
    },
    {
      "functionResponse": {
        "name": "get_current_weather",
        "response": {
          "content": "{\"temperature\": 25, \"unit\": \"C\"}"
        }
      }
    },
    {
      "text": "Please respond in French"
    }
  ]
}

(Full example in open-telemetry/opentelemetry-python-contrib@f322c46)

This doesn't really fit with the semconv for gen_ai.tool.message. Vertex has overlap of user event and tool events, similar to how tool call requests are embedded in gen_ai.choice events.

Describe the solution you'd like

We could either adapt the semconv to embed tool calls in gen_ai.user.message event or keep the current semconv and massage Vertex response into it.

Possible options for massaging the data:

  1. One gen_ai.user.message with just "Please respond in French" content plus two gen_ai.tool.message for the tool calls.
  2. One gen_ai.user.message event with all three parts in it plus two gen_ai.tool.message duplicating the tool calls.

The benefit of 2. is for debugging you can actually reconstruct the exact original API request.

Metadata

Metadata

Assignees

Type

No type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions