You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The naming and separation of events is messy and confusing:
There's different events for user and system messages, but the distinction is very artificial. The bodies have the same structure, the only difference is the role, which is also present in the body anyway, so a single event name would have worked.
genai: handle system role renamed to developer in openai #1877 shows that these roles change over time and aren't reliable enough to be embedded into the event name which needs to be very stable. One day new developers working with OpenAI will only be familiar with the role being called developer instead of system and won't understand why the event is called gen_ai.system.message.
Assistant message events can simultaneously contain text content with any number of tool calls, but for user messages these are split into multiple events. Why the inconsistency? Why not an event per tool call?
The event name gen_ai.tool.message doesn't make it clear that it means the result of a tool call, rather than the tool call itself. In other words, it's not clear at a glance whether it's sent by the user or assistant.
Tool calls have a type field which should apparently always be function, so its purpose is not clear.
Describe the solution you'd like
There needs to be a conceptual hierarchy, where a request consists of a list of messages, and a message consists of a list of 'parts'. Here's one way the events could look:
One event per message in the request, each with the same event name, e.g. gen_ai.message.
Each message event has role and content keys in the body, similar to the current events.
role is required and is used to distinguish between user, system, and assistant messages.
content in the body is an array of parts.
Each part is an object with a type field. Some possible values for type are text, image, tool_call, and tool_response.
If needed and possible, this field should account for multiple different types of tool call that the existing type field seems to be meant for.
The separate tool_calls array in the bodies of assistant and choice events are removed in favour of tool_call parts in the content array.
User and assistant messages (including the response choice events) all have the same structure, except that the choice events have additional fields (index, finish_reason) that don't make sense in the request events.
pydantic_ai has ModelMessage which is either ModelRequest or ModelResponse, each of which has a parts field which is a list of things like TextPart or ToolCallPart. This may seem like a biased example but the point is that pydantic_ai works with many different underlying AI APIs from different companies, and it translates between all those schemas and ModelMessage out of necessity.
Area(s)
area:gen-ai
What's missing?
developerinstead ofsystemand won't understand why the event is calledgen_ai.system.message.gen_ai.tool.messagedoesn't make it clear that it means the result of a tool call, rather than the tool call itself. In other words, it's not clear at a glance whether it's sent by the user or assistant.typefield which should apparently always befunction, so its purpose is not clear.Describe the solution you'd like
There needs to be a conceptual hierarchy, where a request consists of a list of messages, and a message consists of a list of 'parts'. Here's one way the events could look:
gen_ai.message.roleandcontentkeys in the body, similar to the current events.roleis required and is used to distinguish between user, system, and assistant messages.contentin the body is an array of parts.typefield. Some possible values fortypearetext,image,tool_call, andtool_response.typefield seems to be meant for.tool_callsarray in the bodies of assistant and choice events are removed in favour oftool_callparts in thecontentarray.choiceevents) all have the same structure, except that the choice events have additional fields (index, finish_reason) that don't make sense in the request events.Support for this data model:
pydantic_aihasModelMessagewhich is eitherModelRequestorModelResponse, each of which has apartsfield which is a list of things likeTextPartorToolCallPart. This may seem like a biased example but the point is thatpydantic_aiworks with many different underlying AI APIs from different companies, and it translates between all those schemas andModelMessageout of necessity.