Skip to content

fix: Restore Agent memory functionality by fixing inheritance and type compatibility#10008

Merged
ogabrielluiz merged 8 commits into
mainfrom
fix/agent-memory-issues
Sep 29, 2025
Merged

fix: Restore Agent memory functionality by fixing inheritance and type compatibility#10008
ogabrielluiz merged 8 commits into
mainfrom
fix/agent-memory-issues

Conversation

@rodrigosnader
Copy link
Copy Markdown
Contributor

@rodrigosnader rodrigosnader commented Sep 27, 2025

Summary

  • Fixes two critical bugs that completely broke Agent memory in the main branch
  • Agents can now remember conversation context across messages
  • Restores memory functionality to same level as release-1.6.0

Bugs Fixed

Bug #1: Inheritance Method Call Error

  • Problem: Agent components called non-existent get_base_inputs() method
  • Fix: Changed to correct _base_inputs attribute access
  • Files:
    • src/lfx/src/lfx/components/agents/agent.py:157
    • src/lfx/src/lfx/base/agents/agent.py:229

Bug #2: Message Type Incompatibility

  • Problem: Memory system returns langflow.schema.message.Message but Agent expected lfx.schema.message.Message
  • Result: Type check failed → chat history ignored → Agent ran with zero memory
  • Fix: Updated type checking to use duck typing instead of strict isinstance check
  • File: src/lfx/src/lfx/base/agents/agent.py:148-150

Test Results

Before: Agent says "I don't have access to your name or occupation"
After: Agent says "Your name is VICTORY TEST, and you work as a memory bug hunter"

Changes

  • 3 lines changed across 2 files
  • No breaking changes
  • Backward compatible

🤖 Generated with Claude Code

Summary by CodeRabbit

  • New Features
    • Agents now accept chat histories containing different message object types, improving interoperability with varied schemas.
  • Refactor
    • Streamlined how base inputs are sourced for agent components to improve consistency and maintainability, with no expected change in behavior.

…e compatibility

This commit fixes two critical bugs that completely broke Agent memory in the main branch:

## Bug #1: Inheritance Method Call Error
- Fixed incorrect method calls in Agent component inheritance
- Changed `get_base_inputs()` to `_base_inputs` in:
  - src/lfx/src/lfx/components/agents/agent.py:157
  - src/lfx/src/lfx/base/agents/agent.py:229

## Bug #2: Message Type Incompatibility
- Fixed type checking in Agent base class to handle both Message types
- Memory returns `langflow.schema.message.Message` but Agent expected `lfx.schema.message.Message`
- Updated type check to use duck typing instead of strict isinstance check
- Changed in src/lfx/src/lfx/base/agents/agent.py:148-150

## Impact
- Agents can now remember conversation context across messages
- Memory functionality restored to same level as release-1.6.0
- Fixes issue where agents would forget user information immediately

## Test Results
- Before: Agent says "I don't have access to your name or occupation"
- After: Agent says "Your name is VICTORY TEST, and you work as a memory bug hunter"

🤖 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

Updates adjust chat_history handling in run_agent to detect items with to_data for interoperability between Message types, and switch base inputs sourcing from public methods to a private _base_inputs attribute in LCToolsAgentComponent and AgentComponent.

Changes

Cohort / File(s) Summary of Changes
Agent runtime chat history handling
src/lfx/src/lfx/base/agents/agent.py
Updated run_agent to transform chat_history by checking for a to_data method on elements, supporting both lfx.schema.message.Message and langflow.schema.message.Message without strict isinstance checks.
Components base inputs sourcing
src/lfx/src/lfx/base/agents/agent.py, src/lfx/src/lfx/components/agents/agent.py
Replaced calls to get_base_inputs() with the private attribute _base_inputs to assemble base inputs for agent components.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant U as Caller
  participant AC as Agent Component
  participant RA as run_agent
  participant AG as Agent

  U->>AC: invoke(...)
  AC->>RA: run_agent(inputs, chat_history)
  activate RA
  note right of RA: Normalize chat_history<br/>- if item has to_data(), call it<br/>- otherwise pass through
  RA->>AG: execute(inputs, normalized_history)
  AG-->>RA: result
  deactivate RA
  RA-->>AC: result
  AC-->>U: result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 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 No new or updated test files are present in this PR, and the bug fix that restores agent memory lacks a corresponding regression test to prevent future regressions, so the custom test-coverage criterion is not satisfied. Please add a regression test that exercises the restored agent memory behavior—verifying that mixed Message types are handled and base inputs work as intended—using the repository’s test naming conventions so the coverage aligns with the fix.
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 agent memory fixes, and existing suites appear unchanged, leaving the restored duck-typing logic and the corrected base-input wiring uncovered. Without targeted regression or behavioral tests confirming the agent now preserves and recalls chat history after these changes, the main functionality described in the PR objectives is not validated. Please add focused tests that exercise an agent retaining and recalling chat history with both message types, ensuring the duck-typing path and corrected base-input inheritance are verified, then rerun the check.
Test File Naming And Structure ❓ Inconclusive The pull request does not introduce or modify any test files, so there is no evidence that would allow verification of naming patterns, structure, or coverage per the specified criteria; without relevant artifacts or additional context, compliance with the test file requirements remains indeterminate. Please provide or reference the affected test files, or clarify whether new tests are required for this change, so that compliance with the naming and structural guidelines can be evaluated.
✅ 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 concisely summarizes the primary change by stating that it restores Agent memory functionality while indicating the fixes for inheritance and type compatibility, directly reflecting the pull request’s objectives without extraneous details or noise.
Excessive Mock Usage Warning ✅ Passed No test files were modified in this pull request, so there are no new or altered mocks to evaluate and no evidence of excessive mock usage impacting test quality. Consequently, the existing tests remain unchanged with respect to how mocks are employed.

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
🧪 Early access (Sonnet 4.5): enabled

We are currently testing the Sonnet 4.5 model, which is expected to improve code review quality. However, this model may lead to increased noise levels in the review comments. Please disable the early access features if the noise level causes any inconvenience.

Note:

  • Public repositories are always opted into early access features.
  • You can enable or disable early access features from the CodeRabbit UI or by updating the CodeRabbit configuration file.

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
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a892fe4 and 835175e.

📒 Files selected for processing (2)
  • src/lfx/src/lfx/base/agents/agent.py (2 hunks)
  • src/lfx/src/lfx/components/agents/agent.py (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
src/lfx/src/lfx/components/agents/agent.py (1)
src/lfx/src/lfx/base/agents/agent.py (1)
  • LCToolsAgentComponent (220-269)
🪛 GitHub Check: Ruff Style Check (3.13)
src/lfx/src/lfx/base/agents/agent.py

[failure] 149-149: Ruff (Q000)
src/lfx/src/lfx/base/agents/agent.py:149:66: Q000 Single quotes found but double quotes preferred


[failure] 149-149: Ruff (B009)
src/lfx/src/lfx/base/agents/agent.py:149:55: B009 Do not call getattr with a constant attribute value. It is not any safer than normal property access.


[failure] 149-149: Ruff (Q000)
src/lfx/src/lfx/base/agents/agent.py:149:31: Q000 Single quotes found but double quotes preferred

🪛 GitHub Actions: Ruff Style Check
src/lfx/src/lfx/base/agents/agent.py

[error] 149-149: Q000 Single quotes found but double quotes preferred (Ruff: formatting rule).

⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Update Starter Projects

Comment thread src/lfx/src/lfx/base/agents/agent.py Outdated
Comment on lines 149 to 150
if all(hasattr(m, 'to_data') and callable(getattr(m, 'to_data')) for m in self.chat_history):
input_dict["chat_history"] = data_to_messages([m.to_data() for m in self.chat_history])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Resolve Ruff lint failure in chat history duck-typing check

Ruff is currently red on this PR (Q000/B009) because of the single quotes and the getattr call without a default. Switching to double quotes and using a default-backed getattr clears the lint failure while keeping the duck-typing logic intact.

-            if all(hasattr(m, 'to_data') and callable(getattr(m, 'to_data')) for m in self.chat_history):
-                input_dict["chat_history"] = data_to_messages([m.to_data() for m in self.chat_history])
+            if all(callable(getattr(message, "to_data", None)) for message in self.chat_history):
+                input_dict["chat_history"] = data_to_messages(
+                    [message.to_data() for message in self.chat_history]
+                )
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if all(hasattr(m, 'to_data') and callable(getattr(m, 'to_data')) for m in self.chat_history):
input_dict["chat_history"] = data_to_messages([m.to_data() for m in self.chat_history])
if all(callable(getattr(message, "to_data", None)) for message in self.chat_history):
input_dict["chat_history"] = data_to_messages(
[message.to_data() for message in self.chat_history]
)
🧰 Tools
🪛 GitHub Check: Ruff Style Check (3.13)

[failure] 149-149: Ruff (Q000)
src/lfx/src/lfx/base/agents/agent.py:149:66: Q000 Single quotes found but double quotes preferred


[failure] 149-149: Ruff (B009)
src/lfx/src/lfx/base/agents/agent.py:149:55: B009 Do not call getattr with a constant attribute value. It is not any safer than normal property access.


[failure] 149-149: Ruff (Q000)
src/lfx/src/lfx/base/agents/agent.py:149:31: Q000 Single quotes found but double quotes preferred

🪛 GitHub Actions: Ruff Style Check

[error] 149-149: Q000 Single quotes found but double quotes preferred (Ruff: formatting rule).

🤖 Prompt for AI Agents
In src/lfx/src/lfx/base/agents/agent.py around lines 149 to 150, update the
duck-typing check to satisfy Ruff by using double quotes and a default-backed
getattr; replace hasattr(m, 'to_data') and callable(getattr(m, 'to_data')) with
callable(getattr(m, "to_data", None)) so the check uses double quotes and avoids
calling getattr without a default while preserving the original behavior.

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

codecov Bot commented Sep 27, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 23.43%. Comparing base (fbad5fa) to head (18ec5a7).
⚠️ Report is 5 commits behind head on main.

❌ Your project status has failed because the head coverage (46.02%) is below the target coverage (55.00%). You can increase the head coverage or adjust the target coverage.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #10008      +/-   ##
==========================================
+ Coverage   23.25%   23.43%   +0.17%     
==========================================
  Files        1090     1090              
  Lines       39855    39855              
  Branches     5531     5531              
==========================================
+ Hits         9270     9340      +70     
+ Misses      30414    30344      -70     
  Partials      171      171              
Flag Coverage Δ
backend 46.02% <ø> (+0.46%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.
see 4 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

… types

This commit modifies the `data_to_messages` function to accept a list of both `Data` and `Message` types, enhancing type compatibility. The function's docstring has been updated to reflect the new input type and return type, ensuring clarity in its usage.
This commit updates the chat history processing in the LCAgentComponent to ensure that only messages with valid 'text' data are included. The method now checks for the presence of 'text' in the message data before converting it to the appropriate format. Additionally, the base input retrieval method has been changed from `_base_inputs` to `get_base_inputs()` for consistency and clarity.
@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
@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label 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
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Sep 29, 2025
@sonarqubecloud
Copy link
Copy Markdown

@ogabrielluiz ogabrielluiz added this pull request to the merge queue Sep 29, 2025
Merged via the queue into main with commit d13fdf1 Sep 29, 2025
194 of 197 checks passed
@ogabrielluiz ogabrielluiz deleted the fix/agent-memory-issues branch September 29, 2025 21:48
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