Skip to content

fix: don't send duplicate messages to Agent#8909

Merged
ogabrielluiz merged 22 commits into
mainfrom
fix-duplicated-anthropic-message
Jul 8, 2025
Merged

fix: don't send duplicate messages to Agent#8909
ogabrielluiz merged 22 commits into
mainfrom
fix-duplicated-anthropic-message

Conversation

@ogabrielluiz
Copy link
Copy Markdown
Contributor

@ogabrielluiz ogabrielluiz commented Jul 7, 2025

When using Anthropic models if you pass a message like 2+2 in the Simple Agent template, it would calculate 2+22+2. This fixes that issue.

  • Refactor MessageTextInput to MessageInput for consistency.
  • Enhance input dictionary construction to handle different input types in LCAgentComponent.
  • Update get_memory_data method to filter out current input value from retrieved messages.

Summary by CodeRabbit

  • Bug Fixes

    • Improved agent chat history handling to exclude the current input message from memory, preventing duplication or feedback loops across all agent components and starter projects.
  • Enhancements

    • Updated system prompts for Pokédex Agent, Price Deal Finder, and Travel Planning Agents to provide more specific and descriptive instructions, improving agent responses for those use cases.

…mory data retrieval

* Refactor MessageTextInput to MessageInput for consistency.
* Enhance input dictionary construction to handle different input types in LCAgentComponent.
* Update get_memory_data method to filter out current input value from retrieved messages.
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 7, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 7, 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

This change updates the agent input handling and memory retrieval logic across the core agent component and multiple starter project configurations. It standardizes the input type, refines how input values are processed, and modifies the memory retrieval method to exclude the current input message from the agent's chat history, preventing self-reference or duplication.

Changes

File(s) Change Summary
src/backend/base/langflow/base/agents/agent.py Changed agent input type from MessageTextInput to MessageInput; updated input handling in run_agent to extract text from Message instances; ensures agent input is a string or list of messages.
src/backend/base/langflow/components/agents/agent.py Modified get_memory_data to filter out messages matching the current input's id.
src/backend/base/langflow/initial_setup/starter_projects/Instagram Copywriter.json
Invoice Summarizer.json
Market Research.json
News Aggregator.json
Pokédex Agent.json
Price Deal Finder.json
Research Agent.json
SaaS Pricing.json
Search agent.json
Sequential Tasks Agents.json
Simple Agent.json
Social Media Agent.json
Travel Planning Agents.json
Youtube Analysis.json
Updated embedded AgentComponent code in each starter project: get_memory_data now filters out the message matching the current input's id; some files also update the system_prompt default value for more specific agent instructions.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant AgentComponent
    participant MemoryComponent

    User->>AgentComponent: Provide input (MessageInput)
    AgentComponent->>AgentComponent: If input is Message, extract text
    AgentComponent->>MemoryComponent: Retrieve chat history
    MemoryComponent-->>AgentComponent: Return messages
    AgentComponent->>AgentComponent: Filter out message with same id as input_value
    AgentComponent->>AgentComponent: Process agent logic with filtered memory
    AgentComponent-->>User: Return agent response
Loading

Suggested labels

bug, size:L, lgtm

Suggested reviewers

  • edwinjosechittilappilly
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix-duplicated-anthropic-message

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dosubot dosubot Bot added the bug Something isn't working label Jul 7, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 7, 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: 0

🔭 Outside diff range comments (11)
src/backend/base/langflow/initial_setup/starter_projects/Youtube Analysis.json (1)

868-915: get_memory_data silently keeps non-Message objects – add a type-check guard

messages can come back with system artefacts (strings, dicts, etc.) when custom Memories are plugged in.
The list-comprehension currently filters only by id, so a non-Message element with no id attribute will slip through and later break the agent when it expects .text, .role, etc.

-        return [
-            message for message in messages
-            if getattr(message, "id", None) != getattr(self.input_value, "id", None)
-        ]
+        return [
+            m for m in messages
+            if isinstance(m, Message)            # ensure correct type
+            and getattr(m, "id", None) != getattr(self.input_value, "id", None)
+        ]

Keeps the behaviour but prevents type errors further down the chain.

src/backend/base/langflow/initial_setup/starter_projects/News Aggregator.json (2)

1516-1540: Out-of-date import & type name – switch to MessageInput

The PR narrative says MessageTextInput was refactored to MessageInput, yet the embedded AgentComponent code still:

from langflow.io import (..., MessageTextInput, ...)

Keeping the old name will break once MessageTextInput disappears from the public API.

-from langflow.io import BoolInput, DropdownInput, IntInput, MultilineInput, Output, MessageTextInput
+from langflow.io import (
+    BoolInput,
+    DropdownInput,
+    IntInput,
+    MultilineInput,
+    Output,
+    MessageInput,         # <- new
+)

Follow up: replace every remaining MessageTextInput( occurrence in this file with MessageInput(.


1600-1625: get_memory_data only excludes a single input_value – lists slip through

return [
    message
    for message in messages
    if getattr(message, "id", None) != getattr(self.input_value, "id", None)
]

When input_value is a list of messages, getattr(list, "id", None) is always None, so no messages are filtered out.
Consider handling the list case explicitly:

-if getattr(message, "id", None) != getattr(self.input_value, "id", None)
+excluded_ids = {
+    getattr(m, "id", None) for m in (
+        self.input_value if isinstance(self.input_value, list) else [self.input_value]
+    )
+}
+if getattr(message, "id", None) not in excluded_ids

This keeps the history clean regardless of how input_value is supplied.

src/backend/base/langflow/initial_setup/starter_projects/Research Agent.json (1)

2690-2705: Guard against unintended history purge when input_value.id is None

get_memory_data unconditionally filters on
getattr(m, "id", None) != getattr(self.input_value, "id", None).

If the current input_value hasn’t been persisted yet, getattr(self.input_value,"id",None) is None.
Any stale messages that also lack an id (e.g. synthetic or test messages) would then be discarded, silently wiping part—or all—of the chat history.

A safer pattern:

-        return [
-            message for message in messages if getattr(message, "id", None) != getattr(self.input_value, "id", None)
-        ]
+        input_id = getattr(self.input_value, "id", None)
+        # Only filter when current input has a valid id
+        if input_id is None:
+            return messages
+        return [m for m in messages if getattr(m, "id", None) != input_id]

Minor, but it eliminates a hard-to-trace edge case while keeping O(n) complexity.

src/backend/base/langflow/initial_setup/starter_projects/Sequential Tasks Agents.json (1)

526-548: Replace deprecated MessageTextInput with MessageInput throughout the starter project

MessageTextInput was renamed to MessageInput in the core library in this PR.
Keeping the old _input_type here will break runtime deserialization for every Agent/Prompt node that still references the old class (input_value, tool_placeholder, etc.).

-"_input_type": "MessageTextInput",
+"_input_type": "MessageInput",

Please update all occurrences in the JSON (three shown here, but many more exist in other nodes) or run an automated find-&-replace before shipping the template.
Failure to do so will raise ValueError: unknown input_type 'MessageTextInput' when the flow is loaded.

Also applies to: 1078-1098, 2422-2442

src/backend/base/langflow/initial_setup/starter_projects/Price Deal Finder.json (1)

1765-1785: retrieve_messages() result is not awaited – potential coroutine leak

retrieve_messages() is invoked immediately after .set(...), but the returned value is assigned without awaiting.
If retrieve_messages() is an async method (very likely, since it usually hits the DB), the current statement will assign a coroutine object instead of the actual list of messages, and the later list-comprehension will silently iterate over an empty list.

-        messages = (
-            await MemoryComponent(**self.get_base_args())
-            .set(session_id=self.graph.session_id, order="Ascending", n_messages=self.n_messages)
-            .retrieve_messages()
-        )
+        memory_component = await MemoryComponent(**self.get_base_args())
+        memory_component = memory_component.set(
+            session_id=self.graph.session_id,
+            order="Ascending",
+            n_messages=self.n_messages,
+        )
+        messages = await memory_component.retrieve_messages()

Failing to await here will surface only at runtime and is hard to trace; please double-check the signature of retrieve_messages() and add the missing await if needed.

src/backend/base/langflow/initial_setup/starter_projects/Social Media Agent.json (2)

660-706: Update deprecated MessageTextInput references to MessageInput.

MessageTextInput was renamed in this PR, yet the template still lists it several times (background_color, chat_icon, etc.). Keeping the old enum will break dynamic form generation at runtime and produces a “component type not found” error.

Typical fix for each occurrence:

- "_input_type": "MessageTextInput",
+ "_input_type": "MessageInput",

Please sweep the file (and the other starter-project JSONs) for the old value and replace it consistently.


1461-1483: input_value field still uses the obsolete input type / wrong scalar type.

Inside the Agent node:

"_input_type": "MessageTextInput",
"type": "str",
"input_types": ["Message"],
  1. _input_type should be MessageInput (see previous comment).
  2. type should be "Message" (or be omitted) to keep the static-typing contract between the ChatInput output and the Agent input. Leaving it as "str" forces an implicit cast and silently discards metadata/files attached to the message.
- "_input_type": "MessageTextInput",
- "type": "str",
+ "_input_type": "MessageInput",
+ "type": "Message",

Mis-typing here will surface as “invalid message format” when the Agent tries to access .id or .files.

src/backend/base/langflow/initial_setup/starter_projects/Invoice Summarizer.json (2)

1340-1375: await precedence may skip awaiting retrieve_messages()

messages = (
    await MemoryComponent(**self.get_base_args())
    .set(session_id=self.graph.session_id, order="Ascending", n_messages=self.n_messages)
    .retrieve_messages()
)

Because attribute access and function calls bind tighter than await, the expression is parsed as:

await (MemoryComponent(**...).set(...).retrieve_messages())

…so you ARE awaiting retrieve_messages(), not MemoryComponent(...).
If MemoryComponent.__call__ (i.e. instantiation) or .set() returns an awaitable, those awaits are skipped.

To remove any ambiguity:

mem = await MemoryComponent(**self.get_base_args())
mem = mem.set(session_id=self.graph.session_id, order="Ascending", n_messages=self.n_messages)
messages = await mem.retrieve_messages()

This guarantees every coroutine is awaited and eases future refactors.


1376-1384: Filtering out current input looks good but misses None IDs

getattr(message, "id", None) != getattr(self.input_value, "id", None)
works, but when both IDs are None (e.g. legacy messages without IDs) the message is wrongly excluded.

-        return [
-            message for message in messages
-            if getattr(message, "id", None) != getattr(self.input_value, "id", None)
-        ]
+        current_id = getattr(self.input_value, "id", object())
+        return [m for m in messages if getattr(m, "id", object()) != current_id]

Using a unique sentinel avoids accidental drops.

src/backend/base/langflow/initial_setup/starter_projects/SaaS Pricing.json (1)

1025-1035: Possible over-filtering in get_memory_data when input_value lacks an id

If self.input_value is a str, a list, or a Message without an id, the RHS of the comparison resolves to None.
The current list-comprehension will then silently drop every past message whose id is also None, shrinking the chat history and potentially degrading the agent’s performance.

-        return [
-            message for message in messages if getattr(message, "id", None) != getattr(self.input_value, "id", None)
-        ]
+        input_ids = (
+            {getattr(m, "id", None) for m in self.input_value}
+            if isinstance(self.input_value, list)
+            else {getattr(self.input_value, "id", None)}
+        )
+        return [msg for msg in messages if getattr(msg, "id", None) not in input_ids]

• Handles list inputs
• Keeps historical messages whose id is None but are not the current input.

♻️ Duplicate comments (4)
src/backend/base/langflow/initial_setup/starter_projects/Instagram Copywriter.json (2)

2566-2586: Same MessageInput upgrade applied here

The LanguageModelComponent template now uses MessageInput for input_value, matching the Python definition further up. No issues spotted.


2859-2880: Same change replicated for second LLM node

Identical reasoning as previous comment — consistent and correct.

src/backend/base/langflow/initial_setup/starter_projects/Travel Planning Agents.json (2)

2379-2410: Duplicate of the previous get_memory_data block – same refactor/comments apply.


2923-2950: Duplicate of the previous get_memory_data block – same refactor/comments apply.

🧹 Nitpick comments (10)
src/backend/base/langflow/initial_setup/starter_projects/News Aggregator.json (1)

1541-1555: Remove dead code: memory_inputs is defined but never used

memory_inputs is created:

memory_inputs = [set_advanced_true(component_input) for component_input in MemoryComponent().inputs]

but later commented-out in the inputs list. This leaves an unused variable, raising linter warnings and confusing readers.

-# ❶ remove the whole definition – it’s now obsolete
-memory_inputs = [set_advanced_true(component_input) for component_input in MemoryComponent().inputs]
-
-# (...)
-        # removed memory inputs from agent component
-        # *memory_inputs,

If you plan to re-enable memory customization, keep the variable and add it back to inputs; otherwise delete it entirely.

src/backend/base/langflow/initial_setup/starter_projects/Instagram Copywriter.json (1)

2080-2105: Guard against None IDs when filtering chat history

get_memory_data now excludes the current input_value from history via

[message for message in messages if getattr(message, "id", None) != getattr(self.input_value, "id", None)]

If either side lacks an id, the comparison falls back to None, letting every message whose id is also None pass through, potentially re-introducing duplicates for storages that never assign IDs.

-        return [
-            message for message in messages
-            if getattr(message, "id", None) != getattr(self.input_value, "id", None)
-        ]
+        input_id = getattr(self.input_value, "id", object())  # sentinel avoids None collision
+        return [m for m in messages if getattr(m, "id", object()) != input_id]

This preserves all messages with real IDs while reliably removing the current one.

src/backend/base/langflow/initial_setup/starter_projects/Market Research.json (2)

2170-2188: Harden get_memory_data with type-safety & empty-history guard

retrieve_messages() can theoretically return None or an empty iterable.
Iterating over it immediately may raise or propagate TypeError.
A small guard also lets you add type hints & a doc-string for future readers.

-    async def get_memory_data(self):
-        messages = (
+    async def get_memory_data(self) -> list[Message]:
+        """
+        Fetch chat history and drop the message that triggered the call
+        to avoid echo-loops.
+        """
+        messages: list[Message] | None = (
             await MemoryComponent(**self.get_base_args())
                 .set(session_id=self.graph.session_id, order="Ascending", n_messages=self.n_messages)
                 .retrieve_messages()
         )
-        return [
-            message for message in messages if getattr(message, "id", None) != getattr(self.input_value, "id", None)
-        ]
+        if not messages:
+            return []
+
+        return [
+            m
+            for m in messages
+            if getattr(m, "id", None) != getattr(self.input_value, "id", None)
+        ]

Benefits:
• Avoids TypeError on None returns.
• Adds explicit return type & docstring.
• Keeps comprehension readable.


2210-2228: AgentComponent.input_value still uses MessageTextInput – align with new MessageInput

The PR migrates to MessageInput for text-based message fields, yet this node definition remains on the deprecated MessageTextInput.
Leaving it untouched means the agent path keeps the old behaviour while other components (e.g. ChatOutput, LanguageModelComponent) already expect the new input type – potential schema drift and UI inconsistency.

Please verify and, if appropriate, switch:

-"_input_type": "MessageTextInput",
+" _input_type": "MessageInput",

to stay consistent with the rest of the template set.

src/backend/base/langflow/initial_setup/starter_projects/Search agent.json (1)

1135-1135: Consider extracting embedded Python code to separate files for better maintainability.

Having large Python code blocks embedded within JSON configuration files makes code review, version control, and maintenance challenging. The embedded AgentComponent class is substantial and would benefit from being in a separate Python file.

Consider refactoring to:

  1. Extract the AgentComponent implementation to a dedicated Python file
  2. Reference the class by import path in the JSON configuration
  3. This would improve code maintainability, enable proper syntax highlighting, and make changes easier to review
src/backend/base/langflow/initial_setup/starter_projects/Sequential Tasks Agents.json (1)

505-514: Minor optimisation in get_memory_data comprehension

The new filter works, but getattr(self.input_value, "id", None) is recomputed for every loop iteration.

-        return [
-            message for message in messages if getattr(message, "id", None) != getattr(self.input_value, "id", None)
-        ]
+        current_id = getattr(self.input_value, "id", None)
+        return [msg for msg in messages if getattr(msg, "id", None) != current_id]

Not critical, yet shaves a method call per message and improves readability.

Also applies to: 540-547, 2388-2397

src/backend/base/langflow/initial_setup/starter_projects/Pokédex Agent.json (3)

1421-1470: Potential ordering confusion in get_memory_data

messages = (
    await MemoryComponent(**self.get_base_args())
        .set(session_id=self.graph.session_id, order="Ascending", n_messages=self.n_messages)
        .retrieve_messages()
)
return [
    message for message in messages
    if getattr(message, "id", None) != getattr(self.input_value, "id", None)
]

Two things to verify:

  1. Most LangChain agents expect history in chronological order (oldest → newest), but elsewhere in the codebase we traditionally fetched it descending and then reversed. Ensure downstream consumers aren’t accidentally seeing reversed context.

  2. You rely on id uniqueness to filter the current input. If self.input_value is a string or any non-Message, getattr(..., "id", None) will be None, so nothing is filtered. That’s fine, but be aware the optimisation only kicks in when the UI passes a Message object.
    If that assumption is shaky, you could compare text plus a timestamp hash instead.

No change required if this behaviour is intentional.


1471-1505: Edge case: prefix may be None in _build_llm_model

for input_ in inputs:
    if hasattr(self, f"{prefix}{input_.name}"):
        model_kwargs[input_.name] = getattr(self, f"{prefix}{input_.name}")

MODEL_PROVIDERS_DICT sets prefix to "" for most providers, but if a contributor adds a new provider and forgets the key, prefix could be None, leading to TypeError: can only concatenate str (not "NoneType") to str.

Guard once upfront:

- for input_ in inputs:
-     if hasattr(self, f"{prefix}{input_.name}"):
+ prefix = prefix or ""
+ for input_ in inputs:
+     attr_name = f"{prefix}{input_.name}"
+     if hasattr(self, attr_name):
          model_kwargs[input_.name] = getattr(self, attr_name)

1506-1580: update_build_config is getting unwieldy

The method is pushing 150+ lines, merging concerns for:

  • provider field switching
  • dynamic input-type patching
  • validation of mandatory keys

Consider extracting helper functions (e.g., _sync_provider_fields, _sanitize_input_types, _validate_default_keys) for readability and unit-testability.
This would also make future provider additions less error-prone.

src/backend/base/langflow/initial_setup/starter_projects/Travel Planning Agents.json (1)

1835-1860: Factor out duplicated get_memory_data and cover list inputs

Each agent embeds the same block:

async def get_memory_data(self):
    messages = (
        await MemoryComponent(**self.get_base_args())
        .set(session_id=self.graph.session_id, order="Ascending", n_messages=self.n_messages)
        .retrieve_messages()
    )
    return [
        m for m in messages
        if getattr(m, "id", None) != getattr(self.input_value, "id", None)
    ]

Issues:

  1. If self.input_value is a list of Messages, only the first id is checked, so duplicates can re-enter history.
  2. The identical definition is copied into three agents – any future tweak requires triple maintenance.

Suggested refactor (utility in a mixin or helper):

+def _exclude_current(messages, current):
+    if isinstance(current, list):
+        exclude_ids = {getattr(m, "id", None) for m in current}
+    else:
+        exclude_ids = {getattr(current, "id", None)}
+    return [m for m in messages if getattr(m, "id", None) not in exclude_ids]

async def get_memory_data(self):
    messages = (
        await MemoryComponent(**self.get_base_args())
        .set(session_id=self.graph.session_id, order="Ascending", n_messages=self.n_messages)
        .retrieve_messages()
    )
-    return [m for m in messages if getattr(m, "id", None) != getattr(self.input_value, "id", None)]
+    return _exclude_current(messages, self.input_value)

This removes duplication and handles list/None cases cleanly.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 90d9ab2 and 808808c.

📒 Files selected for processing (16)
  • src/backend/base/langflow/base/agents/agent.py (3 hunks)
  • src/backend/base/langflow/components/agents/agent.py (1 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Instagram Copywriter.json (1 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Invoice Summarizer.json (1 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Market Research.json (1 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/News Aggregator.json (1 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Pokédex Agent.json (1 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Price Deal Finder.json (1 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Research Agent.json (1 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/SaaS Pricing.json (1 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Search agent.json (1 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Sequential Tasks Agents.json (3 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Simple Agent.json (1 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Social Media Agent.json (1 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Travel Planning Agents.json (3 hunks)
  • src/backend/base/langflow/initial_setup/starter_projects/Youtube Analysis.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
`src/backend/base/langflow/components/**/*.py`: Add new backend components to th...

src/backend/base/langflow/components/**/*.py: Add new backend components to the appropriate subdirectory under src/backend/base/langflow/components/
Implement async component methods using async def and await for asynchronous operations
Use asyncio.create_task for background work in async components and ensure proper cleanup on cancellation
Use asyncio.Queue for non-blocking queue operations in async components and handle timeouts appropriately

📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)

List of files the instruction was applied to:

  • src/backend/base/langflow/components/agents/agent.py
`src/backend/**/*.py`: Run make format_backend to format Python code early and often Run make lint to check for linting issues in backend Python code

src/backend/**/*.py: Run make format_backend to format Python code early and often
Run make lint to check for linting issues in backend Python code

📄 Source: CodeRabbit Inference Engine (.cursor/rules/backend_development.mdc)

List of files the instruction was applied to:

  • src/backend/base/langflow/components/agents/agent.py
  • src/backend/base/langflow/base/agents/agent.py
`src/backend/**/components/**/*.py`: In your Python component class, set the `icon` attribute to a string matching the frontend icon mapping exactly (case-sensitive).

src/backend/**/components/**/*.py: In your Python component class, set the icon attribute to a string matching the frontend icon mapping exactly (case-sensitive).

📄 Source: CodeRabbit Inference Engine (.cursor/rules/icons.mdc)

List of files the instruction was applied to:

  • src/backend/base/langflow/components/agents/agent.py
🧠 Learnings (2)
src/backend/base/langflow/base/agents/agent.py (4)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test Langflow's 'Message' objects and chat functionality by asserting correct properties and structure.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/base/langflow/components/**/__init__.py : Update __init__.py with alphabetical imports when adding new components
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/base/langflow/components/**/*.py : Add new backend components to the appropriate subdirectory under src/backend/base/langflow/components/
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test backward compatibility across Langflow versions by mapping component files to supported versions using 'VersionComponentMapping'.
src/backend/base/langflow/initial_setup/starter_projects/Instagram Copywriter.json (1)

undefined

<retrieved_learning>
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Starter project files are auto-formatted after langflow run; these changes can be committed or ignored
</retrieved_learning>

🧬 Code Graph Analysis (1)
src/backend/base/langflow/base/agents/agent.py (4)
src/backend/base/langflow/inputs/inputs.py (1)
  • MessageInput (187-202)
src/backend/base/langflow/schema/data.py (1)
  • get_text (60-69)
src/backend/tests/unit/custom/custom_component/test_component_events.py (1)
  • get_text (28-30)
src/backend/base/langflow/schema/message.py (1)
  • Message (39-289)
⏰ 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). (4)
  • GitHub Check: Optimize new Python code in this PR
  • GitHub Check: Run Ruff Check and Format
  • GitHub Check: Update Starter Projects
  • GitHub Check: Ruff Style Check (3.13)
🔇 Additional comments (16)
src/backend/base/langflow/components/agents/agent.py (1)

129-136: Excellent fix for memory data filtering!

This change successfully addresses the issue where the current input message was being included in the agent's chat history, causing calculation errors like 2+2 becoming 2+22+2. The filtering logic correctly excludes the current input message from the retrieved memory data.

The implementation uses defensive programming with getattr(message, "id", None) to handle cases where messages might not have an id attribute, which is robust and prevents potential AttributeError exceptions.

src/backend/base/langflow/initial_setup/starter_projects/Simple Agent.json (1)

1127-1127: Consistent implementation across starter projects!

The embedded AgentComponent code correctly mirrors the memory filtering changes from the main agent component. This ensures that users starting with the Simple Agent template will benefit from the same fix that prevents input message duplication in chat history.

Maintaining consistency between the core components and starter project templates is crucial for providing a uniform user experience.

src/backend/base/langflow/initial_setup/starter_projects/Youtube Analysis.json (1)

1564-1586: input_value switched to MessageInput – verify it still accepts edge connections

The field is now declared as

"_input_type": "MessageInput",
"input_types": ["Data", "DataFrame", "Message"],

MessageInput is a literal text-box input and, unlike HandleInput, is not meant to accept incoming links.
However this node is wired to Agent-JRSRu → ChatOutput-vlskP via input_value, so the editor will attempt to connect a handle here.

Double-check that the underlying UI component was updated so MessageInput can act as a handle target; otherwise the edge will be refused at runtime and the flow will break.

If linkage is still required, keep the field as HandleInput (or the new MessageHandleInput counterpart) instead of MessageInput.

src/backend/base/langflow/initial_setup/starter_projects/News Aggregator.json (1)

1626-1640: Minor: defensive check for retrieve_messages await-ability

retrieve_messages() is called inside the awaited expression:

messages = (
    await MemoryComponent(**self.get_base_args())
    .set(...).retrieve_messages()
)

If retrieve_messages ever becomes async itself this works, but if it is sync returning a list, the whole expression is still fine.
Just ensure tests cover both sync/async implementations—or add a comment clarifying that retrieve_messages returns an awaitable.

src/backend/base/langflow/initial_setup/starter_projects/Instagram Copywriter.json (1)

1151-1173: Template field switched to MessageInput—looks correct

Changing _input_type from MessageTextInput to MessageInput aligns the UI control with the new input-handling changes in ChatOutput. input_types still allow Data/DataFrame/Message, so existing flows stay compatible.

src/backend/base/langflow/initial_setup/starter_projects/Market Research.json (1)

618-640: Confirm ChatOutput’s input_value typing after the switch to MessageInput

_input_type has been updated to "MessageInput" but the underlying type field is still "str".
If MessageInput can emit objects other than plain strings (e.g. full Message instances), the "str" declaration may break validation or downstream assumptions.

Double-check the expected payload of MessageInput and adjust type / input_types accordingly to avoid runtime coercion surprises.

src/backend/base/langflow/initial_setup/starter_projects/Search agent.json (1)

1135-1135: Memory filtering logic is correctly implemented

The get_memory_data method excludes the current input message by comparing message.id to self.input_value.id, as intended:

• It returns
[message for message in messages if getattr(message, "id", None) != getattr(self.input_value, "id", None)]
which correctly filters out the current input message.

No further changes are needed for this logic.

src/backend/base/langflow/base/agents/agent.py (3)

15-15: LGTM: Import update aligns with improved input handling.

The change from MessageTextInput to MessageInput is appropriate. Based on the relevant code snippets, MessageInput provides more robust validation and can handle various input types (dict, Message, str, iterators) while converting them to proper Message instances.


37-42: LGTM: Input type change is consistent with the import update.

The change from MessageTextInput to MessageInput in the _base_inputs definition is consistent with the import change and maintains proper typing for the input field.


138-140: Approved: Input handling for Message instances is correct

Confirmed that Message.get_text() is inherited from Data.get_text() in src/backend/base/langflow/schema/data.py, which reliably returns the message’s text (or the default empty string). No further changes are needed.

src/backend/base/langflow/initial_setup/starter_projects/Price Deal Finder.json (1)

581-603: Inconsistent _input_type update – verify front-end binding

input_value was switched from MessageTextInput to MessageInput for the ChatOutput component.
Other components (e.g. Agent still using MessageTextInput) remain unchanged. Make sure the UI side renders the proper widget and that the back-end validation layer recognises both types, otherwise users may hit a “value is not a valid xxx” error when wiring nodes.

No change is required in this JSON, but please confirm the new _input_type is supported across the whole stack.

src/backend/base/langflow/initial_setup/starter_projects/Social Media Agent.json (1)

1441-1500: Edge-case in get_memory_data filter – string inputs leak through.

return [
    message
    for message in messages
    if getattr(message, "id", None) != getattr(self.input_value, "id", None)
]

If self.input_value is a plain str (user passes raw text instead of a Message), getattr(self.input_value,"id",None) returns None.
All stored messages whose id is also None (e.g., legacy rows or system prompts) will be wrongly excluded.

Consider making the comparison only when self.input_value is a Message:

- if getattr(message, "id", None) != getattr(self.input_value, "id", None)
+ if not isinstance(self.input_value, Message) or message.id != self.input_value.id

That prevents accidental loss of messages and keeps the intention clear.

src/backend/base/langflow/initial_setup/starter_projects/Pokédex Agent.json (1)

557-579: Confirm frontend support for new MessageInput type

The _input_type for input_value was changed from MessageTextInput to MessageInput.
Double-check that:

  1. The React component registry already maps MessageInput to a rendered control.
  2. Existing starter projects or user flows that persist MessageTextInput don’t break on load/migration.

If runtime compatibility is a concern, you might temporarily allow both aliases or run a migration script that rewrites stored flows.

src/backend/base/langflow/initial_setup/starter_projects/Invoice Summarizer.json (1)

429-435: Confirm backend support for newly-renamed MessageInput type

"_input_type": "MessageInput" replaces the previous MessageTextInput.
Please double–check that:

  1. The front-end schema recognises MessageInput (autocompletion, validation, etc.).
  2. All components that still emit/expect the old MessageTextInput type were refactored accordingly, otherwise drag-and-drop wiring in the UI will silently break.

If this is just an alias, adding a short migration helper (e.g. accept both names for one release) could avoid regressions for existing custom templates.

src/backend/base/langflow/initial_setup/starter_projects/SaaS Pricing.json (1)

1025-1027: Stale MessageTextInput reference will break once the rename to MessageInput lands

The PR description says MessageTextInput was refactored to MessageInput, yet this embedded component still imports and instantiates the old class. When the alias is removed, this starter project will fail to load.

Update the import and the input declaration:

-from langflow.io import MessageTextInput, Output, PromptInput
+from langflow.io import MessageInput, Output, PromptInput
...
-        MessageTextInput(
+        MessageInput(

Run a quick grep over the starter projects to ensure no other lingering references remain.

⛔ Skipped due to learnings
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Starter project files are auto-formatted after langflow run; these changes can be committed or ignored
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/backend_development.mdc:0-0
Timestamp: 2025-06-30T14:39:17.464Z
Learning: Applies to src/backend/base/langflow/components/**/__init__.py : Update __init__.py with alphabetical imports when adding new components
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/icons.mdc:0-0
Timestamp: 2025-06-23T12:46:52.420Z
Learning: When implementing a new component icon in Langflow, ensure the icon name is clear, recognizable, and used consistently across both backend (Python 'icon' attribute) and frontend (React/TypeScript mapping).
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/testing.mdc:0-0
Timestamp: 2025-06-30T14:41:58.849Z
Learning: Applies to {src/backend/tests/**/*.py,tests/**/*.py} : Test Langflow's 'Message' objects and chat functionality by asserting correct properties and structure.
src/backend/base/langflow/initial_setup/starter_projects/Travel Planning Agents.json (1)

650-672: Inconsistent _input_type rename – verify front-end compatibility

ChatOutput.input_value now uses _input_type": "MessageInput" while other nodes (e.g. ChatInput, all Agent nodes) still rely on "MessageTextInput".
If the UI/backend doesn’t recognise both aliases, drag-and-drop wiring or validation might silently fail.

Please confirm that

  1. MessageInput is registered as a component type, and
  2. legacy MessageTextInput references are either migrated or kept as backward-compatible shims.

Failing to do so will break existing flows once they’re re-saved.

@ogabrielluiz ogabrielluiz changed the title fix: update message input handling in LCAgentComponent and improve memory data retrieval fix: don't send duplicate messages to Agent Jul 7, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 7, 2025
@edwinjosechittilappilly
Copy link
Copy Markdown
Collaborator

testing

@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 7, 2025
)
input_dict: dict[str, str | list[BaseMessage]] = {"input": self.input_value}
input_dict: dict[str, str | list[BaseMessage]] = {
"input": self.input_value.get_text() if isinstance(self.input_value, Message) else self.input_value
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@ogabrielluiz I believe @Cristhianzl was making changes to ensure the images work with agents.
Won't this be in conflict with that, since we are getting only the text inputs.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It was already getting text inputs before. I can fix that in another PR as this is aimed getting it back to a working state.

@edwinjosechittilappilly
Copy link
Copy Markdown
Collaborator

@ogabrielluiz The issue still persists.

@edwinjosechittilappilly
Copy link
Copy Markdown
Collaborator

@coderabbitai, Even if we do the following:
Refactor MessageTextInput to MessageInput for consistency.
Enhance input dictionary construction to handle different input types in LCAgentComponent.
Update the get_memory_data method to filter out the current input value from retrieved messages.

The input seems repeated.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 7, 2025

Tip

For best results, initiate chat on the files or code changes.

🧩 Analysis chain

@edwinjosechittilappilly Thank you for testing and confirming the issue persists. Let me investigate the implementation to identify why the input duplication is still occurring.


🏁 Script executed:

#!/bin/bash
# Let's examine the specific implementation of the changes made
echo "=== Examining LCAgentComponent changes ==="
cat src/backend/base/langflow/base/agents/agent.py

echo -e "\n=== Examining AgentComponent changes ==="
cat src/backend/base/langflow/components/agents/agent.py

Length of output: 23793


Let me examine the Simple Agent template implementation and check for potential issues with the filtering logic:


🏁 Script executed:

#!/bin/bash
# Let's examine the Simple Agent template to see the specific configuration
echo "=== Examining Simple Agent template ==="
cat "src/backend/base/langflow/initial_setup/starter_projects/Simple Agent.json" | jq '.data.nodes[] | select(.data.type == "AgentComponent") | .data.node.template.code.value' -r

echo -e "\n=== Let's also check if there are other places where memory gets added ==="
rg -A 5 -B 5 "chat_history" src/backend/base/langflow/base/agents/agent.py

echo -e "\n=== Check the memory component to understand how messages are stored/retrieved ==="
cat src/backend/base/langflow/components/helpers/memory.py | head -50

Length of output: 3913


🏁 Script executed:

#!/bin/bash
# Let's see the complete memory component to understand message storage
echo "=== Complete memory component implementation ==="
cat src/backend/base/langflow/components/helpers/memory.py

echo -e "\n=== Let's check how messages are being stored and their ID assignment ==="
rg -A 10 -B 5 "store_message\|aget_messages" src/backend/base/langflow/components/helpers/memory.py

echo -e "\n=== Check the Message class to understand ID assignment ==="
rg -A 10 -B 5 "class Message\|def __init__" src/backend/base/langflow/schema/message.py

Length of output: 10447


🏁 Script executed:

#!/bin/bash
# Let's search for the Message class definition more broadly
echo "=== Looking for Message class definition ==="
fd -e py -x grep -l "class Message" | head -5

echo -e "\n=== Check Message schema file specifically ==="
find . -name "message.py" -path "*/schema/*" | head -3

echo -e "\n=== Look at the Message class implementation ==="
cat src/backend/base/langflow/schema/message.py | head -100

echo -e "\n=== Check if there's an issue with ID comparison in the filtering ==="
echo "Current filtering logic in get_memory_data:"
grep -A 3 -B 3 "getattr.*id.*None" src/backend/base/langflow/components/agents/agent.py

Length of output: 5151


🏁 Script executed:

#!/bin/bash
# Let's see the complete Message class to find the ID field
echo "=== Complete Message class definition ==="
cat src/backend/base/langflow/schema/message.py

echo -e "\n=== Let's check the Data class that Message inherits from ==="
cat src/backend/base/langflow/schema/data.py | head -50

echo -e "\n=== Check if messages have IDs when stored/retrieved ==="
rg -A 5 -B 5 "\.id" src/backend/base/langflow/components/helpers/memory.py

Length of output: 19782


🏁 Script executed:

#!/bin/bash
# Let's see the complete Data class to find the ID field
echo "=== Complete Data class definition ==="
cat src/backend/base/langflow/schema/data.py

echo -e "\n=== Let's see if Data class has an id field or inherits one ==="
rg -A 10 -B 5 "id.*=" src/backend/base/langflow/schema/data.py

echo -e "\n=== Let's check what fields are actually available on Message instances ==="
echo "Looking for where messages get their IDs assigned..."
rg -A 5 -B 5 "\.id.*=" src/backend/base/langflow/schema/

echo -e "\n=== Check if there's a different field that should be used for comparison ==="
echo "Let's see if there's a uuid or similar field:"
rg "uuid\|UUID\|id.*Field" src/backend/base/langflow/schema/data.py

Length of output: 13041


🏁 Script executed:

#!/bin/bash
# The issue is now clear! Let's see what fields are actually available for unique identification
echo "=== Let's check the Message Response class that seems to have an ID field ==="
grep -A 20 -B 5 "class MessageResponse" src/backend/base/langflow/schema/message.py

echo -e "\n=== Let's see what fields Message instances actually have available ==="
echo "Looking at Message class fields:"
grep -A 10 -B 5 "timestamp\|session_id\|flow_id" src/backend/base/langflow/schema/message.py

echo -e "\n=== Let's check if we can use timestamp + text combination for uniqueness ==="
echo "The issue: Message class doesn't have an 'id' field, so getattr(message, 'id', None) always returns None"
echo "Current filtering logic:"
grep -A 3 -B 3 "getattr.*id.*None" src/backend/base/langflow/components/agents/agent.py

echo -e "\n=== Let's look at database models to see how messages are actually stored with IDs ==="
find . -name "*.py" -path "*/database/models/message/*" -exec head -30 {} \;

Length of output: 11831


@edwinjosechittilappilly I've found the root cause of the issue! The problem is that the Message class doesn't have an id field, but the filtering logic is trying to use one.

Looking at the current filtering code:

return [
    message for message in messages if getattr(message, "id", None) != getattr(self.input_value, "id", None)
]

Since Message instances don't have an id field, both getattr calls return None, making the comparison None != None which is always False. This means no messages are being filtered out, causing the input duplication.

Here's the fix needed:

Fix: Replace ID-based filtering with message content comparison

  • Update the filtering logic in get_memory_data to use a more reliable comparison method
  • Use direct message comparison or text/timestamp combination since Message instances don't have IDs

This fix compares the actual message content (text, timestamp, and sender) instead of relying on non-existent ID fields, which should properly filter out the current input message from the chat history.


⏳ Preparing changes...

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 7, 2025

A summary of the changes CodeRabbit can apply:

  • Update the get_memory_data method in agent.py to replace the invalid id-based message filtering with a comparison using text, timestamp, and sender fields to correctly exclude the current input message and prevent duplication.

A summary of the context that CodeRabbit is considering across the codebase:

Need to understand the Message class structure to see what fields are available for proper comparison

Show context details

Shell Result:

Shell script executed:

Examine the Message class fields to understand what's available for comparison

grep -A 20 "class Message(Data):" src/backend/base/langflow/schema/message.py

Output:

class Message(Data):
model_config = ConfigDict(arbitrary_types_allowed=True)
# Helper class to deal with image data
text_key: str = "text"
text: str | AsyncIterator | Iterator | None = Field(default="")
sender: str | None = None
sender_name: str | None = None
files: list[str | Image] | None = Field(default=[])
session_id: str | UUID | None = Field(default="")
timestamp: Annotated[str, timestamp_to_str_validator] = Field(
default_factory=lambda: datetime.now(timezone.utc).strftime("%Y-%m-%d %H:%M:%S %Z")
)
flow_id: str | UUID | None = None
error: bool = Field(default=False)
edit: bool = Field(default=False)

properties: Properties = Field(default_factory=Properties)
category: Literal["message", "error", "warning", "info"] | None = "message"
content_blocks: list[ContentBlock] = Field(default_factory=list)
duration: int | None = None

Need to understand how the input_value is structured and what type it is to make proper comparison

Show context details

Shell Result:

Shell script executed:

Check the input_value field definition in the base agent component

grep -A 10 -B 5 "MessageInput.*input_value" src/backend/base/langflow/base/agents/agent.py

Output:

class LCAgentComponent(Component):
trace_type = "agent"
_base_inputs: list[InputTypes] = [
MessageInput(
name="input_value",
display_name="Input",
info="The input provided by the user for the agent to process.",
tool_mode=True,
),
BoolInput(

Check current filtering logic and understand the exact problem

Show context details

Shell Result:

Shell script executed:

Look at the current filtering logic in get_memory_data

grep -A 5 -B 5 "getattr.*id.*None" src/backend/base/langflow/components/agents/agent.py

Output:
    return [
        message for message in messages if getattr(message, "id", None) != getattr(self.input_value, "id", None)
    ]

Check if there are any similar message filtering patterns in the codebase that work correctly

Show context details

Shell Result:

Shell script executed:

Search for message comparison patterns in the codebase

rg -A 3 -B 3 "message.text.*message.timestamp|message.timestamp.*message.text" src/backend/base/langflow/

Output:

src/backend/base/langflow/components/helpers/memory.py- data = {"text": message.text, "timestamp": message.timestamp}
src/backend/base/langflow/components/helpers/memory.py- if message.sender:
src/backend/base/langflow/components/helpers/memory.py- data["sender"] = message.sender
src/backend/base/langflow/components/helpers/memory.py- if message.sender_name:
src/backend/base/langflow/components/helpers/memory.py- data["sender_name"] = message.sender_name
src/backend/base/langflow/components/helpers/memory.py- if message.session_id:
src/backend/base/langflow/components/helpers/memory.py- data["session_id"] = message.session_id

  • ✅ Create PR with these edits
  • 📌 Create commit in current branch
  • 📋 Get copyable edits

@ogabrielluiz
Copy link
Copy Markdown
Contributor Author

@ogabrielluiz The issue still persists.

What did you do to reproduce it? Did you update the component?

…input handling

* Added documentation link for AgentComponent.
* Removed memory inputs from the agent component for cleaner input management.
* Enhanced error handling in message_response method to ensure better validation and logging of exceptions.
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 7, 2025
@ogabrielluiz ogabrielluiz added the lgtm This PR has been approved by a maintainer label Jul 7, 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.

LGTM, Fix looks ok, lets add tests and further stability fixes post release.

…onversion

* Updated input dictionary construction in LCAgentComponent to use to_lc_message() for Message instances, improving input handling consistency.
@github-actions github-actions Bot removed the bug Something isn't working label Jul 7, 2025
@ogabrielluiz ogabrielluiz added this pull request to the merge queue Jul 7, 2025
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jul 7, 2025
* Updated the sender validation logic in the Message class to remove unnecessary checks for missing sender values.
* This change enhances code clarity and maintains the intended functionality for handling user messages with associated files.
* Modified the test for message conversion to assert that lc_message.content is a string instead of a list.
* Updated assertions to ensure the content matches the expected text, enhancing test accuracy and reliability.
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 8, 2025
@ogabrielluiz ogabrielluiz enabled auto-merge July 8, 2025 00:32
@ogabrielluiz ogabrielluiz added lgtm This PR has been approved by a maintainer and removed lgtm This PR has been approved by a maintainer labels Jul 8, 2025
@ogabrielluiz ogabrielluiz added this pull request to the merge queue Jul 8, 2025
* Modified the sender validation logic to handle cases where the sender is not specified, defaulting to HumanMessage.
* Updated the corresponding test case to reflect this change, ensuring accurate type assertion for lc_message when no sender is provided.
* Replaced the import of BaseModel from langchain.pydantic_v1 with the direct import from pydantic to streamline dependencies.
* This change enhances code clarity and aligns with best practices for managing imports in the codebase.
@ogabrielluiz ogabrielluiz removed this pull request from the merge queue due to a manual request Jul 8, 2025
@ogabrielluiz ogabrielluiz enabled auto-merge July 8, 2025 01:35
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 8, 2025
@ogabrielluiz ogabrielluiz added this pull request to the merge queue Jul 8, 2025
Merged via the queue into main with commit 7aeb687 Jul 8, 2025
21 checks passed
@ogabrielluiz ogabrielluiz deleted the fix-duplicated-anthropic-message branch July 8, 2025 02:02
smatiolids pushed a commit to smatiolids/langflow-dev that referenced this pull request Jul 10, 2025
* fix: update message input handling in LCAgentComponent and improve memory data retrieval

* Refactor MessageTextInput to MessageInput for consistency.
* Enhance input dictionary construction to handle different input types in LCAgentComponent.
* Update get_memory_data method to filter out current input value from retrieved messages.

* fix: update AgentComponent to include documentation link and improve input handling

* Added documentation link for AgentComponent.
* Removed memory inputs from the agent component for cleaner input management.
* Enhanced error handling in message_response method to ensure better validation and logging of exceptions.

* fix: enhance input handling in LCAgentComponent by updating message conversion

* Updated input dictionary construction in LCAgentComponent to use to_lc_message() for Message instances, improving input handling consistency.

* test: add regression test for message duplication in agent component

* Introduced a new test to verify that mathematical expressions do not experience message duplication when processed by the agent component.
* The test checks both input and output JSON to ensure correct handling of expressions like "2+2" without duplication errors.

* test: add workspace tag to regression test for message duplication in agent component

* Updated the regression test for mathematical expressions to include the "@workspace" tag, enhancing test categorization and organization.
* This change ensures better tracking and management of tests related to the agent component.

* fix: add temporary comment in get_memory_data to address message duplication

* Added a TODO comment in the get_memory_data method of AgentComponent to indicate a temporary fix for message duplication issues. This serves as a reminder to develop a more robust solution in the future.

* feat: add message extraction utility for BaseMessage

* Introduced a new helper function, _get_message_from_base_message, to extract and concatenate text content from BaseMessage instances, improving message handling.
* Updated input handling in handle_on_chain_start to utilize the new extraction function, ensuring consistent processing of input messages.

* refactor: standardize code snippets across starter project JSON files

* Updated the "value" field in multiple starter project JSON files to ensure consistent formatting and structure of code snippets.
* This change enhances readability and maintainability of the code examples provided in the starter projects.

* feat: add caching and content dictionary creation for images

* Introduced a new function, create_image_content_dict, to generate a content dictionary for multimodal inputs from image files, enhancing image handling capabilities.
* Implemented LRU caching to optimize performance for repeated image processing.
* Added comprehensive error handling and documentation for better usability and maintainability.

* refactor: update message handling to utilize create_image_content_dict

* Replaced direct image URL creation with create_image_content_dict for improved image content handling in the Data and Message classes.
* Adjusted the order of content in human messages to ensure text appears first, enhancing message structure and clarity.
* Removed deprecated to_lc_message method to streamline the codebase and improve maintainability.

* docs: enhance _get_message_from_base_message docstring for clarity

* Expanded the docstring for the _get_message_from_base_message function to provide detailed information on input types, expected behavior, and examples of usage.
* Improved documentation aims to enhance usability and maintainability of the code by clarifying how to extract text content from BaseMessage instances.

* refactor: enhance image path handling and update message content structure

* Modified the get_file_paths function to support both Image objects and string paths for improved flexibility in file handling.
* Updated test cases to reflect changes in image content structure, ensuring consistency in type and source type attributes.
* Introduced new tests for create_image_content_dict to validate successful creation and error handling for image content dictionaries.

* refactor: streamline message extraction in handle_on_chain_start

* Removed the _get_message_from_base_message function to simplify the codebase.
* Updated handle_on_chain_start to directly use the text method of BaseMessage for extracting message content, enhancing clarity and maintainability.

* feat: enhance input handling for multimodal messages

* Added functionality to process image content within input messages, ensuring images are included in chat history as HumanMessage instances.
* Updated input handling logic to separate image types from text, improving the structure and clarity of message content.
* This enhancement supports better management of multimodal inputs in the agent's chat history.

* feat: add to_lc_message method for converting Data to BaseMessage

* Introduced the to_lc_message method in the Message class to facilitate conversion of Data instances to BaseMessage.
* Implemented logic to handle both HumanMessage and AIMessage based on the presence of required keys and sender type.
* Added logging for missing required keys to improve debugging and maintainability.

* refactor: simplify sender check in Message class

* Updated the sender validation logic in the Message class to remove unnecessary checks for missing sender values.
* This change enhances code clarity and maintains the intended functionality for handling user messages with associated files.

* test: update test_message_from_human_text to reflect content type change

* Modified the test for message conversion to assert that lc_message.content is a string instead of a list.
* Updated assertions to ensure the content matches the expected text, enhancing test accuracy and reliability.

* fix: update sender validation in Message class and adjust test case

* Modified the sender validation logic to handle cases where the sender is not specified, defaulting to HumanMessage.
* Updated the corresponding test case to reflect this change, ensuring accurate type assertion for lc_message when no sender is provided.

* refactor: update import statements for consistency and clarity

* Replaced the import of BaseModel from langchain.pydantic_v1 with the direct import from pydantic to streamline dependencies.
* This change enhances code clarity and aligns with best practices for managing imports in the codebase.

---------

Co-authored-by: Edwin Jose <edwin.jose@datastax.com>
Co-authored-by: Carlos Coelho <80289056+carlosrcoelho@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working fast-track Skip tests and sends PR into the merge queue lgtm This PR has been approved by a maintainer size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants