Skip to content

AI Message with No Content but Tool Calls Gets Removed #874

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
AustinJiangH opened this issue Apr 18, 2025 · 0 comments
Open

AI Message with No Content but Tool Calls Gets Removed #874

AustinJiangH opened this issue Apr 18, 2025 · 0 comments

Comments

@AustinJiangH
Copy link

An AIMessage with no text content but only tool calls will be trimmed out.

AIMessage(
        content="",
        additional_kwargs={},
        response_metadata={
            "id": "msg_vrtx_23232323232323",
            "model": "claude-3-5-sonnet-v2-20241022",
            "stop_reason": "tool_use",
            "stop_sequence": None,
            "usage": {
                "cache_creation_input_tokens": 0,
                "cache_read_input_tokens": 0,
                "input_tokens": 111,
                "output_tokens": 111,
            },
        },
        name="tool_call_node",
        id="run-xxxxxxx",
        tool_calls=[
            {
                "name": "mocked_tool",
                "args": {
                    "arg_1": "value_1",
                    "arg_2": ["value2"],
                },
                "id": "toolu_vrtx_23232323233232323",
                "type": "tool_call",
            }
        ],
        usage_metadata={
            "input_tokens": 111,
            "output_tokens": 111,
            "total_tokens": 222,
            "cache_creation_input_tokens": 0,
            "cache_read_input_tokens": 0,
        },
    )

The error is in this function.

def _format_message_anthropic(
message: Union[HumanMessage, AIMessage, SystemMessage], project: Optional[str]
):
"""Format a message for Anthropic API.
Args:
message: The message to format. Can be HumanMessage, AIMessage, or SystemMessage.
Returns:
A dictionary with the formatted message, or None if the message is empty.
""" # noqa: E501
content: List[Dict[str, Any]] = []
if isinstance(message.content, str):
if not message.content.strip():
return None

@langcarl langcarl bot added the investigate label Apr 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant