feat(api): agent-friendly flow graph endpoints#12910
Draft
Empreiteiro wants to merge 1 commit intomainfrom
Draft
feat(api): agent-friendly flow graph endpoints#12910Empreiteiro wants to merge 1 commit intomainfrom
Empreiteiro wants to merge 1 commit intomainfrom
Conversation
Adds GET/POST endpoints under /api/v1/flows/{flow_id}/{components,edges}
so AI agents can inspect and edit flows without round-tripping the full
ReactFlow payload. Wraps the existing lfx.graph.flow_builder helpers,
which already provide type-compatibility validation and idempotent edge
insertion.
Also exposes the four operations on LangflowClient for the MCP server
and other Python consumers, with unit tests for each.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds four endpoints under
/api/v1/flows/{flow_id}/{components,edges}so AI agents (and any HTTP client) can inspect and edit a flow without round-tripping the full ReactFlow payload stored inFlow.data./flows/{flow_id}/components/flows/{flow_id}/edges/flows/{flow_id}/components/flows/{flow_id}/edgesThe write endpoints are thin wrappers over the existing pure helpers in
lfx.graph.flow_builder(add_component,add_connection), which already handle ID generation, ReactFlow handle encoding (œ-quoted JSON), idempotency, andtypes_compatiblevalidation.LangflowClient(the MCP HTTP client) gets typed methods for all four operations, so MCP server tools and other Python consumers don't need to assemble the URLs by hand.Why
Today, an agent that wants to add a node has to PATCH the entire
Flow.datablob — which means parsing it, mutating nested ReactFlow structures, and writing back. This burns context and any schema drift breaks the whole flow. Granular endpoints reduce blast radius and produce localized error messages (e.g.Type mismatch: output 'model_output' produces ['LanguageModel'], but input 'input_value' accepts ['Message']).The catalog endpoint already exists (
GET /api/v1/all); this PR does not duplicate it.Notable design choices
types_compatible()fromlfx.graph.edge.base. Source/target types are auto-resolved from the flow.(source, source_output, target, target_input)twice returns the existing edge.PATCH /flows/{flow_id}behavior. Worth revisiting if it becomes an issue.CurrentActiveUser+ ownership check (Flow.user_id == user.id) as every other flow endpoint.Test plan
src/lfx/tests/unit/mcp/test_client_flow_graph.py(8 passing) covering all fourLangflowClientmethods, including the 400 propagation on type mismatch.Basic Prompting.jsonconfirming the helper flow end-to-end (add component → connect → idempotency check → mismatch rejection).ruff check+ruff format --checkclean across all touched files.list_components,get_flow_info) to use these endpoints instead of parsingflow.datalocally — left as follow-up.Files
src/backend/base/langflow/api/v1/flow_graph.pysrc/lfx/tests/unit/mcp/test_client_flow_graph.pysrc/backend/base/langflow/api/router.py,src/backend/base/langflow/api/v1/__init__.py,src/lfx/src/lfx/mcp/client.py🤖 Generated with Claude Code