-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Expand file tree
/
Copy pathprompt_chaining.py
More file actions
81 lines (71 loc) · 2.33 KB
/
prompt_chaining.py
File metadata and controls
81 lines (71 loc) · 2.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
from praisonaiagents.agent import Agent
from praisonaiagents.task import Task
from praisonaiagents.agents import Agents
from typing import List, Dict
import time
def get_time_check():
current_time = int(time.time())
result = "even" if current_time % 2 == 0 else "odd"
print(f"Time check: {current_time} is {result}")
return result
# Create agents for each step in the chain
agent1 = Agent(
name="Time Checker",
role="Time checker",
goal="Check if the time is even or odd",
instructions="Check if the time is even or odd",
tools=[get_time_check]
)
agent2 = Agent(
name="Advanced Analyzer",
role="Advanced data analyzer",
goal="Perform in-depth analysis of processed data",
instructions="Analyze the processed data in detail"
)
agent3 = Agent(
name="Final Processor",
role="Final data processor",
goal="Generate final output based on analysis",
instructions="Create final output based on analyzed data"
)
# Create tasks for each step
initial_task = Task(
name="time_check",
description="Getting time check and checking if it is even or odd",
expected_output="Getting time check and checking if it is even or odd",
agent=agent1,
is_start=True, # Mark as the starting task
task_type="decision", # This task will make a decision
next_tasks=["advanced_analysis"], # Next task if condition passes
condition={
"even": ["advanced_analysis"], # If passes, go to advanced analysis
"odd": "" # If fails, exit the chain
}
)
analysis_task = Task(
name="advanced_analysis",
description="Perform advanced analysis on the processed data",
expected_output="Analyzed data ready for final processing",
agent=agent2,
next_tasks=["final_processing"]
)
final_task = Task(
name="final_processing",
description="Generate final output",
expected_output="Final processed result",
agent=agent3
)
# Create the workflow manager
workflow = AgentTeam(
agents=[agent1, agent2, agent3],
tasks=[initial_task, analysis_task, final_task],
process="workflow", # Use workflow process type
output="verbose"
)
# Run the workflow
results = workflow.start(return_dict=True)
# Print results
print("\nWorkflow Results:")
for task_id, result in results["task_results"].items():
if result:
print(f"Task {task_id}: {result.raw}")