Skip to content

feat: support OpenAI 'developer' role in ChatMessage (#12604) - #12991

Closed
Taranum01 wants to merge 1 commit into
deepset-ai:mainfrom
Taranum01:fix/12604-chat-message-developer-role
Closed

Taranum01 wants to merge 1 commit into
deepset-ai:mainfrom
Taranum01:fix/12604-chat-message-developer-role

Conversation

@Taranum01

Copy link
Copy Markdown

Summary

Fixes #12604.

OpenAI exposes a 'developer' chat role that was silently downgraded to ChatRole.SYSTEM by ChatMessage.from_openai_dict_format. _validate_openai_message and to_openai_dict_format already accepted 'developer', so the value was preserved on the wire but lost its identity on the client. This PR adds first-class ChatRole.DEVELOPER support so the role survives a round-trip.

Changes

  • haystack/dataclasses/chat_message.py
    • Added ChatRole.DEVELOPER = "developer".
    • Added ChatMessage.from_developer(content, meta, name) classmethod, mirroring from_system.
    • Split from_openai_dict_format: "developer" -> from_developer; "system" -> from_system. "user" / "assistant" / "tool" unchanged.

Tests

  • test/dataclasses/test_chat_message.py
    • test_chat_role_developer_value
    • test_from_developer_basic
    • test_from_developer_with_meta_and_name
    • test_from_openai_dict_format_developer_role
    • test_to_openai_dict_format_developer_role
    • test_round_trip_developer_role_preserved
    • test_round_trip_system_role_unchanged

@Taranum01
Taranum01 requested a review from a team as a code owner September 27, 2026 22:59
@Taranum01
Taranum01 requested review from sjrl and removed request for a team September 27, 2026 22:59
@vercel

vercel Bot commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Someone is attempting to deploy a commit to the deepset Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions

Copy link
Copy Markdown
Contributor

Hi @Taranum01, thanks for your interest in contributing to Haystack! 🙏

⚠️ You currently have 3 open pull requests in this repository (#12993, #12992 and this one). Our review capacity is limited, so please hold off opening more PRs until we've had a chance to review your first 2 open PRs. This helps us give each contribution the attention it deserves. Thank you!

This is an automated message to help us keep the review queue healthy.

@CLAassistant

CLAassistant commented Sep 27, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

Add a DEVELOPER entry to the ChatRole enum and a ChatMessage.from_developer
classmethod. from_openai_dict_format now maps 'developer' to ChatRole.DEVELOPER
(via from_developer) instead of silently collapsing it into ChatRole.SYSTEM,
so to_openai_dict_format round-trips the role correctly. system messages
continue to round-trip unchanged.
@Taranum01
Taranum01 force-pushed the fix/12604-chat-message-developer-role branch from e163a78 to 3f939c0 Compare September 27, 2026 23:25
@sjrl

sjrl commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

Thanks for the PR! However, we don't want a new ChatRole here. Adding the role would mean updating every place that special-cases ChatRole.SYSTEM (ChatPromptBuilder, the Jinja message tag, compaction, Agent, and the integrations that extract system messages). On the OpenAI side the two roles behave the same: in a quick test against Chat Completions (gpt-4o-mini, gpt-4.1-nano, gpt-5-nano, o4-mini, o1) both were accepted with identical prompt token counts.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ChatMessage.from_openai_dict_format silently collapses OpenAI's 'developer' role into 'system'

3 participants