mirror of
https://github.com/MervinPraison/PraisonAI.git
synced 2026-11-11 03:31:27 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7e8f9b0574 |
No files matched your search
@@ -103,7 +103,11 @@ 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](#workflow-checkpoints) | [📖](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) |
|
||||
|
||||
## Supported Providers
|
||||
|
||||
@@ -445,6 +449,59 @@ result = asyncio.run(manager.aexecute("deploy", default_llm="gpt-4o-mini"))
|
||||
- **Per-Step Agents**: Configure different agents with roles, goals, tools for each step
|
||||
- **Async Execution**: Use `aexecute()` for async workflows
|
||||
- **Planning Mode**: Enable at workflow level with `planning=True`
|
||||
- **Branching**: Use `next_steps` and `branch_condition` for conditional routing
|
||||
- **Loops**: Use `loop_over` and `loop_var` to iterate over data
|
||||
|
||||
### Workflow Branching & Loops
|
||||
|
||||
```python
|
||||
from praisonaiagents.memory.workflows import WorkflowStep
|
||||
|
||||
# Branching step
|
||||
decision_step = WorkflowStep(
|
||||
name="decide",
|
||||
action="Evaluate if task is complete",
|
||||
next_steps=["success_step", "retry_step"],
|
||||
branch_condition={"success": ["success_step"], "failure": ["retry_step"]}
|
||||
)
|
||||
|
||||
# Loop step
|
||||
loop_step = WorkflowStep(
|
||||
name="process_items",
|
||||
action="Process {{item}}",
|
||||
loop_over="items", # Variable containing list
|
||||
loop_var="item" # Current item variable name
|
||||
)
|
||||
```
|
||||
|
||||
### Task Callbacks & Variables (process="workflow")
|
||||
|
||||
```python
|
||||
from praisonaiagents import Agent, Task, PraisonAIAgents
|
||||
|
||||
# Per-task agent config (no need to create agent separately)
|
||||
task = Task(
|
||||
description="Research {{topic}}",
|
||||
agent_config={"name": "Researcher", "role": "Expert", "llm": "gpt-4o-mini"},
|
||||
variables={"topic": "AI trends"}
|
||||
)
|
||||
|
||||
# Callbacks for workflow execution
|
||||
def on_start(task, task_id):
|
||||
print(f"Starting: {task.name}")
|
||||
|
||||
def on_complete(task, output):
|
||||
print(f"Completed: {task.name}")
|
||||
|
||||
agents = PraisonAIAgents(
|
||||
agents=[agent],
|
||||
tasks=[task],
|
||||
process="workflow",
|
||||
on_task_start=on_start,
|
||||
on_task_complete=on_complete,
|
||||
variables={"global_var": "shared_value"} # Global variables for all tasks
|
||||
)
|
||||
```
|
||||
|
||||
### 9. Hooks
|
||||
|
||||
|
||||
+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.16" \
|
||||
"praisonai>=2.3.18" \
|
||||
"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.16" \
|
||||
"praisonai>=2.3.18" \
|
||||
"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.16" \
|
||||
"praisonai>=2.3.18" \
|
||||
"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.16" \
|
||||
"praisonai>=2.3.18" \
|
||||
"praisonai[ui]" \
|
||||
"praisonai[crewai]"
|
||||
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
"""
|
||||
Task Callbacks Example
|
||||
|
||||
Demonstrates using on_task_start and on_task_complete callbacks
|
||||
with PraisonAIAgents for workflow monitoring and logging.
|
||||
"""
|
||||
|
||||
from praisonaiagents import Agent, Task, PraisonAIAgents
|
||||
|
||||
# Create an agent
|
||||
researcher = Agent(
|
||||
name="Researcher",
|
||||
role="Research Assistant",
|
||||
goal="Find and summarize information",
|
||||
llm="gpt-4o-mini"
|
||||
)
|
||||
|
||||
# Create tasks with variables
|
||||
task1 = Task(
|
||||
name="research",
|
||||
description="Research the topic: {{topic}}",
|
||||
expected_output="A brief summary of the topic",
|
||||
agent=researcher,
|
||||
variables={"topic": "artificial intelligence"}
|
||||
)
|
||||
|
||||
task2 = Task(
|
||||
name="summarize",
|
||||
description="Create a one-paragraph summary of the research.",
|
||||
expected_output="A concise summary",
|
||||
agent=researcher
|
||||
)
|
||||
|
||||
# Define callbacks
|
||||
def on_start(task, task_id):
|
||||
"""Called before each task starts."""
|
||||
print(f"🚀 Starting task: {task.name} (ID: {task_id})")
|
||||
|
||||
def on_complete(task, output):
|
||||
"""Called after each task completes."""
|
||||
print(f"✅ Completed task: {task.name}")
|
||||
print(f" Output preview: {str(output)[:100]}...")
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Create agents with callbacks
|
||||
agents = PraisonAIAgents(
|
||||
agents=[researcher],
|
||||
tasks=[task1, task2],
|
||||
process="workflow",
|
||||
on_task_start=on_start,
|
||||
on_task_complete=on_complete,
|
||||
variables={"global_var": "shared_value"} # Global variables
|
||||
)
|
||||
|
||||
# Run the workflow
|
||||
result = agents.start()
|
||||
print("\n🎉 Workflow completed!")
|
||||
@@ -0,0 +1,48 @@
|
||||
"""
|
||||
Workflow Branching Example
|
||||
|
||||
Demonstrates conditional branching in workflows where steps can route
|
||||
to different next steps based on output content.
|
||||
"""
|
||||
|
||||
from praisonaiagents.memory.workflows import WorkflowManager, WorkflowStep, Workflow
|
||||
|
||||
# Create a workflow with branching
|
||||
workflow = Workflow(
|
||||
name="Decision Workflow",
|
||||
description="A workflow that branches based on validation result",
|
||||
steps=[
|
||||
WorkflowStep(
|
||||
name="validate",
|
||||
action="Check if the number 42 is positive. Reply with 'valid' or 'invalid'.",
|
||||
next_steps=["success_handler", "error_handler"],
|
||||
branch_condition={
|
||||
"valid": ["success_handler"],
|
||||
"invalid": ["error_handler"]
|
||||
}
|
||||
),
|
||||
WorkflowStep(
|
||||
name="success_handler",
|
||||
action="The validation passed! Generate a success message."
|
||||
),
|
||||
WorkflowStep(
|
||||
name="error_handler",
|
||||
action="The validation failed. Generate an error message."
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Create manager and register workflow
|
||||
manager = WorkflowManager()
|
||||
manager.workflows["Decision Workflow"] = workflow
|
||||
|
||||
# Execute - will branch to success_handler since 42 is positive
|
||||
result = manager.execute(
|
||||
"Decision Workflow",
|
||||
default_llm="gpt-4o-mini"
|
||||
)
|
||||
|
||||
print("Workflow completed!")
|
||||
for step_result in result["results"]:
|
||||
print(f" {step_result['step']}: {step_result['status']}")
|
||||
@@ -0,0 +1,63 @@
|
||||
"""
|
||||
Workflow Checkpoints Example
|
||||
|
||||
Demonstrates saving and resuming workflow execution using checkpoints.
|
||||
Useful for long-running workflows that may be interrupted.
|
||||
"""
|
||||
|
||||
from praisonaiagents.memory.workflows import WorkflowManager, WorkflowStep, Workflow
|
||||
|
||||
# Create a multi-step workflow
|
||||
workflow = Workflow(
|
||||
name="Long Process",
|
||||
description="A workflow with checkpoints for resumability",
|
||||
steps=[
|
||||
WorkflowStep(
|
||||
name="step1",
|
||||
action="Initialize the process and prepare data."
|
||||
),
|
||||
WorkflowStep(
|
||||
name="step2",
|
||||
action="Process the first batch of data."
|
||||
),
|
||||
WorkflowStep(
|
||||
name="step3",
|
||||
action="Process the second batch of data."
|
||||
),
|
||||
WorkflowStep(
|
||||
name="step4",
|
||||
action="Finalize and generate report."
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
manager = WorkflowManager()
|
||||
manager.workflows["Long Process"] = workflow
|
||||
|
||||
# Execute with checkpoint - saves after each step
|
||||
print("=== Starting workflow with checkpoint ===")
|
||||
result = manager.execute(
|
||||
"Long Process",
|
||||
default_llm="gpt-4o-mini",
|
||||
checkpoint="my-checkpoint" # Saves progress after each step
|
||||
)
|
||||
|
||||
print(f"Completed {len(result['results'])} steps")
|
||||
|
||||
# List available checkpoints
|
||||
print("\n=== Available checkpoints ===")
|
||||
checkpoints = manager.list_checkpoints()
|
||||
for cp in checkpoints:
|
||||
print(f" {cp['name']}: {cp['completed_steps']} steps completed")
|
||||
|
||||
# Resume from checkpoint (if workflow was interrupted)
|
||||
# result = manager.execute(
|
||||
# "Long Process",
|
||||
# default_llm="gpt-4o-mini",
|
||||
# resume="my-checkpoint" # Resumes from last saved state
|
||||
# )
|
||||
|
||||
# Clean up checkpoint
|
||||
manager.delete_checkpoint("my-checkpoint")
|
||||
print("\n✅ Checkpoint deleted")
|
||||
@@ -0,0 +1,69 @@
|
||||
"""
|
||||
Workflow Early Stop Example
|
||||
|
||||
Demonstrates how to stop a workflow early using custom handler
|
||||
functions that return StepResult with stop_workflow=True.
|
||||
"""
|
||||
|
||||
from praisonaiagents.memory.workflows import (
|
||||
WorkflowManager, WorkflowStep, Workflow,
|
||||
WorkflowContext, StepResult
|
||||
)
|
||||
|
||||
# Custom validator that can stop the workflow
|
||||
def validate_data(context: WorkflowContext) -> StepResult:
|
||||
"""Check if data is valid and stop workflow if not."""
|
||||
data = context.variables.get("data", {})
|
||||
|
||||
if data.get("value", 0) < 0:
|
||||
return StepResult(
|
||||
output="❌ Validation failed: negative value detected. Stopping workflow.",
|
||||
stop_workflow=True # This stops the entire workflow
|
||||
)
|
||||
|
||||
return StepResult(
|
||||
output="✅ Validation passed: data is valid.",
|
||||
stop_workflow=False # Continue to next step
|
||||
)
|
||||
|
||||
# Create workflow with early stop capability
|
||||
workflow = Workflow(
|
||||
name="Data Processing",
|
||||
description="Process data with validation gate",
|
||||
variables={
|
||||
"data": {"value": -5} # Invalid data - will trigger early stop
|
||||
},
|
||||
steps=[
|
||||
WorkflowStep(
|
||||
name="validate",
|
||||
handler=validate_data # Custom function
|
||||
),
|
||||
WorkflowStep(
|
||||
name="process",
|
||||
action="Process the validated data." # Won't run if validation fails
|
||||
),
|
||||
WorkflowStep(
|
||||
name="report",
|
||||
action="Generate final report." # Won't run if validation fails
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
manager = WorkflowManager()
|
||||
manager.workflows["Data Processing"] = workflow
|
||||
|
||||
# Test with invalid data (will stop early)
|
||||
print("=== Testing with invalid data ===")
|
||||
result = manager.execute("Data Processing", default_llm="gpt-4o-mini")
|
||||
|
||||
for step_result in result["results"]:
|
||||
print(f" {step_result['step']}: {step_result['output']}")
|
||||
|
||||
# Test with valid data (will complete)
|
||||
print("\n=== Testing with valid data ===")
|
||||
workflow.variables["data"] = {"value": 42}
|
||||
result = manager.execute("Data Processing", default_llm="gpt-4o-mini")
|
||||
|
||||
for step_result in result["results"]:
|
||||
print(f" {step_result['step']}: {step_result['status']}")
|
||||
@@ -0,0 +1,46 @@
|
||||
"""
|
||||
Workflow Loops Example
|
||||
|
||||
Demonstrates iterating over a list of items in a workflow step.
|
||||
Each item is processed individually with the loop variable.
|
||||
"""
|
||||
|
||||
from praisonaiagents.memory.workflows import WorkflowManager, WorkflowStep, Workflow
|
||||
|
||||
# Create a workflow with loop
|
||||
workflow = Workflow(
|
||||
name="Process Items",
|
||||
description="Process a list of items using loop",
|
||||
variables={
|
||||
"items": ["apple", "banana", "cherry"] # List to iterate over
|
||||
},
|
||||
steps=[
|
||||
WorkflowStep(
|
||||
name="process_each",
|
||||
action="Describe the fruit: {{item}}",
|
||||
loop_over="items", # Variable name containing the list
|
||||
loop_var="item" # Variable name for current item
|
||||
),
|
||||
WorkflowStep(
|
||||
name="summarize",
|
||||
action="Summarize all the fruits that were processed."
|
||||
)
|
||||
]
|
||||
)
|
||||
|
||||
if __name__ == "__main__":
|
||||
# Create manager and register workflow
|
||||
manager = WorkflowManager()
|
||||
manager.workflows["Process Items"] = workflow
|
||||
|
||||
# Execute - will process each fruit in the list
|
||||
result = manager.execute(
|
||||
"Process Items",
|
||||
default_llm="gpt-4o-mini"
|
||||
)
|
||||
|
||||
print("Workflow completed!")
|
||||
for step_result in result["results"]:
|
||||
print(f" {step_result['step']}: {step_result['status']}")
|
||||
if isinstance(step_result.get("output"), list):
|
||||
print(f" Loop processed {len(step_result['output'])} items")
|
||||
@@ -57,6 +57,19 @@ def __getattr__(name):
|
||||
if name == "WorkflowStep":
|
||||
from .workflows import WorkflowStep
|
||||
return WorkflowStep
|
||||
if name == "WorkflowContext":
|
||||
from .workflows import WorkflowContext
|
||||
return WorkflowContext
|
||||
if name == "StepResult":
|
||||
from .workflows import StepResult
|
||||
return StepResult
|
||||
# Backward compatibility aliases
|
||||
if name == "StepInput":
|
||||
from .workflows import WorkflowContext
|
||||
return WorkflowContext
|
||||
if name == "StepOutput":
|
||||
from .workflows import StepResult
|
||||
return StepResult
|
||||
if name == "create_workflow_manager":
|
||||
from .workflows import create_workflow_manager
|
||||
return create_workflow_manager
|
||||
@@ -89,6 +102,8 @@ __all__ = [
|
||||
"WorkflowManager",
|
||||
"Workflow",
|
||||
"WorkflowStep",
|
||||
"WorkflowContext",
|
||||
"StepResult",
|
||||
"create_workflow_manager",
|
||||
# Hooks
|
||||
"HooksManager",
|
||||
|
||||
@@ -29,13 +29,35 @@ from dataclasses import dataclass, field
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
@dataclass
|
||||
class WorkflowContext:
|
||||
"""Context passed to step handlers. Contains all information about the current workflow state."""
|
||||
input: str = "" # Original workflow input
|
||||
previous_result: Optional[str] = None # Output from previous step
|
||||
current_step: str = "" # Current step name
|
||||
variables: Dict[str, Any] = field(default_factory=dict) # All workflow variables
|
||||
|
||||
@dataclass
|
||||
class StepResult:
|
||||
"""Result returned from step handlers."""
|
||||
output: str = "" # Step output content
|
||||
stop_workflow: bool = False # If True, stop the entire workflow early
|
||||
variables: Dict[str, Any] = field(default_factory=dict) # Variables to add/update
|
||||
|
||||
# Aliases for backward compatibility
|
||||
StepInput = WorkflowContext
|
||||
StepOutput = StepResult
|
||||
|
||||
|
||||
@dataclass
|
||||
class WorkflowStep:
|
||||
"""A single step in a workflow."""
|
||||
name: str
|
||||
description: str = ""
|
||||
action: str = "" # The action/prompt to execute
|
||||
condition: Optional[str] = None # Optional condition for execution
|
||||
condition: Optional[str] = None # Optional condition for execution (string)
|
||||
should_run: Optional[Callable[['WorkflowContext'], bool]] = None # Function to check if step should run
|
||||
handler: Optional[Callable[['WorkflowContext'], 'StepResult']] = None # Custom function instead of agent
|
||||
on_error: Literal["stop", "continue", "retry"] = "stop"
|
||||
max_retries: int = 1
|
||||
|
||||
@@ -46,6 +68,7 @@ class WorkflowStep:
|
||||
|
||||
# Agent configuration fields
|
||||
agent_config: Optional[Dict[str, Any]] = None # Per-step agent config {role, goal, backstory, llm}
|
||||
agent: Optional[Any] = None # Direct agent instance for this step
|
||||
tools: Optional[List[Any]] = None # Tools for this step
|
||||
|
||||
# Branching fields
|
||||
@@ -56,12 +79,24 @@ class WorkflowStep:
|
||||
loop_over: Optional[str] = None # Variable name to iterate over (e.g., "items")
|
||||
loop_var: str = "item" # Variable name for current item in loop
|
||||
|
||||
# Backward compatibility aliases
|
||||
@property
|
||||
def evaluator(self):
|
||||
return self.should_run
|
||||
|
||||
@property
|
||||
def executor(self):
|
||||
return self.handler
|
||||
|
||||
def to_dict(self) -> Dict[str, Any]:
|
||||
return {
|
||||
"name": self.name,
|
||||
"description": self.description,
|
||||
"action": self.action,
|
||||
"condition": self.condition,
|
||||
"should_run": self.should_run is not None,
|
||||
"handler": self.handler is not None,
|
||||
"agent": self.agent is not None,
|
||||
"on_error": self.on_error,
|
||||
"max_retries": self.max_retries,
|
||||
"context_from": self.context_from,
|
||||
@@ -717,6 +752,16 @@ class WorkflowManager:
|
||||
on_result=on_result
|
||||
)
|
||||
|
||||
# Handle skipped steps
|
||||
if step_result.get("skipped"):
|
||||
results.append({
|
||||
"step": step.name,
|
||||
"status": "skipped",
|
||||
"output": None
|
||||
})
|
||||
current_step_idx += 1
|
||||
continue
|
||||
|
||||
results.append({
|
||||
"step": step.name,
|
||||
"status": "success" if step_result["success"] else "failed",
|
||||
@@ -724,6 +769,11 @@ class WorkflowManager:
|
||||
"error": step_result.get("error")
|
||||
})
|
||||
|
||||
# Handle early stop (like Agno's StepOutput.stop=True)
|
||||
if step_result.get("stop"):
|
||||
self._log(f"Workflow stopped early at step '{step.name}'")
|
||||
break
|
||||
|
||||
# Save checkpoint after each step if enabled
|
||||
if checkpoint:
|
||||
self._save_checkpoint(
|
||||
@@ -784,9 +834,64 @@ class WorkflowManager:
|
||||
planning: bool = False,
|
||||
verbose: int = 0,
|
||||
on_step: Optional[Callable[[WorkflowStep, int], None]] = None,
|
||||
on_result: Optional[Callable[[WorkflowStep, str], None]] = None
|
||||
on_result: Optional[Callable[[WorkflowStep, str], None]] = None,
|
||||
original_input: str = ""
|
||||
) -> Dict[str, Any]:
|
||||
"""Execute a single workflow step."""
|
||||
# Get previous step output
|
||||
previous_output = results[-1].get("output") if results else None
|
||||
|
||||
# Create context for step handlers
|
||||
context = WorkflowContext(
|
||||
input=original_input,
|
||||
previous_result=str(previous_output) if previous_output else None,
|
||||
current_step=step.name,
|
||||
variables=all_variables.copy()
|
||||
)
|
||||
|
||||
# Check should_run condition if provided
|
||||
if step.should_run:
|
||||
try:
|
||||
if not step.should_run(context):
|
||||
return {
|
||||
"success": True,
|
||||
"output": None,
|
||||
"skipped": True,
|
||||
"stop": False
|
||||
}
|
||||
except Exception as e:
|
||||
self._log(f"should_run check for step '{step.name}' failed: {e}")
|
||||
|
||||
# If step has a custom handler function
|
||||
if step.handler:
|
||||
try:
|
||||
result = step.handler(context)
|
||||
# Handle StepResult
|
||||
if isinstance(result, StepResult):
|
||||
# Update variables from result
|
||||
if result.variables:
|
||||
all_variables.update(result.variables)
|
||||
return {
|
||||
"success": True,
|
||||
"output": result.output,
|
||||
"stop": result.stop_workflow, # Early termination flag
|
||||
"error": None
|
||||
}
|
||||
else:
|
||||
return {
|
||||
"success": True,
|
||||
"output": str(result),
|
||||
"stop": False,
|
||||
"error": None
|
||||
}
|
||||
except Exception as e:
|
||||
return {
|
||||
"success": False,
|
||||
"output": None,
|
||||
"stop": False,
|
||||
"error": str(e)
|
||||
}
|
||||
|
||||
# Build context from previous steps
|
||||
context = self._build_step_context(step, step_idx, results, all_variables)
|
||||
|
||||
@@ -800,15 +905,20 @@ class WorkflowManager:
|
||||
# Get or create executor for this step
|
||||
step_executor = executor
|
||||
if step_executor is None:
|
||||
# Create agent for this step
|
||||
step_agent = self._create_step_agent(
|
||||
step=step,
|
||||
default_agent=default_agent,
|
||||
default_llm=default_llm,
|
||||
memory=memory,
|
||||
planning=planning,
|
||||
verbose=verbose
|
||||
)
|
||||
# Use step's direct agent if provided
|
||||
step_agent = step.agent
|
||||
|
||||
# Otherwise create agent from config
|
||||
if step_agent is None:
|
||||
step_agent = self._create_step_agent(
|
||||
step=step,
|
||||
default_agent=default_agent,
|
||||
default_llm=default_llm,
|
||||
memory=memory,
|
||||
planning=planning,
|
||||
verbose=verbose
|
||||
)
|
||||
|
||||
if step_agent:
|
||||
if planning and hasattr(step_agent, 'start'):
|
||||
def agent_executor(prompt, agent=step_agent):
|
||||
@@ -823,6 +933,7 @@ class WorkflowManager:
|
||||
return {
|
||||
"success": False,
|
||||
"output": None,
|
||||
"stop": False,
|
||||
"error": f"No executor available for step '{step.name}'"
|
||||
}
|
||||
|
||||
@@ -853,6 +964,7 @@ class WorkflowManager:
|
||||
return {
|
||||
"success": step_success,
|
||||
"output": output,
|
||||
"stop": False, # Normal execution doesn't request stop
|
||||
"error": error
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
||||
|
||||
[project]
|
||||
name = "praisonaiagents"
|
||||
version = "0.0.194"
|
||||
version = "0.0.196"
|
||||
description = "Praison AI agents for completing complex tasks with Self Reflection Agents"
|
||||
requires-python = ">=3.10"
|
||||
authors = [
|
||||
|
||||
Generated
+1
-1
@@ -2422,7 +2422,7 @@ wheels = [
|
||||
|
||||
[[package]]
|
||||
name = "praisonaiagents"
|
||||
version = "0.0.194"
|
||||
version = "0.0.196"
|
||||
source = { editable = "." }
|
||||
dependencies = [
|
||||
{ name = "aiohttp" },
|
||||
|
||||
+58
-1
@@ -103,7 +103,11 @@ 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](#workflow-checkpoints) | [📖](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) |
|
||||
|
||||
## Supported Providers
|
||||
|
||||
@@ -445,6 +449,59 @@ result = asyncio.run(manager.aexecute("deploy", default_llm="gpt-4o-mini"))
|
||||
- **Per-Step Agents**: Configure different agents with roles, goals, tools for each step
|
||||
- **Async Execution**: Use `aexecute()` for async workflows
|
||||
- **Planning Mode**: Enable at workflow level with `planning=True`
|
||||
- **Branching**: Use `next_steps` and `branch_condition` for conditional routing
|
||||
- **Loops**: Use `loop_over` and `loop_var` to iterate over data
|
||||
|
||||
### Workflow Branching & Loops
|
||||
|
||||
```python
|
||||
from praisonaiagents.memory.workflows import WorkflowStep
|
||||
|
||||
# Branching step
|
||||
decision_step = WorkflowStep(
|
||||
name="decide",
|
||||
action="Evaluate if task is complete",
|
||||
next_steps=["success_step", "retry_step"],
|
||||
branch_condition={"success": ["success_step"], "failure": ["retry_step"]}
|
||||
)
|
||||
|
||||
# Loop step
|
||||
loop_step = WorkflowStep(
|
||||
name="process_items",
|
||||
action="Process {{item}}",
|
||||
loop_over="items", # Variable containing list
|
||||
loop_var="item" # Current item variable name
|
||||
)
|
||||
```
|
||||
|
||||
### Task Callbacks & Variables (process="workflow")
|
||||
|
||||
```python
|
||||
from praisonaiagents import Agent, Task, PraisonAIAgents
|
||||
|
||||
# Per-task agent config (no need to create agent separately)
|
||||
task = Task(
|
||||
description="Research {{topic}}",
|
||||
agent_config={"name": "Researcher", "role": "Expert", "llm": "gpt-4o-mini"},
|
||||
variables={"topic": "AI trends"}
|
||||
)
|
||||
|
||||
# Callbacks for workflow execution
|
||||
def on_start(task, task_id):
|
||||
print(f"Starting: {task.name}")
|
||||
|
||||
def on_complete(task, output):
|
||||
print(f"Completed: {task.name}")
|
||||
|
||||
agents = PraisonAIAgents(
|
||||
agents=[agent],
|
||||
tasks=[task],
|
||||
process="workflow",
|
||||
on_task_start=on_start,
|
||||
on_task_complete=on_complete,
|
||||
variables={"global_var": "shared_value"} # Global variables for all tasks
|
||||
)
|
||||
```
|
||||
|
||||
### 9. Hooks
|
||||
|
||||
|
||||
@@ -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.16.tar.gz"
|
||||
sha256 `curl -sL https://github.com/MervinPraison/PraisonAI/archive/refs/tags/v2.3.16.tar.gz | shasum -a 256`.split.first
|
||||
url "https://github.com/MervinPraison/PraisonAI/archive/refs/tags/v2.3.18.tar.gz"
|
||||
sha256 `curl -sL https://github.com/MervinPraison/PraisonAI/archive/refs/tags/v2.3.18.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.16 gunicorn markdown\n")
|
||||
file.write("RUN pip install flask praisonai==2.3.18 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.16"
|
||||
__version__ = "2.3.18"
|
||||
@@ -12,7 +12,7 @@ dependencies = [
|
||||
"rich>=13.7",
|
||||
"markdown>=3.5",
|
||||
"pyparsing>=3.0.0",
|
||||
"praisonaiagents>=0.0.194",
|
||||
"praisonaiagents>=0.0.196",
|
||||
"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.0.194" },
|
||||
{ name = "praisonaiagents", specifier = ">=0.0.196" },
|
||||
{ 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.0.194"
|
||||
version = "0.0.196"
|
||||
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/e9/5f/f572e88d4148e61da3d114f71357c9103a822099103b0b57adc7d88bedc2/praisonaiagents-0.0.194.tar.gz", hash = "sha256:e70c85203c9cf3792697535844a8bba4da158ecb9959abc5025967199eb86d36", size = 518340, upload-time = "2025-12-16T22:58:43.725Z" }
|
||||
sdist = { url = "https://files.pythonhosted.org/packages/c4/ab/35494082a1d43578b71dcd288d1199f8faee2a5c74c513140065802a535b/praisonaiagents-0.0.196.tar.gz", hash = "sha256:3996cd045af3bcf883a2215ddef8ea77653aae943197917b122ba89779e0f4ca", size = 519286, upload-time = "2025-12-16T23:18:20.613Z" }
|
||||
wheels = [
|
||||
{ url = "https://files.pythonhosted.org/packages/01/18/d0d0d99ec828d0cc749eb642e0246abda45575c18646893786cdad01fd9c/praisonaiagents-0.0.194-py3-none-any.whl", hash = "sha256:a1f89d3169a4df8c0c96706afcc7c71f20560c4fd2a37aaa0b8193ee6445fdef", size = 494859, upload-time = "2025-12-16T22:58:41.237Z" },
|
||||
{ url = "https://files.pythonhosted.org/packages/e5/ec/fadfa767224f31c867826c3837764179b713bc05a612d6b9c3b82fc83286/praisonaiagents-0.0.196-py3-none-any.whl", hash = "sha256:1cb5786fc28062488162abb7f89b91f3c012aabea8c3d9baeeaf9a0799e4f814", size = 495801, upload-time = "2025-12-16T23:18:19.035Z" },
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
||||
Reference in new issue
Block a user