fix: Restore Agent memory functionality by fixing inheritance and type compatibility#10008
Conversation
…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>
|
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 WalkthroughUpdates 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
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
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 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. 🧪 Early access (Sonnet 4.5): enabledWe 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:
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 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
| 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]) |
There was a problem hiding this comment.
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.
| 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.
Codecov Report✅ All modified and coverable lines are covered by tests. ❌ 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@@ 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
Flags with carried forward coverage won't be shown. Click here to find out more. 🚀 New features to boost your workflow:
|
… 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.
|



Summary
Bugs Fixed
Bug #1: Inheritance Method Call Error
get_base_inputs()method_base_inputsattribute accesssrc/lfx/src/lfx/components/agents/agent.py:157src/lfx/src/lfx/base/agents/agent.py:229Bug #2: Message Type Incompatibility
langflow.schema.message.Messagebut Agent expectedlfx.schema.message.Messagesrc/lfx/src/lfx/base/agents/agent.py:148-150Test 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
🤖 Generated with Claude Code
Summary by CodeRabbit