Flow in BRX
Flow in BRX refers to how data moves through a BRX workflow, from inputs to outputs, through various BRKs and their dependencies. Understanding flow is essential for designing effective and efficient BRX applications.Data Flow Basics
In BRX, data flows through a directed graph of BRKs, where each BRK:- Receives inputs from the user or from parent BRKs
- Processes those inputs using LLMs or other tools
- Produces outputs that can be used by dependent BRKs
- Returns final results to the user
Input Flow
Inputs to a BRK can come from several sources:User Inputs
The most direct source of inputs is from the user:Dependency Outputs
BRKs can also receive inputs from the outputs of their dependencies:Environment Variables
BRKs can access environment variables and configuration settings:Processing Flow
Once a BRK receives its inputs, it processes them according to its configuration:Prompt Processing
The most common processing flow involves sending a prompt to an LLM:- The BRK constructs a prompt using its template and input values
- The prompt is sent to the LLM
- The LLM generates a response
- The response is processed and structured as needed
Tool Calling
BRKs can also call external tools as part of their processing:- The BRK prepares data for the external tool
- The tool is called with the prepared data
- The tool returns a result
- The result is incorporated into the BRK’s output
Conditional Processing
BRKs can implement conditional processing flows:Output Flow
After processing, BRKs produce outputs that flow to their dependents:Direct Outputs
The simplest output flow is a direct output to the user:Dependency Chains
Outputs can flow through chains of dependencies:Parallel Flows
Outputs can flow to multiple dependent BRKs in parallel:Flow Control
BRX provides several mechanisms for controlling the flow of data:Sequential Execution
By default, BRKs are executed in a sequence determined by their dependencies:Parallel Execution
Independent BRKs can be executed in parallel:Conditional Execution
BRKs can implement conditional execution based on inputs or other factors:Flow Patterns
Several common flow patterns are used in BRX applications:Pipeline Pattern
The pipeline pattern is a linear sequence of BRKs, where each BRK processes the output of the previous one:- Extract data from text
- Clean and normalize the data
- Analyze the data
- Generate a report
Fan-Out Pattern
The fan-out pattern involves a single BRK that feeds multiple dependent BRKs:- Extract data from text
- Generate a summary
- Create visualizations
- Translate to different languages
Fan-In Pattern
The fan-in pattern involves multiple BRKs that feed into a single dependent BRK:- Collect data from multiple APIs
- Combine the data
- Generate a comprehensive report
Feedback Loop Pattern
The feedback loop pattern involves a BRK that feeds back into itself or an earlier BRK in the chain:- Generate an initial draft
- Evaluate the draft
- If not satisfactory, refine and repeat
Best Practices
Design for Clear Flow
- Design your BRK dependencies to create a clear and logical flow of data
- Avoid overly complex dependency graphs that are difficult to understand
- Document the expected inputs and outputs of each BRK
Optimize Flow Efficiency
- Minimize unnecessary data transfers between BRKs
- Use parallel execution where appropriate to improve performance
- Cache intermediate results to avoid redundant processing
Monitor and Debug Flow
- Log the flow of data through your BRK workflow
- Monitor execution times and resource usage
- Use debugging tools to identify bottlenecks and issues
Handle Flow Errors
- Implement error handling at each stage of the flow
- Provide fallback options for critical paths
- Design your flow to be resilient to failures
Example: Content Creation Workflow
Here’s an example of a content creation workflow that demonstrates various flow patterns:- Sequential flow (Topic → Outline)
- Conditional flow (Content Generation Router)
- Parallel paths (Blog vs. Script)
- Pipeline pattern (Blog → Edit → Format)