Skip to content

Conversation

@ogabrielluiz
Copy link
Contributor

@ogabrielluiz ogabrielluiz commented Dec 17, 2025

Note

This is a Proof of Concept PR to validate the agent blocks architecture. Once the approach is established, this will be broken into smaller, more modular PRs for easier review. (This PR has ~9k new lines but most of them are tests 😅)

Summary

Introduces Agent Blocks - a set of composable primitives for building agent workflows visually:

  • AgentStep: The reasoning core - sends messages to LLM and routes based on tool calls
  • ExecuteTool: Executes tool calls from AgentStep with parallel execution support
  • WhileLoop: Loop control for iterative agent execution
  • AgentLoop: Pre-composed component that encapsulates the complete agent loop

Key Features

  • Conditional routing based on tool calls (AgentStep outputs to either ai_message or tool_calls)
  • Parallel tool execution with proper error handling
  • Streaming support with immediate tool notifications
  • Built-in session memory - AgentLoop auto-fetches chat history from Langflow's session memory
  • Full message history preservation via DataFrame
  • Think tool support for step-by-step reasoning

Architecture

ChatInput → WhileLoop → AgentStep → [Tool Calls] → ExecuteTool → WhileLoop
                              ↓ [AI Message - done]
                         ChatOutput

Memory Integration

AgentLoop automatically retrieves conversation history from Langflow's session memory:

  • message_history - Optional DataFrame input (takes precedence if provided)
  • n_messages - Number of messages to retrieve (default: 100)
  • context_id - Optional context ID for memory isolation

Benchmark Results (vs other agent frameworks)

50 iterations, 100% success rate, using gpt-4o-mini:

Framework Version Avg Init Avg Runtime Avg Total
Langflow latest 0.89ms 1936ms 1937ms
LangGraph 1.0.5 12.33ms 1923ms 1935ms
Pydantic-AI 1.34.0 8.26ms 1941ms 1949ms
Agno 2.3.13 0.04ms 2934ms 2934ms

Runtime differences between Langflow, LangGraph, and Pydantic-AI are within API latency variance (~18ms). Langflow's AgentLoopComponent performs on par with the best agent frameworks.

Test plan

  • Unit tests for all agent block components
  • Integration tests for agent graph builder
  • Contract tests for agent loop events
  • E2E tests for tool calling workflows
  • Manual testing in UI

Add WhileLoop, AgentStep, ExecuteTool, and ThinkTool components:

- WhileLoop: Flow control component with initial_state input for
  MessageHistory integration and loop feedback support
- AgentStep: LLM reasoning step with conditional routing (ai_message
  or tool_calls output based on model response)
- ExecuteTool: Executes tool calls with parallel execution and
  timeout support, outputs updated conversation as DataFrame
- ThinkTool: Optional tool that lets the model reason step-by-step

Supporting infrastructure:
- LCModelComponent base class for model components
- Message and tool execution utilities
- Updated serve_app to use execute_graph_with_capture
- EventManager improvements for streaming
- Frontend cleanEdges fix for group_outputs components

These components enable visual agent loops:
ChatInput → WhileLoop → AgentStep → [tool_calls] → ExecuteTool → WhileLoop
                             ↓ [ai_message]
                         ChatOutput
Add Agent Blocks category to the frontend UI:
- Add nodeColors entry with violet color (#7C3AED)
- Add nodeColorsName mapping
- Add SIDEBAR_CATEGORIES entry after Flow Control
- Add categoryIcons with Blocks icon
- Add nodeIconToDisplayIconMap entry
…mportant messages based on vertex configuration
…is correctly assigned and all fields are included
Introduces comprehensive unit and contract tests validating the agent loop’s graph execution, LLM invocation, streaming behavior, and tool-call lifecycle. Ensures single AI message updates, immediate tool notification during streaming with a parent message, and reuse of tool entries across execution to avoid duplicates.

Improves reliability and UX by formalizing event sequencing (accessing → executed → final), enforcing one message ID per response, and preventing duplicate message events. Supports performance by minimizing DB updates during streaming and tightening tool-content updates.

Relates to feature X to enhance user experience and optimize performance.
- Check model_message.text instead of lf_message.text for unconsumed generator
  (lf_message loses generator reference after serialization via model_dump)
- Remove redundant aggregation in fallback loop - aggregation already happens
  inside stream_and_capture() via nonlocal aggregated_chunk
- Fixes corrupted tool_calls (e.g., 'calculatorcalculator') when running
  without event_manager
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 17, 2025

Important

Review skipped

Draft detected.

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.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat/agent-blocks

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 community Pull Request from an external contributor enhancement New feature or request and removed enhancement New feature or request labels Dec 17, 2025
@ogabrielluiz ogabrielluiz removed the community Pull Request from an external contributor label Dec 17, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 18, 2025
@ogabrielluiz ogabrielluiz changed the base branch from main to feat/loop-subgraph December 18, 2025 12:54
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 18, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Dec 18, 2025
…rokenEdgesEdges

   Fixed handle reconstruction to match how NodeOutputParameter builds handles:
   - Regular outputs use [selectedType]
   - Loop outputs with allows_loop=true use [selectedType, ...loop_types]
   This fixes loop connections being incorrectly removed as invalid when loading  flows with While Loop and Execute Tool components.                                                                   Added comprehensive unit tests for both functions covering edge validation, loop edges, group_outputs handling, and hidden field filtering.
- Add SharedContextEventsDisplay component for rendering shared context updates
- Add sharedContextStore for managing shared context state
- Update ContentDisplay to include shared context events
- Add SharedContextEventOutput type to chat types
- Update buildUtils to handle shared context events
@ogabrielluiz ogabrielluiz changed the title feat: Agent Blocks - composable agent building primitives feat: Agent Blocks for composable agent Jan 7, 2026
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jan 7, 2026
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jan 8, 2026
- Fix extract_loop_output to handle dict outputs from model_dump()
- Add loop subgraph execution infrastructure
- Preserve component configuration across subgraph deepcopy
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jan 8, 2026
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jan 8, 2026
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants