Skip to content

Conversation

@maslo55555
Copy link
Contributor

@maslo55555 maslo55555 commented Dec 7, 2025

Description

Fixes an issue where using createAgent with a custom name parameter (e.g., name: 'my_agent') causes Google GenAI to throw an error: Unknown / unsupported author: <custom_agent_name>.

Problem

When creating a ReactAgent with a custom name, the agent sets this name on AIMessage objects. However, Google GenAI's getMessageAuthor function was returning the custom name instead of the message type, causing convertAuthorToRole to fail since Google GenAI only supports standard roles: model, user, function, and system.

Solution

Modified getMessageAuthor in libs/providers/langchain-google-genai/src/utils/common.ts to always return the message type, ignoring custom names which are metadata for tracking in multi-agent scenarios but not supported by Google GenAI's API.

Changes

  • Updated getMessageAuthor to return message type instead of message.name ?? type
  • Added comprehensive tests to verify AIMessages with custom names work correctly
  • Added documentation explaining why custom names are ignored

Testing

Added unit tests in chat_models.test.ts:

  • Test that getMessageAuthor returns message type for AIMessages with custom names
  • Test that convertBaseMessagesToContent handles messages with custom agent names without throwing errors

Example

After this fix, the following code works correctly:

import { createAgent, tool } from 'langchain';

const agent = createAgent({
  model: 'google-genai:gemini-2.0-flash',
  tools: [myTool],
  name: 'my_agent', // This now works!
});

When using createAgent with a name parameter (e.g., name: 'math_expert'),
the agent sets this name on AIMessage objects. However, Google GenAI's
getMessageAuthor function was returning the custom name instead of the
message type, causing convertAuthorToRole to fail since Google GenAI
only supports standard roles (model, user, function, system).

This fix modifies getMessageAuthor to always return the message type,
ignoring custom names which are metadata for tracking in multi-agent
scenarios but not supported by Google GenAI's API.

Fixes the error: Unknown / unsupported author: <custom_agent_name>
@changeset-bot
Copy link

changeset-bot bot commented Dec 7, 2025

🦋 Changeset detected

Latest commit: 22b67e2

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 6 packages
Name Type
@langchain/google-genai Patch
@langchain/google-common Patch
@langchain/google-gauth Patch
@langchain/google-webauth Patch
@langchain/google-vertexai Patch
@langchain/google-vertexai-web Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@hntrl hntrl merged commit 5b27f38 into langchain-ai:main Dec 7, 2025
22 checks passed
@github-actions github-actions bot mentioned this pull request Dec 7, 2025
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.

2 participants