Skip to content

fix: Extract text content from Message objects for agent input#10009

Merged
ogabrielluiz merged 5 commits into
mainfrom
fix/agent-input-format
Sep 30, 2025
Merged

fix: Extract text content from Message objects for agent input#10009
ogabrielluiz merged 5 commits into
mainfrom
fix/agent-input-format

Conversation

@rodrigosnader
Copy link
Copy Markdown
Contributor

@rodrigosnader rodrigosnader commented Sep 27, 2025

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:

(content='text' additional_kwargs={} response_metadata={})

instead of clean text like "text".

Solution

Properly extract the content attribute from LangChain messages to ensure agents receive clean text input.

Changes

  • Modified src/lfx/src/lfx/base/agents/agent.py to extract text content from Message objects before passing to agent
  • Added proper handling for both Message objects and regular text input

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Improved robustness when providing message-based inputs to agents, preventing errors and inconsistent behavior.
    • Ensures agent inputs are consistently interpreted as text, even when messages lack explicit content.
  • Refactor

    • Standardized input normalization to reliably derive text from various input types, enhancing stability and predictability across agent interactions.

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>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Sep 27, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Normalizes 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

Cohort / File(s) Summary
Agent input normalization
src/lfx/src/lfx/base/agents/agent.py
Added input normalization: convert Message to LC message, extract content or fallback to string; replaced inline input construction with input_text to ensure "input" is consistently string-derived rather than a Message object.

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
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 error, 2 warnings, 1 inconclusive)
Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error I inspected the PR diff and only src/lfx/src/lfx/base/agents/agent.py was modified, with no new or updated test files discovered via the repository search, so the bug fix lacks a regression test that would verify the new Message content extraction behavior. Please add an automated test that covers passing a Message object to the agent and asserts the normalized text-only input, ensuring the regression is guarded going forward.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Test Quality And Coverage ⚠️ Warning No new or updated tests accompany the change in agent.py, so there is no coverage ensuring that Message objects are converted to plain text or that non-Message inputs still function correctly; manual inspection found no existing tests exercising this normalization path, leaving the updated behavior unverified. Please add or update tests that pass both Message objects and plain text into the agent input path, asserting that the output is normalized as expected, so the new behavior is covered.
Test File Naming And Structure ❓ Inconclusive No test files were added or modified in this pull request, and existing tests remain unchanged. Without changes to review, I cannot verify compliance with the required naming patterns, structure, and scenario coverage from the current diff. Please add or update the relevant tests so their naming, structure, and coverage can be evaluated against the stated criteria, or provide guidance on which existing tests should be reviewed.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately describes the main change by indicating that text content is extracted from Message objects for agent input, clearly reflecting the purpose of the modifications without extraneous details.
Excessive Mock Usage Warning ✅ Passed No test files are modified in this pull request, so there is no use of mocks to evaluate and consequently no evidence of excessive mocking related to the proposed changes.

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions Bot added the bug Something isn't working label Sep 27, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Sep 27, 2025
Copy link
Copy Markdown
Collaborator

@edwinjosechittilappilly edwinjosechittilappilly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the Fix but curious why it was causing issues for gpt4omini

Copy link
Copy Markdown
Collaborator

@edwinjosechittilappilly edwinjosechittilappilly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Sep 29, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Sep 29, 2025
@ogabrielluiz
Copy link
Copy Markdown
Contributor

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.

@edwinjosechittilappilly
Copy link
Copy Markdown
Collaborator

ok In that case this PR approach seems to be correct.

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Sep 30, 2025
@sonarqubecloud
Copy link
Copy Markdown

@ogabrielluiz ogabrielluiz added this pull request to the merge queue Sep 30, 2025
@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label Sep 30, 2025
Merged via the queue into main with commit 92f0e5b Sep 30, 2025
19 checks passed
@ogabrielluiz ogabrielluiz deleted the fix/agent-input-format branch September 30, 2025 20:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants