prebuilt: includeAgentName and withAgentName won't work if provider disallows editing AIMessage history #254

Open
opened 2026-02-15 18:15:06 -05:00 by yindo · 0 comments
Owner

Originally created by @benjamincburns on GitHub (May 12, 2025).

Supervisor and co rely on setting the name field of AIMessage to indicate which agent generated which AIMessage in the message history. Few providers actually observe this field, so the includeAgentName parameter was introduced (e.g. see #1174 and #1176) that modifies past AIMessages to follow the format <name>${agentName}</name><content>${content}</content>.

This is fine in cases when the chat model provider allows updates of previous AIMessages in context, but there are cases where this is disallowed (e.g. when referencing past messages using the OpenAI responses API, or when using thinking blocks with Anthropic).

There may be multiple ways to fix this (including provider-specific approaches), but the most reliable strategy that I can think of to get around this issue would be to get the model to generate its output in this format. This could involve modifying the system message to include prompting that tells the model to use this format using structured output when available.

Originally created by @benjamincburns on GitHub (May 12, 2025). Supervisor and co rely on setting the `name` field of `AIMessage` to indicate which agent generated which `AIMessage` in the message history. Few providers actually observe this field, so the `includeAgentName` parameter was introduced (e.g. see #1174 and #1176) that modifies past AIMessages to follow the format `<name>${agentName}</name><content>${content}</content>`. This is fine in cases when the chat model provider allows updates of previous AIMessages in context, but there are cases where this is disallowed (e.g. when referencing past messages using the OpenAI responses API, or when using thinking blocks with Anthropic). There may be multiple ways to fix this (including provider-specific approaches), but the most reliable strategy that I can think of to get around this issue would be to get the model to generate its output in this format. This could involve modifying the system message to include prompting that tells the model to use this format using structured output when available.
yindo added the bug label 2026-02-15 18:15:06 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#254