# Comparison

BrainyFlow stands out in the AI framework landscape by prioritizing simplicity, modularity, and developer experience over feature bloat.

## Quick Framework Comparison

| Framework      | Core Abstraction | App-Specific Wrappers | Vendor-Specific Wrappers | Lines  | Size   |
| -------------- | ---------------- | --------------------- | ------------------------ | ------ | ------ |
| **BrainyFlow** | ✨                | ❌                     | ❌                        | \~300  | \~15KB |
| LangChain      | ⚠️               | ✅                     | ✅                        | \~500K | \~50MB |
| LlamaIndex     | ⚠️               | ✅                     | ✅                        | \~200K | \~25MB |
| Haystack       | ⚠️               | ✅                     | ✅                        | \~100K | \~20MB |

## BrainyFlow's Philosophy Recap

Before diving into deeper comparisons, let's reiterate BrainyFlow's core tenets:

* **Minimalist Core:** A tiny codebase (\~300 lines) providing essential abstractions (`Node`, `Flow`, `Memory`).
* **Graph-Based Abstraction:** Uses nested directed graphs to model application logic, separating data flow (`Memory`) from computation (`Node`).
* **Zero Dependencies:** The core framework has no external dependencies, offering maximum flexibility.
* **No Vendor Lock-in:** Encourages using external utilities directly, avoiding framework-specific wrappers for APIs or databases.
* **Agentic Coding Friendly:** Designed to be intuitive for both human developers and AI assistants collaborating on code.
* **Composability:** Flows can be nested within other flows, enabling modular design.

## Feature Comparison Matrix

| Feature                   | BrainyFlow         | LangChain         | LangGraph            | CrewAI                    | AutoGen               | PocketFlow       |
| ------------------------- | ------------------ | ----------------- | -------------------- | ------------------------- | --------------------- | ---------------- |
| **Core Abstraction**      | Nodes & Flows      | Chains & Agents   | State Graphs         | Agents & Crews            | Conversational Agents | Nodes & Flows    |
| **Dependencies**          | None               | Many              | Many (via LangChain) | Several                   | Several               | None             |
| **Codebase Size**         | Tiny (\~300 lines) | Large             | Medium               | Medium                    | Medium                | Tiny (100 lines) |
| **Flexibility**           | High               | Medium            | Medium               | Low                       | Medium                | High             |
| **Built-in Integrations** | None               | Extensive         | Via LangChain        | Several                   | Several               | None             |
| **Learning Curve**        | Moderate           | Steep             | Very Steep           | Moderate                  | Moderate              | Moderate         |
| **Primary Focus**         | Graph Execution    | Component Library | State Machines       | Multi-Agent Collaboration | Conversational Agents | Graph Execution  |

## BrainyFlow vs. LangChain

* **Core Abstraction:** LangChain offers a vast array of components (Chains, LCEL, Agents, Tools, Retrievers, etc.). BrainyFlow focuses solely on the Node/Flow/Memory graph.
* **Dependencies & Size:** LangChain has numerous dependencies depending on the components used, leading to a larger footprint. BrainyFlow core is dependency-free.
* **Flexibility vs. Opinionation:** LangChain provides many pre-built components, which can be faster but potentially more opinionated. BrainyFlow offers higher flexibility, requiring developers to build or integrate utilities themselves.
* **Vendor Integrations:** LangChain has extensive built-in integrations. BrainyFlow intentionally avoids these in its core.
* **Learning Curve:** LangChain's breadth can be overwhelming. BrainyFlow's core is small, but mastering its flexible application requires understanding the graph pattern well.

## BrainyFlow vs. LangGraph

* **Core Abstraction:** LangGraph is built on LangChain and specifically focuses on cyclical graphs using a state-based approach. BrainyFlow uses action-based transitions between nodes within its graph structure.
* **Dependencies & Size:** LangGraph inherits LangChain's dependencies. BrainyFlow remains dependency-free.
* **Flexibility vs. Opinionation:** LangGraph is tied to the LangChain ecosystem and state management patterns. BrainyFlow offers more fundamental graph control.
* **Vendor Integrations:** Inherited from LangChain. BrainyFlow has none.
* **Learning Curve:** Requires understanding LangChain concepts plus LangGraph's state model. BrainyFlow focuses only on its core abstractions.

## BrainyFlow vs. CrewAI

* **Core Abstraction:** CrewAI provides higher-level abstractions like Agent, Task, and Crew, focusing on collaborative agent workflows. BrainyFlow provides the lower-level graph building blocks upon which such agent systems _can be built_.
* **Dependencies & Size:** CrewAI has dependencies related to its agent and tooling features. BrainyFlow is minimal.
* **Flexibility vs. Opinionation:** CrewAI is more opinionated towards specific multi-agent structures. BrainyFlow is more general-purpose.
* **Vendor Integrations:** CrewAI integrates with tools and LLMs, often via LangChain. BrainyFlow does not.
* **Learning Curve:** CrewAI's high-level concepts might be quicker for specific agent tasks. BrainyFlow requires building the agent logic from its core components.

## BrainyFlow vs. AutoGen

* **Core Abstraction:** AutoGen focuses on conversational agents (`ConversableAgent`) and multi-agent frameworks, often emphasizing automated chat orchestration. BrainyFlow focuses on the underlying execution graph.
* **Dependencies & Size:** AutoGen has a core set of dependencies, with optional ones for specific tools/models. BrainyFlow core has none.
* **Flexibility vs. Opinionation:** AutoGen is geared towards conversational agent patterns. BrainyFlow is a more general graph execution engine.
* **Vendor Integrations:** AutoGen offers integrations, particularly for LLMs. BrainyFlow avoids them.
* **Learning Curve:** AutoGen's conversational focus might be specific. BrainyFlow's graph is general but requires explicit construction.

## Relationship to PocketFlow

BrainyFlow originated as a fork of [PocketFlow](https://arxiv.org/abs/2504.03771), inheriting its core philosophy of minimalism and a graph-based abstraction. However, BrainyFlow has evolved with some key differences:

* **Core Abstraction & Batching**: [PocketFlow](https://arxiv.org/abs/2504.03771) included many specialized classes for async operations and batching (e.g., `AsyncNode`, `BatchNode`, `AsyncBatchNode`, `AsyncParallelBatchNode`, `AsyncFlow`, `BatchFlow`, `AsyncBatchFlow`, `AsyncParallelBatchFlow`). BrainyFlow simplifies this by removing all of these specialized classes from its core. Instead, it relies on standard `Node` lifecycle methods (which are inherently `async`-capable) combined with `Flow` (or `ParallelFlow`). Batch-like fan-out operations are achieved using multiple `trigger` calls within a single node's `post` method.
* **State Management (`Memory`)**: While both use a shared store, BrainyFlow's `Memory` object now has a more refined distinction between `global` and `local` stores. The `local` store is primarily populated via `forkingData` during `trigger` calls, crucial for managing branch-specific context. This eliminates the need for [PocketFlow](https://arxiv.org/abs/2504.03771)'s separate `Params` concept and simplifies the `Memory` model, removing the complexities that `Batch*` classes in [PocketFlow](https://arxiv.org/abs/2504.03771) tried to solve. BrainyFlow's `Memory` is created with enhanced proxy mechanisms for attribute access and isolation.
* **Focus:** BrainyFlow sharpens the focus on the fundamental `Node`, `Flow`, and `Memory` abstractions as the absolute core, reinforcing the idea that patterns like batching or parallelism are handled by how flows orchestrate standard nodes rather than requiring specialized node types.

Essentially, BrainyFlow refines [PocketFlow](https://arxiv.org/abs/2504.03771)'s minimalist approach, aiming for an even leaner core by handling execution patterns like batching and parallelism primarily at the `Flow` orchestration level.\
BrainyFlow also emphasizes a more consistent and refined API across its Python and TypeScript implementations, particularly for state management and flow execution.

On top of that, BrainyFlow has been designed to be more agentic-friendly, with a focus on building flows that can be used by both humans and AI assistants. Its code is more readable and maintainable, prioritizing developer experience over an arbitrarily defined amount of lines of code.

## Conclusion: When to Choose BrainyFlow?

BrainyFlow excels when you prioritize:

* **Minimalism and Control:** You want a lightweight core without unnecessary bloat or dependencies.
* **Flexibility:** You prefer to integrate your own utilities and avoid framework-specific wrappers.
* **Understanding the Core:** You value a simple, fundamental abstraction (the graph) that you can build upon.
* **Avoiding Vendor Lock-in:** You want the freedom to choose and switch external services easily.
* **Agentic Coding:** You plan to collaborate with AI assistants, leveraging a framework they can easily understand and manipulate.

If you need extensive pre-built integrations, higher-level abstractions for specific patterns (like multi-agent collaboration out-of-the-box), or prefer a more opinionated framework, other options might be a better fit initially. However, BrainyFlow provides the fundamental building blocks to implement _any_ of these patterns with maximum transparency and control.
