-
-
Notifications
You must be signed in to change notification settings - Fork 420
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #290 from MervinPraison/develop
2.0.43
- Loading branch information
Showing
13 changed files
with
379 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
FROM python:3.11-slim | ||
WORKDIR /app | ||
COPY . . | ||
RUN pip install flask praisonai==2.0.42 gunicorn markdown | ||
RUN pip install flask praisonai==2.0.43 gunicorn markdown | ||
EXPOSE 8080 | ||
CMD ["gunicorn", "-b", "0.0.0.0:8080", "api:app"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
from praisonaiagents import Agent, Task, PraisonAIAgents | ||
import time | ||
|
||
def get_environment_feedback(): | ||
"""Simulates environment feedback based on time""" | ||
current_time = int(time.time()) | ||
feedback = "positive" if current_time % 2 == 0 else "negative" | ||
print(f"Environment feedback: {feedback}") | ||
return feedback | ||
|
||
# Create autonomous agent | ||
autonomous_agent = Agent( | ||
name="Autonomous Agent", | ||
role="Environment interactor", | ||
goal="Interact with environment and learn from feedback", | ||
instructions="Take actions based on environment state and adapt from feedback", | ||
tools=[get_environment_feedback] | ||
) | ||
|
||
# Create tasks for the autonomous loop | ||
action_task = Task( | ||
name="take_action", | ||
description="Analyze environment and take appropriate action", | ||
expected_output="Action taken and its rationale", | ||
agent=autonomous_agent, | ||
is_start=True, | ||
task_type="decision", | ||
next_tasks=["process_feedback"], | ||
condition={ | ||
"continue": ["process_feedback"], # Continue to get feedback | ||
"stop": [""] # Stop when goal is achieved | ||
} | ||
) | ||
|
||
feedback_task = Task( | ||
name="process_feedback", | ||
description="Process environment feedback and adapt strategy", | ||
expected_output="Adapted strategy based on feedback", | ||
agent=autonomous_agent, | ||
next_tasks=["take_action"], | ||
context=[action_task] # Access to previous action for learning | ||
) | ||
|
||
# Create workflow manager | ||
workflow = PraisonAIAgents( | ||
agents=[autonomous_agent], | ||
tasks=[action_task, feedback_task], | ||
process="workflow", | ||
verbose=True | ||
) | ||
|
||
# Run autonomous workflow | ||
results = workflow.start() | ||
|
||
# Print results | ||
print("\nAutonomous Agent Results:") | ||
for task_id, result in results["task_results"].items(): | ||
if result: | ||
print(f"Task {task_id}: {result.raw}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
from praisonaiagents import Agent, Task, PraisonAIAgents | ||
|
||
# Create generator and evaluator agents | ||
generator = Agent( | ||
name="Generator", | ||
role="Solution generator", | ||
goal="Generate initial solutions and incorporate feedback", | ||
instructions="Generate solutions and refine based on evaluator feedback" | ||
) | ||
|
||
evaluator = Agent( | ||
name="Evaluator", | ||
role="Solution evaluator", | ||
goal="Evaluate solutions and provide improvement feedback", | ||
instructions="Evaluate solutions for accuracy and provide specific feedback for improvements" | ||
) | ||
|
||
# Create tasks for the feedback loop | ||
generate_task = Task( | ||
name="generate", | ||
description="Write 5 points about AI", | ||
expected_output="5 points", | ||
agent=generator, | ||
is_start=True, | ||
task_type="decision", | ||
next_tasks=["evaluate"] | ||
) | ||
|
||
evaluate_task = Task( | ||
name="evaluate", | ||
description="Check if there are 10 points about AI", | ||
expected_output="more or done", | ||
agent=evaluator, | ||
next_tasks=["generate"], | ||
context=[generate_task], | ||
task_type="decision", | ||
condition={ | ||
"more": ["generate"], # Continue to generate | ||
"done": [""] # Exit when optimization complete | ||
} | ||
) | ||
|
||
# Create workflow manager | ||
workflow = PraisonAIAgents( | ||
agents=[generator, evaluator], | ||
tasks=[generate_task, evaluate_task], | ||
process="workflow", | ||
verbose=True | ||
) | ||
|
||
# Run optimization workflow | ||
results = workflow.start() | ||
|
||
# Print results | ||
print("\nEvaluator-Optimizer Results:") | ||
for task_id, result in results["task_results"].items(): | ||
if result: | ||
print(f"Task {task_id}: {result.raw}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
from praisonaiagents import Agent, Task, PraisonAIAgents | ||
import time | ||
|
||
def get_time_check(): | ||
current_time = int(time.time()) | ||
if current_time % 3 == 0: | ||
result = 1 | ||
elif current_time % 3 == 1: | ||
result = 2 | ||
else: | ||
result = 3 | ||
print(f"Time: {current_time}, Result: {result}") | ||
return result | ||
|
||
# Create orchestrator and worker agents | ||
router = Agent( | ||
name="Router", | ||
role="Task router", | ||
goal="Distribute tasks to based on response from get_time_check", | ||
tools=[get_time_check] | ||
) | ||
|
||
worker1 = Agent( | ||
name="Worker 1", | ||
role="Specialized worker", | ||
goal="Handle specific subtask type 1", | ||
) | ||
|
||
worker2 = Agent( | ||
name="Worker 2", | ||
role="Specialized worker", | ||
goal="Handle specific subtask type 2", | ||
) | ||
|
||
worker3 = Agent( | ||
name="Worker 3", | ||
role="Specialized worker", | ||
goal="Handle specific subtask type 3", | ||
) | ||
|
||
synthesizer = Agent( | ||
name="Synthesizer", | ||
role="Result synthesizer", | ||
goal="Combine and synthesize worker outputs", | ||
) | ||
|
||
# Create orchestrated workflow tasks | ||
router_task = Task( | ||
name="route_task", | ||
description="Analyze input from get_time_check and route to appropriate workers", | ||
expected_output="Task routing decision, 1 , 2 or 3", | ||
agent=router, | ||
is_start=True, | ||
task_type="decision", | ||
next_tasks=["worker1_task", "worker2_task", "worker3_task"], | ||
condition={ | ||
"1": ["worker1_task"], | ||
"2": ["worker2_task"], | ||
"3": ["worker3_task"] | ||
} | ||
) | ||
|
||
worker1_task = Task( | ||
name="worker1_task", | ||
description="Process type 1 operation", | ||
expected_output="Worker 1 result", | ||
agent=worker1, | ||
next_tasks=["synthesize_task"] | ||
) | ||
|
||
worker2_task = Task( | ||
name="worker2_task", | ||
description="Process type 2 operation", | ||
expected_output="Worker 2 result", | ||
agent=worker2, | ||
next_tasks=["synthesize_task"] | ||
) | ||
|
||
worker3_task = Task( | ||
name="worker3_task", | ||
description="Process type 3 operation", | ||
expected_output="Worker 3 result", | ||
agent=worker3, | ||
next_tasks=["synthesize_task"] | ||
) | ||
|
||
synthesize_task = Task( | ||
name="synthesize_task", | ||
description="Synthesize worker results into final output", | ||
expected_output="Final synthesized result", | ||
agent=synthesizer, | ||
context=[worker1_task, worker2_task, worker3_task] | ||
) | ||
|
||
# Create workflow manager | ||
workflow = PraisonAIAgents( | ||
agents=[router, worker1, worker2, worker3, synthesizer], | ||
tasks=[router_task, worker1_task, worker2_task, worker3_task, synthesize_task], | ||
process="workflow", | ||
verbose=True | ||
) | ||
|
||
# Run orchestrated workflow | ||
results = workflow.start() | ||
|
||
# Print results | ||
print("\nOrchestrator-Workers Results:") | ||
for task_id, result in results["task_results"].items(): | ||
if result: | ||
print(f"Task {task_id}: {result.raw}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
from praisonaiagents import Agent, Task, PraisonAIAgents | ||
from datetime import datetime | ||
import asyncio | ||
|
||
def process_time(): | ||
"""Simulate processing""" | ||
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") | ||
print(f"Processing at: {current_time}") | ||
return f"Processed at {current_time}" | ||
|
||
# Create parallel processing agents | ||
agent1 = Agent( | ||
name="Processor 1", | ||
role="Time collector", | ||
goal="Get the time and return it", | ||
tools=[process_time], | ||
verbose=0 | ||
) | ||
|
||
agent2 = Agent( | ||
name="Processor 2", | ||
role="Time collector", | ||
goal="Get the time and return it", | ||
tools=[process_time], | ||
verbose=0 | ||
) | ||
|
||
agent3 = Agent( | ||
name="Processor 3", | ||
role="Time collector", | ||
goal="Get the time and return it", | ||
tools=[process_time], | ||
verbose=0 | ||
) | ||
|
||
aggregator = Agent( | ||
name="Aggregator", | ||
role="Result aggregator", | ||
goal="Collect all the processed time from all tasks", | ||
verbose=0 | ||
) | ||
|
||
# Create parallel tasks with memory disabled | ||
task1 = Task( | ||
name="process_1", | ||
description="Use process_time tool to get the time", | ||
expected_output="processed time", | ||
agent=agent1, | ||
is_start=True, | ||
async_execution=True | ||
) | ||
|
||
task2 = Task( | ||
name="process_2", | ||
description="Use process_time tool to get the time", | ||
expected_output="processed time", | ||
agent=agent2, | ||
is_start=True, | ||
async_execution=True | ||
) | ||
|
||
task3 = Task( | ||
name="process_3", | ||
description="Use process_time tool to get the time", | ||
expected_output="processed time", | ||
agent=agent3, | ||
is_start=True, | ||
async_execution=True | ||
) | ||
|
||
aggregate_task = Task( | ||
name="aggregate", | ||
description="Collect all the processed time from all tasks", | ||
expected_output="Output all the processed time from all tasks and just the time", | ||
agent=aggregator, | ||
context=[task1, task2, task3] | ||
) | ||
|
||
async def main(): | ||
|
||
# Create workflow manager | ||
workflow = PraisonAIAgents( | ||
agents=[agent1, agent2, agent3, aggregator], | ||
tasks=[task1, task2, task3, aggregate_task], | ||
process="workflow", | ||
verbose=0 | ||
) | ||
|
||
# Run parallel workflow | ||
results = await workflow.astart() | ||
|
||
# Print results | ||
print("\nParallel Processing Results:") | ||
for task_id, result in results["task_results"].items(): | ||
if result: | ||
print(f"Task {task_id}: {result.raw}") | ||
|
||
# Run the async main function | ||
if __name__ == "__main__": | ||
asyncio.run(main()) |
Oops, something went wrong.