Skip to content

Commit 81542b1

Browse files
authored
Plan execute pattern on UI (#122)
* Implement plan and execute pattern in clean way * Plan and execute and workflow templates on UI * Start and end node config * Basic UI clean up
1 parent e0822e9 commit 81542b1

18 files changed

Lines changed: 1560 additions & 870 deletions
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
# Plan Execution Framework Guide
2+
3+
The Flo AI framework provides built-in support for plan-and-execute workflows, making it easy to create multi-step, coordinated agent workflows.
4+
5+
## Quick Start
6+
7+
### 1. Basic Software Development Workflow
8+
9+
```python
10+
import asyncio
11+
from flo_ai.llm import OpenAI
12+
from flo_ai.arium.memory import PlanAwareMemory
13+
from flo_ai.arium.llm_router import create_plan_execute_router
14+
from flo_ai.arium import AriumBuilder
15+
from flo_ai.models.plan_agents import create_software_development_agents
16+
17+
async def main():
18+
# Setup (3 lines!)
19+
llm = OpenAI(model='gpt-4o', api_key='your-key')
20+
memory = PlanAwareMemory()
21+
agents = create_software_development_agents(memory, llm)
22+
23+
# Create router
24+
router = create_plan_execute_router(
25+
planner_agent='planner',
26+
executor_agent='developer',
27+
reviewer_agent='reviewer',
28+
additional_agents={'tester': 'Tests implementations'},
29+
llm=llm,
30+
)
31+
32+
# Build workflow
33+
agent_list = list(agents.values())
34+
arium = (
35+
AriumBuilder()
36+
.with_memory(memory)
37+
.add_agents(agent_list)
38+
.start_with(agents['planner'])
39+
.add_edge(agents['planner'], agent_list, router)
40+
.add_edge(agents['developer'], agent_list, router)
41+
.add_edge(agents['tester'], agent_list, router)
42+
.add_edge(agents['reviewer'], agent_list, router)
43+
.end_with(agents['reviewer'])
44+
.build()
45+
)
46+
47+
# Execute
48+
result = await arium.run(['Create a user authentication API'])
49+
50+
asyncio.run(main())
51+
```
52+
53+
### 2. Custom Plan Workflow
54+
55+
```python
56+
from flo_ai.models.plan_agents import PlannerAgent, ExecutorAgent
57+
58+
# Create custom agents
59+
planner = PlannerAgent(memory, llm, name='planner')
60+
researcher = ExecutorAgent(memory, llm, name='researcher')
61+
analyst = ExecutorAgent(memory, llm, name='analyst')
62+
writer = ExecutorAgent(memory, llm, name='writer')
63+
64+
# Use the same pattern as above with your custom agents
65+
```
66+
67+
## Key Components
68+
69+
### Plan Agents
70+
71+
- **`PlannerAgent`**: Creates execution plans automatically
72+
- **`ExecutorAgent`**: Executes plan steps and tracks progress
73+
- **`create_software_development_agents()`**: Pre-configured dev team
74+
75+
### Plan Tools
76+
77+
- **`PlanTool`**: Parses and stores execution plans (from `flo_ai.tool.plan_tool`)
78+
- **`StepTool`**: Marks steps as completed (from `flo_ai.tool.plan_tool`)
79+
- **`PlanStatusTool`**: Checks plan progress (from `flo_ai.tool.plan_tool`)
80+
81+
### Memory
82+
83+
- **`PlanAwareMemory`**: Stores both conversations and execution plans
84+
85+
### Router
86+
87+
- **`create_plan_execute_router()`**: Intelligent routing for plan workflows
88+
89+
## How It Works
90+
91+
1. **Planning Phase**: Router sends task to planner agent
92+
2. **Plan Storage**: Planner creates and stores ExecutionPlan in memory
93+
3. **Execution Phase**: Router routes to appropriate agents based on plan steps
94+
4. **Progress Tracking**: Agents mark steps as completed using tools
95+
5. **Completion**: Router detects when all steps are done
96+
97+
## Plan Format
98+
99+
Plans are created in this standard format:
100+
101+
```
102+
EXECUTION PLAN: [Title]
103+
DESCRIPTION: [Description]
104+
105+
STEPS:
106+
1. step_1: [Task description] → agent_name
107+
2. step_2: [Task description] → agent_name (depends on: step_1)
108+
3. step_3: [Task description] → agent_name (depends on: step_1, step_2)
109+
```
110+
111+
## Benefits
112+
113+
- **Minimal Code**: Pre-built components handle all the complexity
114+
- **Automatic Plan Management**: Plans are created, stored, and tracked automatically
115+
- **Flexible**: Create custom agents for any domain
116+
- **Robust**: Built-in error handling and progress tracking
117+
- **Reusable**: Tools and agents work across different workflows
118+
119+
## Examples
120+
121+
See the `examples/` directory for:
122+
- `fixed_plan_execute_demo.py` - Basic software development workflow
123+
- `custom_plan_execute_demo.py` - Custom research workflow
Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
"""
2+
Custom Plan-Execute Demo - Creating Your Own Plan Workflows
3+
4+
This demo shows how to create custom plan-execute workflows
5+
using the framework's plan execution components.
6+
"""
7+
8+
import asyncio
9+
import os
10+
from flo_ai.llm import OpenAI
11+
from flo_ai.arium.memory import PlanAwareMemory
12+
from flo_ai.arium.llm_router import create_plan_execute_router
13+
from flo_ai.arium import AriumBuilder
14+
from flo_ai.models.plan_agents import PlannerAgent, ExecutorAgent
15+
16+
17+
async def main():
18+
"""Custom plan-execute workflow example"""
19+
print('🎯 Custom Plan-Execute Demo')
20+
print('=' * 35)
21+
22+
# Check API key
23+
api_key = os.getenv('OPENAI_API_KEY')
24+
if not api_key:
25+
print('❌ OPENAI_API_KEY environment variable not set')
26+
return
27+
28+
# Setup
29+
llm = OpenAI(model='gpt-4o', api_key=api_key)
30+
memory = PlanAwareMemory()
31+
32+
# Create custom agents for research workflow
33+
planner = PlannerAgent(
34+
memory=memory,
35+
llm=llm,
36+
name='planner',
37+
system_prompt="""You are a research project planner. Create plans for research tasks.
38+
39+
EXECUTION PLAN: [Title]
40+
DESCRIPTION: [Description]
41+
42+
STEPS:
43+
1. step_1: [Research task] → researcher
44+
2. step_2: [Analysis task] → analyst (depends on: step_1)
45+
3. step_3: [Writing task] → writer (depends on: step_2)
46+
47+
Use agents: researcher, analyst, writer
48+
IMPORTANT: After generating the plan, use store_execution_plan to save it.""",
49+
)
50+
51+
researcher = ExecutorAgent(
52+
memory=memory,
53+
llm=llm,
54+
name='researcher',
55+
system_prompt="""You are a researcher who gathers information and data.
56+
Check plan status first, then execute research steps thoroughly.""",
57+
)
58+
59+
analyst = ExecutorAgent(
60+
memory=memory,
61+
llm=llm,
62+
name='analyst',
63+
system_prompt="""You are an analyst who processes and analyzes research data.
64+
Check plan status first, then execute analysis steps thoroughly.""",
65+
)
66+
67+
writer = ExecutorAgent(
68+
memory=memory,
69+
llm=llm,
70+
name='writer',
71+
system_prompt="""You are a writer who creates reports and summaries.
72+
Check plan status first, then execute writing steps thoroughly.""",
73+
)
74+
75+
agents = [planner, researcher, analyst, writer]
76+
77+
# Create router
78+
router = create_plan_execute_router(
79+
planner_agent='planner',
80+
executor_agent='researcher',
81+
reviewer_agent='writer',
82+
additional_agents={'analyst': 'Analyzes research data and findings'},
83+
llm=llm,
84+
)
85+
86+
# Build workflow
87+
arium = (
88+
AriumBuilder()
89+
.with_memory(memory)
90+
.add_agents(agents)
91+
.start_with(planner)
92+
.add_edge(planner, agents, router)
93+
.add_edge(researcher, agents, router)
94+
.add_edge(analyst, agents, router)
95+
.add_edge(writer, agents, router)
96+
.end_with(writer)
97+
.build()
98+
)
99+
100+
# Execute task
101+
task = 'Research the impact of AI on software development productivity'
102+
print(f'📋 Task: {task}')
103+
print('🔄 Executing custom research workflow...\n')
104+
105+
try:
106+
result = await arium.run([task])
107+
108+
print('\n' + '=' * 40)
109+
print('🎉 CUSTOM WORKFLOW COMPLETED!')
110+
print('=' * 40)
111+
112+
if result:
113+
final_result = result[-1] if isinstance(result, list) else result
114+
print(f'\n📄 Final Result:\n{final_result}')
115+
116+
# Show plan status
117+
current_plan = memory.get_current_plan()
118+
if current_plan:
119+
print(f'\n📊 Plan: {current_plan.title}')
120+
print(f'✅ Completed: {current_plan.is_completed()}')
121+
122+
except Exception as e:
123+
print(f'❌ Error: {e}')
124+
125+
126+
if __name__ == '__main__':
127+
asyncio.run(main())

0 commit comments

Comments
 (0)