Skip to content

fix: target agent component when updating chat flow system prompt#2001

Open
Vchen7629 wants to merge 6 commits into
mainfrom
agent-system-instruction-fix
Open

fix: target agent component when updating chat flow system prompt#2001
Vchen7629 wants to merge 6 commits into
mainfrom
agent-system-instruction-fix

Conversation

@Vchen7629

@Vchen7629 Vchen7629 commented Jul 2, 2026

Copy link
Copy Markdown
Collaborator

Summary

Port of PR #1918 to target main, Fixes #1514. update_chat_flow_system_prompt was targeting the LLM provider component (e.g. "Ollama", "WatsonX") instead of the Agent component where the system_prompt field lives. As a result, saving new agent instructions in OpenRAG settings never updates langflow

Changes:

  • Updated update_chat_flow_system_prompt to use AGENT_COMPONENT_DISPLAY_NAME as the target component
  • Added unit tests verifying the value is written to the Agent component in the flow

Summary by CodeRabbit

  • Bug Fixes

    • System prompt updates now reliably apply to the chat agent component and no longer depend on provider-specific selection logic.
    • Updates are simplified to always target the agent’s system_prompt, improving consistency.
  • Tests

    • Added unit tests to verify the Agent node includes a system_prompt template and that update requests send the correct PATCH payload reflecting the new prompt.

@Vchen7629 Vchen7629 requested a review from lucaseduoli July 2, 2026 19:03
@github-actions github-actions Bot added backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) tests bug 🔴 Something isn't working. labels Jul 2, 2026
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 88ad009a-6987-4a52-8f6a-1e50248a5c98

📥 Commits

Reviewing files that changed from the base of the PR and between a42d5e6 and 65cf3dc.

📒 Files selected for processing (1)
  • tests/unit/test_langflow_agent_system_prompt.py
💤 Files with no reviewable changes (1)
  • tests/unit/test_langflow_agent_system_prompt.py

Walkthrough

The chat settings path now updates Langflow through the Agent node directly, without passing a provider. New tests verify the flow contains an Agent node with system_prompt and that patching updates that field.

Changes

System prompt update fix

Layer / File(s) Summary
Simplify update_chat_flow_system_prompt targeting
src/services/flows_service.py, src/api/settings/langflow_sync.py
update_chat_flow_system_prompt drops the provider argument and always updates the Agent node by AGENT_COMPONENT_DISPLAY_NAME; the caller now passes only system_prompt.
Add flow-loading test helpers
tests/unit/test_langflow_agent_system_prompt.py
Adds helpers to load a flow JSON file and find nodes by display name, plus a test that flows/openrag_agent.json contains an Agent node with a system_prompt field.
Verify Agent node patching
tests/unit/test_langflow_agent_system_prompt.py
Adds an async test that mocks Langflow GET/PATCH calls, invokes update_chat_flow_system_prompt, and asserts the Agent node’s template.system_prompt.value is updated.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: bug

Suggested reviewers: phact, edwinjosechittilappilly

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: updating the chat flow system prompt on the Agent component.
Linked Issues check ✅ Passed The changes target the Agent component where system_prompt lives, which matches the bug report and expected behavior in #1514.
Out of Scope Changes check ✅ Passed The PR stays focused on the system-prompt target fix and related tests without unrelated code changes.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent-system-instruction-fix

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.

@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels Jul 2, 2026

@coderabbitai coderabbitai Bot left a comment

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.

🧹 Nitpick comments (1)
tests/unit/test_langflow_agent_system_prompt.py (1)

8-10: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Relative flow path depends on process cwd.

_load_flow resolves "flows/openrag_agent.json" relative to the current working directory rather than the repository root or test file location. If pytest is invoked from a different directory, both tests will fail with FileNotFoundError.

♻️ Suggested fix: resolve path relative to test file
+from pathlib import Path
+
+_REPO_ROOT = Path(__file__).resolve().parents[2]
+
+
 def _load_flow(flow_path: str) -> dict:
     """Load a Langflow flow JSON file from the given path."""
-    return json.loads(Path(flow_path).read_text(encoding="utf-8"))
+    return json.loads((_REPO_ROOT / flow_path).read_text(encoding="utf-8"))

Also applies to: 27-27, 43-43

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/unit/test_langflow_agent_system_prompt.py` around lines 8 - 10, The
helper _load_flow currently reads the flow JSON using a path that depends on the
process working directory, so tests can break when pytest runs elsewhere. Update
_load_flow in test_langflow_agent_system_prompt.py to resolve the flow path
relative to the test file or repository root before calling Path.read_text, and
make sure the two tests that use openrag_agent.json keep using that resolved
path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/unit/test_langflow_agent_system_prompt.py`:
- Around line 8-10: The helper _load_flow currently reads the flow JSON using a
path that depends on the process working directory, so tests can break when
pytest runs elsewhere. Update _load_flow in test_langflow_agent_system_prompt.py
to resolve the flow path relative to the test file or repository root before
calling Path.read_text, and make sure the two tests that use openrag_agent.json
keep using that resolved path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f7fc59d0-5364-4b86-8f5e-e329b83a352b

📥 Commits

Reviewing files that changed from the base of the PR and between 4f104ec and e48a6dd.

📒 Files selected for processing (3)
  • src/api/settings/langflow_sync.py
  • src/services/flows_service.py
  • tests/unit/test_langflow_agent_system_prompt.py

@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels Jul 2, 2026
@github-actions github-actions Bot added bug 🔴 Something isn't working. and removed bug 🔴 Something isn't working. labels Jul 2, 2026
@github-actions github-actions Bot added the lgtm label Jul 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend 🔷 Issues related to backend services (OpenSearch, Langflow, APIs) bug 🔴 Something isn't working. lgtm tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Updating Agent Instructions in settings doesn't have any effect

2 participants