Skip to content

🐛 Bug Report: LangChain Tool handling. Tool content in message history and 'tool' message type #2938

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

Closed
1 task done
dinmukhamedm opened this issue May 12, 2025 · 0 comments · Fixed by #2939
Closed
1 task done

Comments

@dinmukhamedm
Copy link
Collaborator

Which component is this bug for?

Langchain Instrumentation

📜 Description

Larger bug: In message history in assistant messages (gen_ai.prompt.N.content) the content is empty if the message was a tool call.

Smaller bug: Message type tool automatically gets converted to unknown. I am not sure if any of the observability platforms (in particular, Traceloop) rely on the message type to be one of user, assistant, unknown, but I'd say conversions like this must happen in the backend.

👟 Reproduction steps

from langchain_core.messages import HumanMessage, AIMessage, ToolMessage, SystemMessage, BaseMessage
from langchain_openai import ChatOpenAI

def get_weather(location: str) -> str:
    return "sunny"

messages: list[BaseMessage] = [
    SystemMessage(content="Be crisp and friendly."),
    HumanMessage(content="Hey, what's the weather in San Francisco?"),
    AIMessage(
        content="",
        tool_calls=[
            {
                "name": "get_weather",
                "args": {"location": "San Francisco"},
                "id": "tool_123",
                "type": "tool_call",
            }
        ],
    ),
    ToolMessage(content="Sunny as always!", tool_call_id="tool_123"),
    HumanMessage(content="What's the weather in London?"),
]
model = ChatOpenAI(model="gpt-4.1-nano", temperature=0)
model_with_tools = model.bind_tools([get_weather])
result = model_with_tools.invoke(messages)

👍 Expected behavior

gen_ai.prompts.2.content has the tool_calls
gen_ai.prompts.3.role == tool

👎 Actual Behavior with Screenshots

gen_ai.prompts.2.content is empty
gen_ai.prompts.3.role == unknown

🤖 Python Version

3.13

📃 Provide any additional context for the Bug.

No response

👀 Have you spent some time to check if this bug has been raised before?

  • I checked and didn't find similar issue

Are you willing to submit PR?

Yes I am willing to submit a PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant