Skip to content

fix: Enhance Flow Copilot with RAG, Memory, and Structured JSON Output - #321

Open
viikas04 wants to merge 13 commits into
Lamatic:mainfrom
viikas04:feat/flow-copilot-enhancements
Open

fix: Enhance Flow Copilot with RAG, Memory, and Structured JSON Output#321
viikas04 wants to merge 13 commits into
Lamatic:mainfrom
viikas04:feat/flow-copilot-enhancements

Conversation

@viikas04

@viikas04 viikas04 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR enhances the original Flow Copilot submission with a significantly richer pipeline:

  • RAG grounding: Added a RAG node that retrieves real Lamatic node documentation from a vector store (lamaticnodedocs) to ground blueprint generation in actual platform capabilities, reducing hallucinated node types.
  • Structured JSON output: Added a Generate JSON node that parses the blueprint into structured fields (flowName, trigger, nodes, nodeSequence, assumptions) for downstream/programmatic use.
  • Multi-turn memory: Added Memory Retrieve and Memory Add nodes so the agent can hold context across a conversation.
  • Expanded knowledge base: Extended the node documentation vector store with "Common Flow Patterns" and "Best Practices" sections (7 → 12 indexed chunks), with measurable improvement in blueprint quality on re-test.
  • Performance: Reduced end-to-end pipeline latency from ~280s to ~20-30s by switching to gemini-3.5-flash-lite.

Current flow: Chat Widget → Memory Retrieve → RAG → Generate Text → Generate JSON → Memory Add → Chat Response

Notes for reviewers

Two platform-level issues were observed during development (documented, not blocking):

  1. Memory Add fails to persist records. The node completes without hard-erroring the pipeline, but the underlying generative-model call returns 400 google error: * GenerateContentRequest.contents: contents is not specified. This appears to be a Lamatic platform-side issue in how the Memory Add node constructs its internal Gemini request — no prompt/content field is exposed in the node's UI to configure this directly. As a result, no records are persisted to the flowcopilotconversationmemory store even after multiple real runs. The rest of the pipeline (RAG, Generate Text, Generate JSON, Chat Response) completes successfully regardless, so the user-facing response is unaffected.
  2. An intermittent RAG/Generate Text timeout pattern was also observed (requests failing at ~127s), which self-resolved within the same session and has not recurred since.

PR Checklist

1. Select Contribution Type

  • Kit (kits/<category>/<kit-name>/)
  • Bundle (bundles/<bundle-name>/)
  • Template (templates/<template-name>/)

2. General Requirements

  • PR is for one project only (no unrelated changes)
  • No secrets, API keys, or real credentials are committed
  • Folder name uses kebab-case and matches the flow ID
  • All changes are documented in README.md (purpose, setup, usage)

3. File Structure (Check what applies)

  • config.json present with valid metadata (name, description, tags, steps, author, env keys)
  • All flows in flows/<flow-name>/ (where applicable) include:
    • config.json (Lamatic flow export)
    • inputs.json
    • meta.json
    • README.md
  • .env.example with placeholder values only (kits only)
  • No hand‑edited flow config.json node graphs (changes via Lamatic Studio export)

4. Validation

  • npm install && npm run dev works locally (kits: UI runs; bundles/templates: flows are valid)
  • PR title is clear (e.g., [kit] Add <name> for <use case>)
  • GitHub Actions workflows pass (all checks are green)
  • All CodeRabbit or other PR review comments are addressed and resolved
  • No unrelated files or projects are modified

Flow Structure

  • Chat Widget receives the user request.
  • Memory Retrieve loads previous conversation context.
  • RAG Node retrieves relevant Lamatic documentation from lamaticnodedocs.
  • Generate Text creates a documentation-grounded flow blueprint.
  • Generate JSON parses the blueprint into structured fields:
    • flowName
    • trigger
    • nodes
    • nodeSequence
    • assumptions
  • Memory Add stores the conversation context.
  • Chat Response returns the generated blueprint.

Added Files

Model configurations

  • flow-copilot_instructor-llmnode-429_generative-model-name.ts — configures Gemini 3.5 Flash Lite for structured JSON generation.
  • flow-copilot_memory-node-302_embedding-model-name.ts — configures Gemini embeddings for memory storage.
  • flow-copilot_memory-node-302_generative-model-name.ts — configures the memory generation model.
  • flow-copilot_memory-retrieve-node-859_embedding-model-name.ts — configures embeddings for memory retrieval.
  • flow-copilot_ragnode-640_embedding-model-name.ts — configures embeddings for RAG searches.
  • flow-copilot_ragnode-640_generative-model-name.ts — configures the RAG generation model.

Prompts

  • flow-copilot_instructor-llmnode-429_system_0.md — defines structured blueprint parsing.
  • flow-copilot_instructor-llmnode-429_user_1.md — supplies the generated blueprint to the JSON parser.
  • flow-copilot_llmnode-474_user_1.md — adds retrieved documentation to the text-generation prompt.
  • flow-copilot_ragnode-640_system_0.md — defines grounded responses and numbered references.
  • flow-copilot_ragnode-640_user_1.md — requests relevant node types, patterns, and best practices.

Other files

  • flows/flow-copilot.ts — adds Memory Retrieve, RAG Node, Generate Text, Generate JSON, Memory Add, and Chat Response nodes. It connects these nodes into a retrieval, grounding, generation, parsing, persistence, and response pipeline.
  • README.md — documents flow setup, documentation ingestion, the lamaticnodedocs vector store, model configuration, structured output, and multi-turn memory.

High-Level Summary

  • The flow converts natural-language requests into Lamatic flow blueprints.
  • RAG grounds blueprint generation in Lamatic node documentation.
  • Memory nodes support multi-turn conversations.
  • Structured JSON exposes the blueprint for programmatic use.
  • Gemini Flash Lite reduces latency to approximately 20–30 seconds.

@coderabbitai

coderabbitai Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@github-actions[bot], you've reached your PR review limit, so we couldn't start this review.

Next review available in: 59 minutes

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: a6436ccb-b8bd-4108-a856-5b04776a5345

📥 Commits

Reviewing files that changed from the base of the PR and between 247ce19 and 30cb673.

📒 Files selected for processing (1)
  • kits/flow-copilot/flows/flow-copilot.ts

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

Walkthrough

The flow-copilot architecture now retrieves conversation memory and node documentation, generates structured flow blueprints, stores conversation details, and returns blueprint data. Gemini configurations support the new retrieval and generation nodes. Prompts and README instructions cover citations, setup, and knowledge-base ingestion.

Changes

Flow Copilot RAG and Memory Pipeline

Layer / File(s) Summary
Flow inputs and model configurations
kits/flow-copilot/flows/flow-copilot.ts, kits/flow-copilot/model-configs/*
Declares inputs and Gemini model configurations for memory retrieval, RAG, Instructor JSON generation, and memory persistence.
RAG and memory retrieval nodes
kits/flow-copilot/flows/flow-copilot.ts, kits/flow-copilot/prompts/flow-copilot_ragnode-640_user_1.md, kits/flow-copilot/prompts/flow-copilot_ragnode-640_system_0.md
Retrieves conversation memory and searches the lamaticnodedocs vector store. RAG output follows numbered citation rules.
Instructor JSON generation and memory persistence
kits/flow-copilot/flows/flow-copilot.ts, kits/flow-copilot/prompts/flow-copilot_instructor-llmnode-429_*
Parses the flow description into structured JSON and stores the user request with generated flow details.
Graph edges and routing
kits/flow-copilot/flows/flow-copilot.ts
Routes requests through memory retrieval, RAG, text generation, Instructor generation, memory storage, and response handling.
Prompt context integration
kits/flow-copilot/prompts/flow-copilot_llmnode-474_user_1.md
Adds retrieved documentation references to the text-generation prompt.
Setup and architecture documentation
kits/flow-copilot/README.md
Documents deployment, Gemini credentials, knowledge-base seeding, structured output, the expanded architecture, and follow-up conversation support.

Suggested reviewers: amanintech, d-pamneja

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly identifies the main changes: RAG, memory, and structured JSON output for Flow Copilot.
Description check ✅ Passed The description covers the main changes, pipeline, known issues, and checklist items, but leaves some validation items unchecked.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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 commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

:robot_face: AgentKit Structural Validation

Existing Kits Modified (not allowed in feat: PRs)

  • kits/flow-copilot

Check Results

Check Status
No edits to existing kits ❌ Fail
Required root files present ✅ Pass
Flow .ts files present ✅ Pass
lamatic.config.ts valid ✅ Pass
No changes outside kits/ ✅ Pass

❌ Errors

  • Existing kit modified: kits/flow-copilot — feat: PRs should only add new contributions

🛑 Please fix the errors above before this PR can be merged.

Refer to CONTRIBUTING.md and CLAUDE.md for the expected folder structure.
❓ Need help? Ask in GitHub Discussions — don't DM on Slack, it helps future contributors if the answer is public.

@github-actions

github-actions Bot commented Aug 4, 2026

Copy link
Copy Markdown
Contributor

Failure recorded at 2026-08-04T12:34:55Z UTC. If this PR is not fixed within 4 weeks it will be automatically closed.

@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.

Actionable comments posted: 5

🤖 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.

Inline comments:
In `@kits/flow-copilot/flows/flow-copilot.ts`:
- Around line 58-64: Update the flow input configuration for memoryNode_302 so
its generativeModelName dependency is configurable: add a matching
generativeModelName input alongside embeddingModelName, or remove the node’s
generative-model requirement if it is not needed. Keep the model-selection
configuration consistent between memoryNode_302 and the exposed flow inputs.
- Around line 227-256: Update the downstream references for
InstructorLLMNode_429 so both sinks consume its verified structured result:
change the structured result field used by memoryNode_302’s memoryValue content
and replace the stale LLMNode_474 generatedResponse template in
responseNode_triggerNode_1.values.content. Preserve the existing sink
configuration and route both references to the appropriate output field of
InstructorLLMNode_429.

In `@kits/flow-copilot/prompts/flow-copilot_ragnode-640_user_1.md`:
- Line 1: Replace the placeholder in the RAGNode_640 prompt with an instruction
that includes the current request/query and directs retrieval of relevant
Lamatic documentation. Define a clear output contract requiring the node to
return only the retrieved references or context that LLMNode_474 can use for
grounding, while preserving the request content in the prompt.

In `@kits/flow-copilot/README.md`:
- Around line 12-16: Add a human-readable setup section before “How to use” in
the README, covering kit deployment, Gemini credential configuration, and
preparation of the ingest-node-docs knowledge-base flow. Keep the existing Chat
Widget usage steps unchanged and follow the setup conventions used by other
kits/*/README.md files.
- Line 4: Add a blank line immediately after each Markdown section heading in
README.md, including the headings near lines 4, 12, 41, and 44, so the document
satisfies markdownlint MD022 without changing the heading text or surrounding
content.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 359b2b78-38f9-4e24-aa49-499f1a9f4dfb

📥 Commits

Reviewing files that changed from the base of the PR and between 8b5b00c and ddf9407.

📒 Files selected for processing (13)
  • kits/flow-copilot/README.md
  • kits/flow-copilot/flows/flow-copilot.ts
  • kits/flow-copilot/model-configs/flow-copilot_instructor-llmnode-429_generative-model-name.ts
  • kits/flow-copilot/model-configs/flow-copilot_memory-node-302_embedding-model-name.ts
  • kits/flow-copilot/model-configs/flow-copilot_memory-node-302_generative-model-name.ts
  • kits/flow-copilot/model-configs/flow-copilot_memory-retrieve-node-859_embedding-model-name.ts
  • kits/flow-copilot/model-configs/flow-copilot_ragnode-640_embedding-model-name.ts
  • kits/flow-copilot/model-configs/flow-copilot_ragnode-640_generative-model-name.ts
  • kits/flow-copilot/prompts/flow-copilot_instructor-llmnode-429_system_0.md
  • kits/flow-copilot/prompts/flow-copilot_instructor-llmnode-429_user_1.md
  • kits/flow-copilot/prompts/flow-copilot_llmnode-474_user_1.md
  • kits/flow-copilot/prompts/flow-copilot_ragnode-640_system_0.md
  • kits/flow-copilot/prompts/flow-copilot_ragnode-640_user_1.md

Comment on lines +58 to 64
"memoryNode_302": [
{
"name": "embeddingModelName",
"label": "Embedding Model Name",
"type": "model"
}
]

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.

🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

flow='kits/flow-copilot/flows/flow-copilot.ts'

ast-grep outline "$flow"
rg -n -C 6 \
  -e '"memoryNode_302"' \
  -e '"embeddingModelName"' \
  -e '"generativeModelName"' \
  "$flow"

Repository: Lamatic/AgentKit

Length of output: 4769


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== candidate files =="
git ls-files | rg '(^|/)(flows|package\.json|README|lamatic\.config|.*model-configs.*)$|memory-node-302|memory-retrieve-node-859' | sed -n '1,200p'

echo
echo "== flow package/config snippets =="
for f in kits/flow-copilot/package.json kits/flow-copilot/README.md kits/flow-copilot/lamatic.config.ts; do
  [ -f "$f" ] && { echo "--- $f"; sed -n '1,220p' "$f"; }
done

echo
echo "== model-config references =="
rg -n "memory-node-302|memory-retrieve-node-859|generative_model_name|embedding_model_name|generativeModelName|embeddingModelName" kits -S

Repository: Lamatic/AgentKit

Length of output: 50373


Mission abort on missing generative model for Memory Add.

memoryNode_302 references generativeModelName, but the flow inputs only expose embeddingModelName. If inputs drives Lamatic Studio model selection, the user cannot configure this model. Add the matching generative-model input or fix the node configuration to not require it.

🤖 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 `@kits/flow-copilot/flows/flow-copilot.ts` around lines 58 - 64, Update the
flow input configuration for memoryNode_302 so its generativeModelName
dependency is configurable: add a matching generativeModelName input alongside
embeddingModelName, or remove the node’s generative-model requirement if it is
not needed. Keep the model-selection configuration consistent between
memoryNode_302 and the exposed flow inputs.

Comment thread kits/flow-copilot/flows/flow-copilot.ts
Comment thread kits/flow-copilot/prompts/flow-copilot_ragnode-640_user_1.md Outdated
Comment thread kits/flow-copilot/README.md
Comment thread kits/flow-copilot/README.md
@viikas04 viikas04 changed the title feat: Enhance Flow Copilot with RAG, Memory, and Structured JSON Output fix: Enhance Flow Copilot with RAG, Memory, and Structured JSON Output Aug 4, 2026
@coderabbitai
coderabbitai Bot requested a review from d-pamneja August 4, 2026 13:30

@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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@kits/flow-copilot/prompts/flow-copilot_ragnode-640_user_1.md`:
- Line 2: Add exactly one trailing newline after the
{{triggerNode_1.output.chatMessage}} expression in the prompt content,
preserving the existing text and avoiding any heading or lint-suppression
changes.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 725d0083-ea7c-4753-99a4-95fa3fc58aaa

📥 Commits

Reviewing files that changed from the base of the PR and between c2dd6a0 and 988ea86.

📒 Files selected for processing (1)
  • kits/flow-copilot/prompts/flow-copilot_ragnode-640_user_1.md

Comment thread kits/flow-copilot/prompts/flow-copilot_ragnode-640_user_1.md Outdated
@github-actions

github-actions Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 5, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Already reviewed.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@viikas04

viikas04 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor Author

review

@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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@kits/flow-copilot/flows/flow-copilot.ts`:
- Line 276: Update the flow-copilot projections so the full
InstructorLLMNode_429 blueprint is preserved: in
kits/flow-copilot/flows/flow-copilot.ts#L276-L276, expand memoryValue[0].content
to include trigger and nodes instead of only flowName, nodeSequence, and
assumptions; and in kits/flow-copilot/flows/flow-copilot.ts#L296-L296, expand
responseNode_triggerNode_1.values.content the same way or pass through the full
structured result. Keep the existing flowName, nodeSequence, and assumptions
fields intact while adding the missing trigger and nodes data.
🪄 Autofix

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI (base), Organization UI (inherited)

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: d647b457-a997-4165-bac1-68fba45e6464

📥 Commits

Reviewing files that changed from the base of the PR and between 247ce19 and 0d470ca.

📒 Files selected for processing (1)
  • kits/flow-copilot/flows/flow-copilot.ts

Comment thread kits/flow-copilot/flows/flow-copilot.ts Outdated
@akshatvirmani akshatvirmani changed the title fix: Enhance Flow Copilot with RAG, Memory, and Structured JSON Output feat: fix: Enhance Flow Copilot with RAG, Memory, and Structured JSON Output Aug 5, 2026
@viikas04

viikas04 commented Aug 6, 2026

Copy link
Copy Markdown
Contributor Author

Hi @akshatvirmani — noticed the title was updated to include feat: again, which re-triggers the structural validation check (since this PR modifies an existing kit, which isn't allowed for feat: PRs). I've reverted it back to fix: to keep the check passing — let me know if you'd prefer it labeled differently for tracking purposes.

@viikas04 viikas04 changed the title feat: fix: Enhance Flow Copilot with RAG, Memory, and Structured JSON Output fix: Enhance Flow Copilot with RAG, Memory, and Structured JSON Output Aug 6, 2026
@github-actions

github-actions Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor
⚠️ Action not completed

Review rate limited.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants