fix: Extract text content from Message objects for agent input#10009
Conversation
Previously, when Message objects were passed to agents, they were converted
to LangChain BaseMessage format which caused input to display as
'(content='text' additional_kwargs={} response_metadata={})' instead of
clean text.
This fix properly extracts the content attribute from LangChain messages
to ensure agents receive clean text input.
🤖 Generated with [Claude Code](https://claude.ai/code)
Co-Authored-By: Claude <noreply@anthropic.com>
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughNormalizes agent input handling: when input_value is a Message, it’s converted to an LC message and content is extracted (falling back to str). Otherwise, the raw input_value is used. The constructed input_dict now consistently uses input_text to ensure the "input" field is a string or derived content. Changes
Sequence Diagram(s)sequenceDiagram
autonumber
actor Caller
participant Agent
participant LCMessage as LC Message Converter
Caller->>Agent: run(input_value)
alt input_value is Message
Agent->>LCMessage: to_lc_message(input_value)
LCMessage-->>Agent: lc_message
Agent->>Agent: extract content or str(lc_message)
else input_value is not Message
Agent->>Agent: use input_value directly
end
Agent->>Agent: build input_dict with input_text in "input"
Agent-->>Caller: result
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Pre-merge checks and finishing touches❌ Failed checks (1 error, 2 warnings, 1 inconclusive)
✅ Passed checks (3 passed)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
edwinjosechittilappilly
left a comment
There was a problem hiding this comment.
I agree with the Fix but curious why it was causing issues for gpt4omini
edwinjosechittilappilly
left a comment
There was a problem hiding this comment.
I think we might need to improve to_lc_message also we might need to explore why this error occured I dont think there was any major chnages to to_lc_message. @ogabrielluiz what do you suggest? in this way the input_text is always a string.
Hey @edwinjosechittilappilly this error occurs because the langchain agent receives a string as input so if you pass something that is not a string it will convert it to string. |
|
ok In that case this PR approach seems to be correct. |
|



Summary
Fix agent input format issue where Message objects were passed as LangChain BaseMessage format instead of clean text.
Problem
When Message objects were passed to agents, they were converted to LangChain BaseMessage format which caused input to display as:
instead of clean text like
"text".Solution
Properly extract the
contentattribute from LangChain messages to ensure agents receive clean text input.Changes
src/lfx/src/lfx/base/agents/agent.pyto extract text content from Message objects before passing to agent🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Refactor