Demonstrates concurrent agent execution where multiple agents work simultaneously on the same input, and their results are aggregated. Perfect for multi-perspective analysis, competitive solutions, and independent task execution.
- Parallel Execution: Multiple agents working simultaneously
- Result Aggregation: Combining outputs from parallel agents
- Multi-Perspective Analysis: Different viewpoints on the same problem
- Performance Benefits: Faster processing through concurrency
- Synthesis Patterns: Merging parallel results into unified insights
parallel-pattern/
├── README.md # This guide
├── requirements.txt # Dependencies
├── .env.example # Environment template
├── main.py # Main application
└── docs/
└── parallel_flows.md # Parallel design patterns
# Install dependencies
pip install -r requirements.txt
# Configure environment
cp .env.example .env
# Edit .env with your LLM settings
# Run the example
python main.py Input
│
┌─────────────┼─────────────┐
▼ ▼ ▼
Agent 1 Agent 2 Agent 3
(Technical) (Business) (UX)
│ │ │
└─────────────┼─────────────┘
▼
Synthesis Agent
│
▼
Final Output
- Parallel Analysis: Technical, Business, UX, and Risk analysts work simultaneously
- Synthesis: Results are combined into comprehensive insights
- Final Report: Unified analysis with balanced perspectives
# Input: "Implement AI-powered customer service chatbot"
#
# Parallel Analysis:
# ┌─ TechnicalAnalyst: Architecture, implementation, scalability
# ├─ BusinessAnalyst: ROI, market impact, competitive advantage
# ├─ UXAnalyst: User experience, adoption, interface design
# └─ RiskAnalyst: Security, compliance, operational risks
#
# Synthesis:
# → Combines all perspectives
# → Identifies conflicts and synergies
# → Provides balanced recommendationsComplete multi-perspective analysis:
python main.py
# Select option 1See each analyst's perspective separately:
python main.py
# Select option 2Chat with the synthesis coordinator:
python main.py
# Select option 3- Faster processing through concurrency
- Multiple agents work simultaneously
- Reduced total execution time
- Multiple expert perspectives
- Reduced bias through diversity
- More thorough coverage
- Agents don't influence each other
- Pure, unbiased viewpoints
- Parallel problem-solving approaches
- Easy to add more parallel agents
- Distribute workload effectively
- Handle complex multi-faceted problems
@app.agent(
name="AnalystA",
description="Specialized perspective A",
system_prompt="Focus on aspect A of the problem..."
)
async def analyst_a():
pass
@app.agent(
name="AnalystB",
description="Specialized perspective B",
system_prompt="Focus on aspect B of the problem..."
)
async def analyst_b():
passfrom tframex import Flow, ParallelPattern
# Create flow with parallel pattern
analysis_flow = Flow(
flow_name="ParallelAnalysisFlow",
description="Multi-perspective parallel analysis"
)
# Add parallel pattern
analysis_flow.add_step(
ParallelPattern(
pattern_name="MultiAnalysis",
tasks=["AnalystA", "AnalystB", "AnalystC"]
)
)
# Optional: Add synthesis step
analysis_flow.add_step("SynthesisAgent")async with app.run_context() as rt:
input_message = Message(role="user", content="Analyze this...")
result = await rt.run_flow("ParallelAnalysisFlow", input_message)
print(result.current_message.content)- Multi-stakeholder perspectives
- Risk and opportunity assessment
- Investment decision analysis
- Strategic planning
- Competitive analysis
- Technology evaluation
- Market research
- Feasibility studies
- Design alternatives
- Creative brainstorming
- Multiple solution approaches
- Artistic perspectives
- Pro/con analysis
- Multiple expert opinions
- Consensus building
- Balanced evaluations
@app.agent(
name="WeightedSynthesizer",
system_prompt="""
Synthesize the parallel analyses, giving different weights based on:
- Technical feasibility: 30%
- Business value: 40%
- User experience: 20%
- Risk factors: 10%
"""
)
async def weighted_synthesizer():
pass# Multiple agents solving the same problem differently
parallel_flow.add_step(
ParallelPattern(
pattern_name="CompetitiveSolutions",
tasks=["ApproachA", "ApproachB", "ApproachC"]
)
)# Multiple rounds of parallel processing
flow.add_step(ParallelPattern(tasks=["Phase1A", "Phase1B"]))
flow.add_step(ParallelPattern(tasks=["Phase2A", "Phase2B"]))
flow.add_step("FinalSynthesis")- True parallel execution
- Faster than sequential processing
- Better resource utilization
- Monitor LLM API rate limits
- Balance parallel load
- Consider token usage across agents
- Group similar analysis types
- Use appropriate timeouts
- Implement result caching
@app.agent(
name="ConsensusBuilder",
system_prompt="""
Find common ground between the parallel analyses:
1. Identify areas of agreement
2. Highlight conflicting viewpoints
3. Propose compromise solutions
4. Build unified recommendations
"""
)@app.agent(
name="ConflictResolver",
system_prompt="""
When parallel analyses conflict:
1. Identify the source of disagreement
2. Evaluate the merits of each position
3. Propose resolution strategies
4. Make evidence-based recommendations
"""
)@app.agent(
name="BalancedReporter",
system_prompt="""
Create a balanced report that:
1. Presents all perspectives fairly
2. Highlights trade-offs and considerations
3. Provides clear recommendations
4. Acknowledges uncertainties and limitations
"""
)After mastering parallel patterns:
- Try Router Patterns: Router Pattern Example
- Explore Discussion Patterns: Discussion Pattern Example
- Advanced Applications: Content Creation Pipeline
- Build Custom Flows: Create your own parallel workflows
- Independence: Ensure parallel agents don't depend on each other
- Diversity: Use agents with genuinely different perspectives
- Clarity: Make synthesis clear and actionable
- Balance: Give appropriate weight to different viewpoints
- Start with 2-3 parallel agents
- Test agents individually first
- Plan synthesis strategy carefully
- Monitor performance and resource usage
- Avoid redundant parallel agents
- Don't neglect the synthesis step
- Consider API rate limits
- Plan for partial failures
This example is provided under the MIT License.