Skip to content

feat: Add context_id history to agent and chat#10319

Merged
erichare merged 3 commits into
mainfrom
feat-agent-history
Oct 20, 2025
Merged

feat: Add context_id history to agent and chat#10319
erichare merged 3 commits into
mainfrom
feat-agent-history

Conversation

@erichare
Copy link
Copy Markdown
Collaborator

@erichare erichare commented Oct 17, 2025

This pull request introduces support for a new context_id field across several chat-related components in the codebase, allowing for an additional layer of context in chat sessions and memory handling. The changes ensure that context_id can be input, stored, and utilized throughout the chat workflow, improving the granularity of context management.

Context ID support in chat components:

  • Added a MessageTextInput for context_id to the input configuration of AgentComponent, ChatInput, and ChatOutput in their respective files, enabling users to specify a context identifier for chat sessions. [1] [2] [3]

Propagation and usage of context ID:

  • Updated the memory retrieval logic in AgentComponent to pass context_id when fetching memory data, ensuring context-aware memory operations.
  • Modified the message_response methods in both ChatInput and ChatOutput to include context_id in the constructed Message objects, so that messages are tagged with the correct context throughout the chat pipeline. [1] [2]

Input type update:

  • Imported MessageTextInput from lfx.io in agent.py to support the new context ID input type.

Summary by CodeRabbit

  • New Features
    • Added "Context ID" input field to Agent, Chat Input, and Chat Output components, enabling users to organize and manage local memory across multiple contexts with an additional organizational layer.

@erichare erichare requested a review from Empreiteiro October 17, 2025 13:50
@coderabbitai
Copy link
Copy Markdown
Contributor

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

The PR adds a new "context_id" input field across agent, chat input, and chat output components. This context_id is threaded through the messaging system and memory retrieval flow to enable context-scoped memory operations.

Changes

Cohort / File(s) Summary
Agent Component
src/lfx/src/lfx/components/agents/agent.py
Added context_id input field to AgentComponent and extended memory retrieval to pass context_id through MemoryComponent.set for context-scoped memory operations.
Chat Components
src/lfx/src/lfx/components/input_output/chat.py, src/lfx/src/lfx/components/input_output/chat_output.py
Added context_id input field to ChatInput and ChatOutput; propagated context_id through Message.create and message assignment respectively.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Consistent, homogeneous pattern applied across three files: adding the same MessageTextInput field type and threading it through existing function calls. Changes are mechanical and follow a repetitive structure with minimal logic density.

Possibly related PRs

  • #10183: Adds and threads context_id through messaging and memory retrieval/storage including MemoryComponent inputs and calls.
  • #10204: Modifies agent memory retrieval flow in agent.py with debug logging additions.

Suggested labels

enhancement, size:L, lgtm

Suggested reviewers

  • Empreiteiro
  • ogabrielluiz
  • Cristhianzl

Pre-merge checks and finishing touches

❌ Failed checks (1 error, 3 warnings)
Check name Status Explanation Resolution
Test Coverage For New Implementations ❌ Error The PR introduces new context_id functionality across three LFX components (AgentComponent, ChatInput, and ChatOutput) that propagates context identifiers through the message creation and memory retrieval pipeline. However, the PR consists of only three modified source files with zero corresponding test additions or modifications. Verification searches confirm that no context_id tests exist in the project's existing test files (test_agent_component.py, test_chat_input.py, test_chat_output.py, or any LFX tests), and no new test files were added to this PR. The implementation changes show that context_id is properly wired through Message.create() and MemoryComponent.set(), but without tests, there is no verification that these integrations work correctly or that the context_id field is properly persisted and retrieved. Add test coverage for the new context_id feature by creating or modifying existing test files. Add unit tests to src/backend/tests/unit/components/agents/test_agent_component.py to verify that AgentComponent correctly initializes the context_id input field and passes it to MemoryComponent.set() during memory retrieval. Modify src/backend/tests/integration/components/inputs/test_chat_input.py and src/backend/tests/integration/components/outputs/test_chat_output.py to verify context_id is properly included in Message.create() calls and persisted on message objects. Include integration tests that verify context_id flows end-to-end through the chat pipeline with both session_id and context_id parameters specified simultaneously.
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 The PR adds context_id functionality to three core components (AgentComponent, ChatInput, ChatOutput) but contains zero test coverage for these new features. Established test files exist for all three components with clear testing patterns already demonstrated: test_agent_component.py, test_chat_input.py, and test_chat_output.py already test similar session_id functionality. However, the PR does not modify any test files despite implementing context_id across multiple integration points. The existing tests verify that session_id is correctly passed to Message.create() and aget_messages(), and that messages are properly stored and retrieved—yet the analogous context_id behavior remains completely untested. This leaves the new context_id input fields, message propagation logic, and memory retrieval integration without validation. Add test coverage for context_id functionality by modifying existing test files to include context_id test cases following the established patterns. For test_chat_input.py, add tests that verify context_id is included in Message.create() calls with both populated and empty values, mirroring the existing session_id tests. For test_chat_output.py, add tests that verify context_id is correctly assigned to message.context_id similar to how session_id verification is performed. For test_agent_component.py, add tests that verify context_id is passed to MemoryComponent.set() during get_memory_data() calls. Use the run_single_component() utility pattern already established in these test files, and include both success cases and edge cases (empty context_id, null values).
Test File Naming And Structure ⚠️ Warning The PR modifies three component files (agent.py, chat.py, and chat_output.py) to add context_id functionality, but no test files were added or modified in this PR. While test files exist for these components following proper conventions (e.g., test_agent_component.py, test_chat_input.py, test_chat_output.py with descriptive test function names like test_build_config_update() and test_default()), none of them have been updated to verify the new context_id field. The existing tests cover other scenarios but lack coverage for the new feature, missing tests for: (1) context_id input field presence and configuration, (2) context_id propagation through the message creation pipeline in ChatInput and ChatOutput, (3) context_id usage in AgentComponent's memory retrieval, and (4) edge cases like empty or missing context_id values. The PR should be updated to include test coverage for the new context_id functionality. Specifically: (1) add test functions to src/backend/tests/unit/components/agents/test_agent_component.py to verify context_id is present in AgentComponent's inputs and that memory retrieval correctly passes context_id to MemoryComponent.set(), (2) add test functions to src/backend/tests/integration/components/inputs/test_chat_input.py to verify context_id is properly set on created Message objects, (3) add test functions to src/backend/tests/integration/components/outputs/test_chat_output.py to verify context_id is correctly propagated to Message objects, and (4) use descriptive test names following the existing pattern (e.g., test_context_id_passed_to_message()) and include both positive scenarios (context_id is set) and edge cases (empty context_id).
✅ 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 "feat: Add context_id history to agent and chat" is directly related to the main change in the pull request. It clearly identifies the key feature being added (context_id) and specifies the affected components (agent and chat). The changeset confirms that context_id input fields have been added to AgentComponent, ChatInput, and ChatOutput, with the context_id being propagated through memory retrieval and message creation. The title uses the term "history" which references the context-aware memory operations that are being enhanced. A developer scanning the pull request history would immediately understand that context_id functionality has been added to agent and chat components.
Excessive Mock Usage Warning ✅ Passed This PR introduces the context_id feature but does not modify any test files. The existing test suite for the affected components shows appropriate testing patterns: test_chat_input.py and test_chat_output_component.py use zero mocks and test real component behavior through integration testing, while test_agent_component.py's active tests use minimal mocking appropriately reserved for external LLM dependencies (MockLanguageModel). The extensive mocking in test_agent_component.py (32 mock references) is confined to skipped tests (@pytest.mark.skip) that are not executed. Since this PR introduces no new tests and therefore no new mock patterns, it does not exhibit excessive mock usage.

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 enhancement New feature or request label Oct 17, 2025
@github-actions
Copy link
Copy Markdown
Contributor

Component index has been automatically updated due to changes in src/lfx/src/lfx/components/

New Index:
🧩 Components: 358
📁 Categories: 92

@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Oct 17, 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

🧹 Nitpick comments (1)
src/lfx/src/lfx/components/agents/agent.py (1)

88-94: Consider centralizing the context_id input definition.

The context_id input field is defined identically in three components (ChatInput, ChatOutput, AgentComponent). If this pattern is common in the codebase, consider creating a shared constant or factory function to reduce duplication.

Example approach (to be applied in a shared module):

# In a shared module (e.g., lfx/components/common/inputs.py)
CONTEXT_ID_INPUT = MessageTextInput(
    name="context_id",
    display_name="Context ID",
    info="The context ID of the chat. Adds an extra layer to the local memory.",
    value="",
    advanced=True,
)

Then import and use it in each component:

from lfx.components.common.inputs import CONTEXT_ID_INPUT

inputs = [
    ...,
    CONTEXT_ID_INPUT,
    ...,
]
📜 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 5c4b8be and 279722a.

📒 Files selected for processing (3)
  • src/lfx/src/lfx/components/agents/agent.py (3 hunks)
  • src/lfx/src/lfx/components/input_output/chat.py (2 hunks)
  • src/lfx/src/lfx/components/input_output/chat_output.py (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (3)
src/lfx/src/lfx/components/input_output/chat_output.py (1)
src/lfx/src/lfx/inputs/inputs.py (1)
  • MessageTextInput (206-257)
src/lfx/src/lfx/components/agents/agent.py (1)
src/lfx/src/lfx/inputs/inputs.py (2)
  • MessageTextInput (206-257)
  • MultilineInput (260-270)
src/lfx/src/lfx/components/input_output/chat.py (1)
src/lfx/src/lfx/inputs/inputs.py (1)
  • MessageTextInput (206-257)
⏰ 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). (2)
  • GitHub Check: Update Starter Projects
  • GitHub Check: update-index
🔇 Additional comments (6)
src/lfx/src/lfx/components/input_output/chat.py (2)

63-69: LGTM!

The context_id input field is well-configured with appropriate metadata and follows the same pattern as session_id above it.


97-97: No action required - Message.create() properly accepts context_id parameter.

Verification confirms the Message.create() method is a @classmethod that accepts **kwargs, and the Message class defines context_id as a valid field. The context_id parameter passed in chat.py line 97 will be correctly accepted and processed.

src/lfx/src/lfx/components/agents/agent.py (2)

24-24: LGTM!

The MessageTextInput import is correctly added to support the new context_id field.


418-418: No action needed—context_id parameter is correctly supported.

Verification confirms that MemoryComponent.set() accepts the context_id parameter. The Component base class defines set(**kwargs) at line 395, which accepts arbitrary keyword arguments and processes them through _process_connection_or_parameters(). Since MemoryComponent defines context_id as an explicit input parameter, passing it via .set(context_id=self.context_id) at line 418 is correct and will not cause runtime errors.

src/lfx/src/lfx/components/input_output/chat_output.py (2)

66-72: LGTM!

The context_id input field is consistently defined with the same configuration as in the other components.


131-131: ****

The Message class already has a context_id attribute defined in src/lfx/src/lfx/schema/message.py as context_id: str | UUID | None = Field(default=""). The assignment at line 131 is valid and will not cause AttributeError at runtime.

Likely an incorrect or invalid review comment.

@Empreiteiro
Copy link
Copy Markdown
Collaborator

Eric, it worked as expected!

One observation is that, as shown in the video, when retrieving conversations from B (or any other sequential agent), it's not possible to retrieve the agent's input (I believe the input is controlled by Chat Input and it is only possible to add one to the flow.)

In the current format, I've already unlocked many cases, and it already avoids the main problem of mixing up agent memories. But if we could have the input in B's memory, just like we have in A, it would be perfect!

In A, we see:
User: ...
Agent: ...

In B, we see:
Agent: ...
Agent: ...

Gravacao.de.Tela.2025-10-17.180331.mp4

Copy link
Copy Markdown
Collaborator

@Empreiteiro Empreiteiro left a comment

Choose a reason for hiding this comment

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

LGTM! The observations made in the other comment will be considered in the future!

@github-actions github-actions Bot added the lgtm This PR has been approved by a maintainer label Oct 20, 2025
@erichare erichare enabled auto-merge October 20, 2025 18:59
@sonarqubecloud
Copy link
Copy Markdown

@erichare erichare added this pull request to the merge queue Oct 20, 2025
@github-actions github-actions Bot added enhancement New feature or request and removed enhancement New feature or request labels Oct 20, 2025
Merged via the queue into main with commit 4cad7ab Oct 20, 2025
22 of 25 checks passed
@erichare erichare deleted the feat-agent-history branch October 20, 2025 19:10
mokeyish pushed a commit to mokeyish/langflow that referenced this pull request Oct 21, 2025
* feat: Add context_id history to agent and chat

* chore: update component index

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
korenLazar pushed a commit to kiran-kate/langflow that referenced this pull request Nov 13, 2025
* feat: Add context_id history to agent and chat

* chore: update component index

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request lgtm This PR has been approved by a maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants