mirror of
https://github.com/MervinPraison/PraisonAI.git
synced 2026-11-10 17:29:39 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
30f1a440b6 |
No files matched your search
@@ -40,7 +40,17 @@ PraisonAI is a production-ready Multi-AI Agents framework with self-reflection,
|
||||
| 🔄 Self Reflection AI Agents | [Example](examples/python/concepts/self-reflection-details.py) | [📖](https://docs.praison.ai/features/selfreflection) |
|
||||
| 🧠 Reasoning AI Agents | [Example](examples/python/concepts/reasoning-extraction.py) | [📖](https://docs.praison.ai/features/reasoning) |
|
||||
| 👁️ Multi Modal AI Agents | [Example](examples/python/general/multimodal.py) | [📖](https://docs.praison.ai/features/multimodal) |
|
||||
| 🎭 AI Agent Workflow (Context Passing, Per-Step Agents) | [Example](examples/python/stateful/workflow-state-example.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| **🔄 Workflows** | | |
|
||||
| ↳ Simple Workflow | [Example](examples/python/workflows/simple_workflow.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| ↳ Workflow with Agents | [Example](examples/python/workflows/workflow_with_agents.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| ↳ Agentic Routing (`route()`) | [Example](examples/python/workflows/workflow_routing.py) | [📖](https://docs.praison.ai/features/routing) |
|
||||
| ↳ Parallel Execution (`parallel()`) | [Example](examples/python/workflows/workflow_parallel.py) | [📖](https://docs.praison.ai/features/parallelisation) |
|
||||
| ↳ Loop over List/CSV (`loop()`) | [Example](examples/python/workflows/workflow_loop_csv.py) | [📖](https://docs.praison.ai/features/repetitive) |
|
||||
| ↳ Evaluator-Optimizer (`repeat()`) | [Example](examples/python/workflows/workflow_repeat.py) | [📖](https://docs.praison.ai/features/evaluator-optimiser) |
|
||||
| ↳ Conditional Steps | [Example](examples/python/workflows/workflow_conditional.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| ↳ Workflow Branching | [Example](examples/python/workflows/workflow_branching.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| ↳ Workflow Early Stop | [Example](examples/python/workflows/workflow_early_stop.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| ↳ Workflow Checkpoints | [Example](examples/python/workflows/workflow_checkpoints.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 📚 Add Custom Knowledge | [Example](examples/python/concepts/knowledge-agents.py) | [📖](https://docs.praison.ai/features/knowledge) |
|
||||
| 🧠 Memory (Short & Long Term) | [Example](examples/python/general/memory_example.py) | [📖](https://docs.praison.ai/concepts/memory) |
|
||||
| 📄 Chat with PDF Agents | [Example](examples/python/concepts/chat-with-pdf.py) | [📖](https://docs.praison.ai/features/chat-with-pdf) |
|
||||
@@ -103,20 +113,6 @@ PraisonAI is a production-ready Multi-AI Agents framework with self-reflection,
|
||||
| @ @Mentions in Prompts | [Example](#mentions-in-prompts) | [📖](https://docs.praison.ai/cli/mentions) |
|
||||
| 💾 Auto-Save Sessions | [Example](#session-management-python) | [📖](https://docs.praison.ai/cli/session) |
|
||||
| 📜 History in Context | [Example](#session-management-python) | [📖](https://docs.praison.ai/cli/session) |
|
||||
| ⏸️ Workflow Checkpoints | [Example](examples/python/workflows/workflow_checkpoints.py) | [📖](https://docs.praison.ai/cli/session) |
|
||||
| 🔀 Workflow Branching | [Example](examples/python/workflows/workflow_branching.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 🔁 Workflow Loops | [Example](examples/python/workflows/workflow_loops.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 📞 Task Callbacks | [Example](examples/python/workflows/task_callbacks.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 🛑 Workflow Early Stop | [Example](examples/python/workflows/workflow_early_stop.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| ⚡ Simple Workflow | [Example](examples/python/workflows/simple_workflow.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 🤖 Workflow with Agents | [Example](examples/python/workflows/workflow_with_agents.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 🔄 Conditional Steps | [Example](examples/python/workflows/workflow_conditional.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 🎭 Mixed Steps | [Example](examples/python/workflows/workflow_mixed_steps.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 🔀 Agentic Routing | [Example](examples/python/workflows/workflow_routing.py) | [📖](https://docs.praison.ai/features/workflow-routing) |
|
||||
| ⚡ Parallel Execution | [Example](examples/python/workflows/workflow_parallel.py) | [📖](https://docs.praison.ai/features/workflow-parallel) |
|
||||
| 🔁 Loop over List | [Example](examples/python/workflows/workflow_loop_list.py) | [📖](https://docs.praison.ai/features/workflow-loop) |
|
||||
| 📄 Loop over CSV | [Example](examples/python/workflows/workflow_loop_csv.py) | [📖](https://docs.praison.ai/features/workflow-loop) |
|
||||
| 🔄 Evaluator-Optimizer | [Example](examples/python/workflows/workflow_repeat.py) | [📖](https://docs.praison.ai/features/workflow-repeat) |
|
||||
|
||||
## Supported Providers
|
||||
|
||||
@@ -467,8 +463,8 @@ result = asyncio.run(manager.aexecute("deploy", default_llm="gpt-4o-mini"))
|
||||
|----------|-------------|
|
||||
| Simple function pipelines | `Workflow` class ⭐ |
|
||||
| Agent-only pipelines | `Workflow` class |
|
||||
| CSV batch processing | `process="workflow"` |
|
||||
| Complex task routing | `process="workflow"` |
|
||||
| CSV batch processing | `Workflow` + `loop()` |
|
||||
| Complex task routing | `Workflow` + `route()` |
|
||||
| Markdown templates | `WorkflowManager` |
|
||||
| Early stop / conditional | `Workflow` class |
|
||||
|
||||
@@ -580,6 +576,162 @@ workflow = Workflow(steps=[
|
||||
])
|
||||
```
|
||||
|
||||
### Workflow with Agents
|
||||
|
||||
Use Agent objects directly as workflow steps:
|
||||
|
||||
```python
|
||||
from praisonaiagents import Agent, Workflow
|
||||
from praisonaiagents.workflows import route, parallel
|
||||
|
||||
# 1. SEQUENTIAL AGENTS
|
||||
researcher = Agent(name="Researcher", role="Research expert", tools=[tavily_search])
|
||||
writer = Agent(name="Writer", role="Content writer")
|
||||
editor = Agent(name="Editor", role="Editor")
|
||||
|
||||
workflow = Workflow(steps=[researcher, writer, editor])
|
||||
result = workflow.start("Research and write about AI")
|
||||
|
||||
# 2. PARALLEL AGENTS
|
||||
workflow = Workflow(steps=[
|
||||
parallel([researcher1, researcher2, researcher3]),
|
||||
aggregator_agent
|
||||
])
|
||||
|
||||
# 3. ROUTE TO AGENTS
|
||||
workflow = Workflow(steps=[
|
||||
classifier_function,
|
||||
route({
|
||||
"technical": [tech_agent],
|
||||
"creative": [creative_agent],
|
||||
"default": [general_agent]
|
||||
})
|
||||
])
|
||||
|
||||
# 4. WITH PLANNING & REASONING
|
||||
workflow = Workflow(
|
||||
steps=[researcher, writer, editor],
|
||||
planning=True, # Create execution plan
|
||||
planning_llm="gpt-4o", # LLM for planning
|
||||
reasoning=True, # Chain-of-thought reasoning
|
||||
verbose=True
|
||||
)
|
||||
|
||||
# 5. TOOLS PER STEP
|
||||
workflow = Workflow(steps=[
|
||||
WorkflowStep(
|
||||
name="research",
|
||||
action="Research {{topic}}",
|
||||
tools=[tavily_search, web_scraper],
|
||||
agent_config={"name": "Researcher", "role": "Expert"}
|
||||
)
|
||||
])
|
||||
|
||||
# 6. OUTPUT TO FILE / IMAGES / PYDANTIC
|
||||
from pydantic import BaseModel
|
||||
|
||||
class Report(BaseModel):
|
||||
title: str
|
||||
content: str
|
||||
|
||||
workflow = Workflow(steps=[
|
||||
WorkflowStep(name="analyze", action="Analyze image", images=["image.jpg"]),
|
||||
WorkflowStep(name="report", action="Generate report", output_pydantic=Report),
|
||||
WorkflowStep(name="save", action="Save results", output_file="output/report.txt")
|
||||
])
|
||||
|
||||
# 7. ASYNC EXECUTION
|
||||
import asyncio
|
||||
|
||||
async def main():
|
||||
result = await workflow.astart("input")
|
||||
print(result)
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
# 8. STATUS TRACKING
|
||||
workflow.status # "not_started" | "running" | "completed"
|
||||
workflow.step_statuses # {"step1": "completed", "step2": "skipped"}
|
||||
|
||||
# 9. MEMORY CONFIG
|
||||
workflow = Workflow(
|
||||
steps=[researcher, writer],
|
||||
memory_config={"provider": "chroma", "persist": True, "collection": "my_workflow"}
|
||||
)
|
||||
result1 = workflow.start("Research AI")
|
||||
result2 = workflow.start("Continue the research") # Remembers first run
|
||||
```
|
||||
|
||||
### YAML Workflow Template
|
||||
|
||||
```yaml
|
||||
# .praison/workflows/research.yaml
|
||||
name: Research Workflow
|
||||
description: Research and write content with all patterns
|
||||
|
||||
agents:
|
||||
researcher:
|
||||
role: Research Expert
|
||||
goal: Find accurate information
|
||||
tools: [tavily_search, web_scraper]
|
||||
writer:
|
||||
role: Content Writer
|
||||
goal: Write engaging content
|
||||
editor:
|
||||
role: Editor
|
||||
goal: Polish content
|
||||
|
||||
steps:
|
||||
# Sequential
|
||||
- agent: researcher
|
||||
action: Research {{topic}}
|
||||
output_variable: research_data
|
||||
|
||||
# Routing
|
||||
- name: classifier
|
||||
action: Classify content type
|
||||
route:
|
||||
technical: [tech_handler]
|
||||
creative: [creative_handler]
|
||||
default: [general_handler]
|
||||
|
||||
# Parallel
|
||||
- name: parallel_research
|
||||
parallel:
|
||||
- agent: researcher
|
||||
action: Research market
|
||||
- agent: researcher
|
||||
action: Research competitors
|
||||
|
||||
# Loop
|
||||
- agent: writer
|
||||
action: Write about {{item}}
|
||||
loop_over: topics
|
||||
loop_var: item
|
||||
|
||||
# Repeat (evaluator-optimizer)
|
||||
- agent: editor
|
||||
action: Review and improve
|
||||
repeat:
|
||||
until: "quality > 8"
|
||||
max_iterations: 3
|
||||
|
||||
# Output to file
|
||||
- agent: writer
|
||||
action: Write final report
|
||||
output_file: output/{{topic}}_report.md
|
||||
|
||||
variables:
|
||||
topic: AI trends
|
||||
topics: [ML, NLP, Vision]
|
||||
|
||||
planning: true
|
||||
planning_llm: gpt-4o
|
||||
memory_config:
|
||||
provider: chroma
|
||||
persist: true
|
||||
```
|
||||
|
||||
### 9. Hooks
|
||||
|
||||
Configure in `.praison/hooks.json`:
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ RUN mkdir -p /root/.praison
|
||||
# Install Python packages (using latest versions)
|
||||
RUN pip install --no-cache-dir \
|
||||
flask \
|
||||
"praisonai>=2.3.23" \
|
||||
"praisonai>=2.3.24" \
|
||||
"praisonai[api]" \
|
||||
gunicorn \
|
||||
markdown
|
||||
|
||||
@@ -16,7 +16,7 @@ RUN mkdir -p /root/.praison
|
||||
# Install Python packages (using latest versions)
|
||||
RUN pip install --no-cache-dir \
|
||||
praisonai_tools \
|
||||
"praisonai>=2.3.23" \
|
||||
"praisonai>=2.3.24" \
|
||||
"praisonai[chat]" \
|
||||
"embedchain[github,youtube]"
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ RUN mkdir -p /root/.praison
|
||||
# Install Python packages (using latest versions)
|
||||
RUN pip install --no-cache-dir \
|
||||
praisonai_tools \
|
||||
"praisonai>=2.3.23" \
|
||||
"praisonai>=2.3.24" \
|
||||
"praisonai[ui]" \
|
||||
"praisonai[chat]" \
|
||||
"praisonai[realtime]" \
|
||||
|
||||
@@ -16,7 +16,7 @@ RUN mkdir -p /root/.praison
|
||||
# Install Python packages (using latest versions)
|
||||
RUN pip install --no-cache-dir \
|
||||
praisonai_tools \
|
||||
"praisonai>=2.3.23" \
|
||||
"praisonai>=2.3.24" \
|
||||
"praisonai[ui]" \
|
||||
"praisonai[crewai]"
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "praisonaiagents"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
description = "Praison AI agents for completing complex tasks with Self Reflection Agents"
|
||||
requires-python = ">=3.10"
|
||||
authors = [
|
||||
|
||||
@@ -1381,6 +1381,106 @@ class TestMigratedFeatures:
|
||||
assert d["rerun"] == False
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Test: Planning and Reasoning Modes
|
||||
# =============================================================================
|
||||
|
||||
class TestPlanningAndReasoning:
|
||||
"""Test planning and reasoning modes in workflows."""
|
||||
|
||||
def test_workflow_planning_parameter_exists(self):
|
||||
"""Test that Workflow accepts planning parameter."""
|
||||
workflow = Workflow(
|
||||
steps=[lambda ctx: StepResult(output="test")],
|
||||
planning=True,
|
||||
planning_llm="gpt-4o"
|
||||
)
|
||||
assert workflow.planning == True
|
||||
assert workflow.planning_llm == "gpt-4o"
|
||||
|
||||
def test_workflow_reasoning_parameter_exists(self):
|
||||
"""Test that Workflow accepts reasoning parameter."""
|
||||
workflow = Workflow(
|
||||
steps=[lambda ctx: StepResult(output="test")],
|
||||
reasoning=True
|
||||
)
|
||||
assert workflow.reasoning == True
|
||||
|
||||
def test_workflow_memory_config_parameter_exists(self):
|
||||
"""Test that Workflow accepts memory_config parameter."""
|
||||
workflow = Workflow(
|
||||
steps=[lambda ctx: StepResult(output="test")],
|
||||
memory_config={"provider": "rag", "persist": True}
|
||||
)
|
||||
assert workflow.memory_config == {"provider": "rag", "persist": True}
|
||||
|
||||
def test_workflow_verbose_parameter_exists(self):
|
||||
"""Test that Workflow accepts verbose parameter."""
|
||||
workflow = Workflow(
|
||||
steps=[lambda ctx: StepResult(output="test")],
|
||||
verbose=True
|
||||
)
|
||||
assert workflow.verbose == True
|
||||
|
||||
|
||||
class TestToolsPerStep:
|
||||
"""Test tools per step functionality."""
|
||||
|
||||
def test_step_with_tools_list(self):
|
||||
"""Test WorkflowStep with tools list."""
|
||||
def my_tool():
|
||||
return "tool result"
|
||||
|
||||
step = WorkflowStep(
|
||||
name="test",
|
||||
action="Do something",
|
||||
tools=[my_tool]
|
||||
)
|
||||
|
||||
assert step.tools == [my_tool]
|
||||
|
||||
def test_step_with_agent_config_tools(self):
|
||||
"""Test WorkflowStep with tools in agent_config."""
|
||||
def my_tool():
|
||||
return "tool result"
|
||||
|
||||
step = WorkflowStep(
|
||||
name="test",
|
||||
action="Do something",
|
||||
agent_config={
|
||||
"name": "TestAgent",
|
||||
"role": "Tester",
|
||||
"tools": [my_tool]
|
||||
}
|
||||
)
|
||||
|
||||
assert step.agent_config["tools"] == [my_tool]
|
||||
|
||||
def test_agent_with_tools_in_workflow(self):
|
||||
"""Test Agent with tools is properly handled in workflow."""
|
||||
class MockAgent:
|
||||
def __init__(self, name, tools=None):
|
||||
self.name = name
|
||||
self.tools = tools or []
|
||||
|
||||
def chat(self, message):
|
||||
return f"Response with {len(self.tools)} tools"
|
||||
|
||||
def mock_tool():
|
||||
return "tool result"
|
||||
|
||||
agent = MockAgent("TestAgent", tools=[mock_tool])
|
||||
workflow = Workflow(steps=[agent])
|
||||
|
||||
# Normalize and verify tools are preserved
|
||||
normalized = workflow._normalize_single_step(agent, 0)
|
||||
assert normalized.tools == [mock_tool]
|
||||
|
||||
# Execute and verify
|
||||
result = workflow.start("test")
|
||||
assert "1 tools" in result["output"]
|
||||
|
||||
|
||||
# =============================================================================
|
||||
# Test: WorkflowManager with Patterns in MD Files
|
||||
# =============================================================================
|
||||
|
||||
Generated
+1
-1
@@ -2422,7 +2422,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "praisonaiagents"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "aiohttp" },
|
||||
|
||||
+169
-17
@@ -40,7 +40,17 @@ PraisonAI is a production-ready Multi-AI Agents framework with self-reflection,
|
||||
| 🔄 Self Reflection AI Agents | [Example](examples/python/concepts/self-reflection-details.py) | [📖](https://docs.praison.ai/features/selfreflection) |
|
||||
| 🧠 Reasoning AI Agents | [Example](examples/python/concepts/reasoning-extraction.py) | [📖](https://docs.praison.ai/features/reasoning) |
|
||||
| 👁️ Multi Modal AI Agents | [Example](examples/python/general/multimodal.py) | [📖](https://docs.praison.ai/features/multimodal) |
|
||||
| 🎭 AI Agent Workflow (Context Passing, Per-Step Agents) | [Example](examples/python/stateful/workflow-state-example.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| **🔄 Workflows** | | |
|
||||
| ↳ Simple Workflow | [Example](examples/python/workflows/simple_workflow.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| ↳ Workflow with Agents | [Example](examples/python/workflows/workflow_with_agents.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| ↳ Agentic Routing (`route()`) | [Example](examples/python/workflows/workflow_routing.py) | [📖](https://docs.praison.ai/features/routing) |
|
||||
| ↳ Parallel Execution (`parallel()`) | [Example](examples/python/workflows/workflow_parallel.py) | [📖](https://docs.praison.ai/features/parallelisation) |
|
||||
| ↳ Loop over List/CSV (`loop()`) | [Example](examples/python/workflows/workflow_loop_csv.py) | [📖](https://docs.praison.ai/features/repetitive) |
|
||||
| ↳ Evaluator-Optimizer (`repeat()`) | [Example](examples/python/workflows/workflow_repeat.py) | [📖](https://docs.praison.ai/features/evaluator-optimiser) |
|
||||
| ↳ Conditional Steps | [Example](examples/python/workflows/workflow_conditional.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| ↳ Workflow Branching | [Example](examples/python/workflows/workflow_branching.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| ↳ Workflow Early Stop | [Example](examples/python/workflows/workflow_early_stop.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| ↳ Workflow Checkpoints | [Example](examples/python/workflows/workflow_checkpoints.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 📚 Add Custom Knowledge | [Example](examples/python/concepts/knowledge-agents.py) | [📖](https://docs.praison.ai/features/knowledge) |
|
||||
| 🧠 Memory (Short & Long Term) | [Example](examples/python/general/memory_example.py) | [📖](https://docs.praison.ai/concepts/memory) |
|
||||
| 📄 Chat with PDF Agents | [Example](examples/python/concepts/chat-with-pdf.py) | [📖](https://docs.praison.ai/features/chat-with-pdf) |
|
||||
@@ -103,20 +113,6 @@ PraisonAI is a production-ready Multi-AI Agents framework with self-reflection,
|
||||
| @ @Mentions in Prompts | [Example](#mentions-in-prompts) | [📖](https://docs.praison.ai/cli/mentions) |
|
||||
| 💾 Auto-Save Sessions | [Example](#session-management-python) | [📖](https://docs.praison.ai/cli/session) |
|
||||
| 📜 History in Context | [Example](#session-management-python) | [📖](https://docs.praison.ai/cli/session) |
|
||||
| ⏸️ Workflow Checkpoints | [Example](examples/python/workflows/workflow_checkpoints.py) | [📖](https://docs.praison.ai/cli/session) |
|
||||
| 🔀 Workflow Branching | [Example](examples/python/workflows/workflow_branching.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 🔁 Workflow Loops | [Example](examples/python/workflows/workflow_loops.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 📞 Task Callbacks | [Example](examples/python/workflows/task_callbacks.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 🛑 Workflow Early Stop | [Example](examples/python/workflows/workflow_early_stop.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| ⚡ Simple Workflow | [Example](examples/python/workflows/simple_workflow.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 🤖 Workflow with Agents | [Example](examples/python/workflows/workflow_with_agents.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 🔄 Conditional Steps | [Example](examples/python/workflows/workflow_conditional.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 🎭 Mixed Steps | [Example](examples/python/workflows/workflow_mixed_steps.py) | [📖](https://docs.praison.ai/features/workflows) |
|
||||
| 🔀 Agentic Routing | [Example](examples/python/workflows/workflow_routing.py) | [📖](https://docs.praison.ai/features/workflow-routing) |
|
||||
| ⚡ Parallel Execution | [Example](examples/python/workflows/workflow_parallel.py) | [📖](https://docs.praison.ai/features/workflow-parallel) |
|
||||
| 🔁 Loop over List | [Example](examples/python/workflows/workflow_loop_list.py) | [📖](https://docs.praison.ai/features/workflow-loop) |
|
||||
| 📄 Loop over CSV | [Example](examples/python/workflows/workflow_loop_csv.py) | [📖](https://docs.praison.ai/features/workflow-loop) |
|
||||
| 🔄 Evaluator-Optimizer | [Example](examples/python/workflows/workflow_repeat.py) | [📖](https://docs.praison.ai/features/workflow-repeat) |
|
||||
|
||||
## Supported Providers
|
||||
|
||||
@@ -467,8 +463,8 @@ result = asyncio.run(manager.aexecute("deploy", default_llm="gpt-4o-mini"))
|
||||
|----------|-------------|
|
||||
| Simple function pipelines | `Workflow` class ⭐ |
|
||||
| Agent-only pipelines | `Workflow` class |
|
||||
| CSV batch processing | `process="workflow"` |
|
||||
| Complex task routing | `process="workflow"` |
|
||||
| CSV batch processing | `Workflow` + `loop()` |
|
||||
| Complex task routing | `Workflow` + `route()` |
|
||||
| Markdown templates | `WorkflowManager` |
|
||||
| Early stop / conditional | `Workflow` class |
|
||||
|
||||
@@ -580,6 +576,162 @@ workflow = Workflow(steps=[
|
||||
])
|
||||
```
|
||||
|
||||
### Workflow with Agents
|
||||
|
||||
Use Agent objects directly as workflow steps:
|
||||
|
||||
```python
|
||||
from praisonaiagents import Agent, Workflow
|
||||
from praisonaiagents.workflows import route, parallel
|
||||
|
||||
# 1. SEQUENTIAL AGENTS
|
||||
researcher = Agent(name="Researcher", role="Research expert", tools=[tavily_search])
|
||||
writer = Agent(name="Writer", role="Content writer")
|
||||
editor = Agent(name="Editor", role="Editor")
|
||||
|
||||
workflow = Workflow(steps=[researcher, writer, editor])
|
||||
result = workflow.start("Research and write about AI")
|
||||
|
||||
# 2. PARALLEL AGENTS
|
||||
workflow = Workflow(steps=[
|
||||
parallel([researcher1, researcher2, researcher3]),
|
||||
aggregator_agent
|
||||
])
|
||||
|
||||
# 3. ROUTE TO AGENTS
|
||||
workflow = Workflow(steps=[
|
||||
classifier_function,
|
||||
route({
|
||||
"technical": [tech_agent],
|
||||
"creative": [creative_agent],
|
||||
"default": [general_agent]
|
||||
})
|
||||
])
|
||||
|
||||
# 4. WITH PLANNING & REASONING
|
||||
workflow = Workflow(
|
||||
steps=[researcher, writer, editor],
|
||||
planning=True, # Create execution plan
|
||||
planning_llm="gpt-4o", # LLM for planning
|
||||
reasoning=True, # Chain-of-thought reasoning
|
||||
verbose=True
|
||||
)
|
||||
|
||||
# 5. TOOLS PER STEP
|
||||
workflow = Workflow(steps=[
|
||||
WorkflowStep(
|
||||
name="research",
|
||||
action="Research {{topic}}",
|
||||
tools=[tavily_search, web_scraper],
|
||||
agent_config={"name": "Researcher", "role": "Expert"}
|
||||
)
|
||||
])
|
||||
|
||||
# 6. OUTPUT TO FILE / IMAGES / PYDANTIC
|
||||
from pydantic import BaseModel
|
||||
|
||||
class Report(BaseModel):
|
||||
title: str
|
||||
content: str
|
||||
|
||||
workflow = Workflow(steps=[
|
||||
WorkflowStep(name="analyze", action="Analyze image", images=["image.jpg"]),
|
||||
WorkflowStep(name="report", action="Generate report", output_pydantic=Report),
|
||||
WorkflowStep(name="save", action="Save results", output_file="output/report.txt")
|
||||
])
|
||||
|
||||
# 7. ASYNC EXECUTION
|
||||
import asyncio
|
||||
|
||||
async def main():
|
||||
result = await workflow.astart("input")
|
||||
print(result)
|
||||
|
||||
asyncio.run(main())
|
||||
|
||||
# 8. STATUS TRACKING
|
||||
workflow.status # "not_started" | "running" | "completed"
|
||||
workflow.step_statuses # {"step1": "completed", "step2": "skipped"}
|
||||
|
||||
# 9. MEMORY CONFIG
|
||||
workflow = Workflow(
|
||||
steps=[researcher, writer],
|
||||
memory_config={"provider": "chroma", "persist": True, "collection": "my_workflow"}
|
||||
)
|
||||
result1 = workflow.start("Research AI")
|
||||
result2 = workflow.start("Continue the research") # Remembers first run
|
||||
```
|
||||
|
||||
### YAML Workflow Template
|
||||
|
||||
```yaml
|
||||
# .praison/workflows/research.yaml
|
||||
name: Research Workflow
|
||||
description: Research and write content with all patterns
|
||||
|
||||
agents:
|
||||
researcher:
|
||||
role: Research Expert
|
||||
goal: Find accurate information
|
||||
tools: [tavily_search, web_scraper]
|
||||
writer:
|
||||
role: Content Writer
|
||||
goal: Write engaging content
|
||||
editor:
|
||||
role: Editor
|
||||
goal: Polish content
|
||||
|
||||
steps:
|
||||
# Sequential
|
||||
- agent: researcher
|
||||
action: Research {{topic}}
|
||||
output_variable: research_data
|
||||
|
||||
# Routing
|
||||
- name: classifier
|
||||
action: Classify content type
|
||||
route:
|
||||
technical: [tech_handler]
|
||||
creative: [creative_handler]
|
||||
default: [general_handler]
|
||||
|
||||
# Parallel
|
||||
- name: parallel_research
|
||||
parallel:
|
||||
- agent: researcher
|
||||
action: Research market
|
||||
- agent: researcher
|
||||
action: Research competitors
|
||||
|
||||
# Loop
|
||||
- agent: writer
|
||||
action: Write about {{item}}
|
||||
loop_over: topics
|
||||
loop_var: item
|
||||
|
||||
# Repeat (evaluator-optimizer)
|
||||
- agent: editor
|
||||
action: Review and improve
|
||||
repeat:
|
||||
until: "quality > 8"
|
||||
max_iterations: 3
|
||||
|
||||
# Output to file
|
||||
- agent: writer
|
||||
action: Write final report
|
||||
output_file: output/{{topic}}_report.md
|
||||
|
||||
variables:
|
||||
topic: AI trends
|
||||
topics: [ML, NLP, Vision]
|
||||
|
||||
planning: true
|
||||
planning_llm: gpt-4o
|
||||
memory_config:
|
||||
provider: chroma
|
||||
persist: true
|
||||
```
|
||||
|
||||
### 9. Hooks
|
||||
|
||||
Configure in `.praison/hooks.json`:
|
||||
|
||||
@@ -3,8 +3,8 @@ class Praisonai < Formula
|
||||
|
||||
desc "AI tools for various AI applications"
|
||||
homepage "https://github.com/MervinPraison/PraisonAI"
|
||||
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/v2.3.23.tar.gz"
|
||||
sha256 `curl -sL https://github.com/MervinPraison/PraisonAI/archive/refs/tags/v2.3.23.tar.gz | shasum -a 256`.split.first
|
||||
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/v2.3.24.tar.gz"
|
||||
sha256 `curl -sL https://github.com/MervinPraison/PraisonAI/archive/refs/tags/v2.3.24.tar.gz | shasum -a 256`.split.first
|
||||
license "MIT"
|
||||
|
||||
depends_on "[email protected]"
|
||||
|
||||
@@ -57,7 +57,7 @@ class CloudDeployer:
|
||||
file.write("FROM python:3.11-slim\n")
|
||||
file.write("WORKDIR /app\n")
|
||||
file.write("COPY . .\n")
|
||||
file.write("RUN pip install flask praisonai==2.3.23 gunicorn markdown\n")
|
||||
file.write("RUN pip install flask praisonai==2.3.24 gunicorn markdown\n")
|
||||
file.write("EXPOSE 8080\n")
|
||||
file.write('CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"]\n')
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
__version__ = "2.3.23"
|
||||
__version__ = "2.3.24"
|
||||
@@ -12,7 +12,7 @@ dependencies = [
|
||||
"rich>=13.7",
|
||||
"markdown>=3.5",
|
||||
"pyparsing>=3.0.0",
|
||||
"praisonaiagents>=0.1.1",
|
||||
"praisonaiagents>=0.1.2",
|
||||
"python-dotenv>=0.19.0",
|
||||
"instructor>=1.3.3",
|
||||
"PyYAML>=6.0",
|
||||
|
||||
Generated
+4
-4
@@ -4197,7 +4197,7 @@ requires-dist = [
|
||||
{ name = "praisonai-tools", marker = "extra == 'autogen'", specifier = ">=0.0.22" },
|
||||
{ name = "praisonai-tools", marker = "extra == 'autogen-v4'", specifier = ">=0.0.22" },
|
||||
{ name = "praisonai-tools", marker = "extra == 'crewai'", specifier = ">=0.0.22" },
|
||||
{ name = "praisonaiagents", specifier = ">=0.1.1" },
|
||||
{ name = "praisonaiagents", specifier = ">=0.1.2" },
|
||||
{ name = "pyautogen", marker = "extra == 'autogen'", specifier = "==0.2.29" },
|
||||
{ name = "pydantic", marker = "extra == 'chat'", specifier = "<=2.10.1" },
|
||||
{ name = "pydantic", marker = "extra == 'code'", specifier = "<=2.10.1" },
|
||||
@@ -4252,7 +4252,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "praisonaiagents"
|
||||
version = "0.1.1"
|
||||
version = "0.1.2"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
dependencies = [
|
||||
{ name = "aiohttp" },
|
||||
@@ -4261,9 +4261,9 @@ dependencies = [
|
||||
{ name = "pydantic" },
|
||||
{ name = "rich" },
|
||||
]
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/b0/41/14a8e49c644c26ee565511776c67cc978427f36aec68a1442ac666c35401/praisonaiagents-0.1.1.tar.gz", hash = "sha256:76f69188e4893b0e868f33ea02d26cccfa90b99d679c2db4185d8cf624fa740e", size = 550745, upload-time = "2025-12-17T00:37:35.974Z" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/e3/cd/e00b4dfc4127e2f51acc8c414a392ec45b5e80c45386f082efc31fe7af1b/praisonaiagents-0.1.2.tar.gz", hash = "sha256:e8f94748af81897cd73cee1e74d031296c2103c2c7b8911ee0618c5cfb2a8492", size = 551139, upload-time = "2025-12-17T07:43:27.008Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/f7/93/2cef070fae77bbef32a986ad7e1787f799442047f5dac831b9c137839353/praisonaiagents-0.1.1-py3-none-any.whl", hash = "sha256:c116551a35df0f8766496ba5102c54633f071735eae2a71b33eb4df5e2728e86", size = 518796, upload-time = "2025-12-17T00:37:33.824Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/8c/1f/8a4e5097bee7e8031c2428cf8c1e47b06c85c5f4ce552231de3224d0c301/praisonaiagents-0.1.2-py3-none-any.whl", hash = "sha256:c5a1241da8feb32957b0820ffaa37b03e4ff45462d322fde4ff84f224f10eb91", size = 518797, upload-time = "2025-12-17T07:43:25.172Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
Reference in new issue
Block a user