-
-
Notifications
You must be signed in to change notification settings - Fork 781
Expand file tree
/
Copy pathevaluator-optimiser.py
More file actions
69 lines (61 loc) · 2.06 KB
/
evaluator-optimiser.py
File metadata and controls
69 lines (61 loc) · 2.06 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
from praisonaiagents import Agent, Task, AgentTeam
# Create generator and evaluator agents
generator = Agent(
name="Generator",
role="Solution generator",
goal="Generate initial solutions and incorporate feedback",
instructions=(
"1. Look at the context from previous tasks.\n"
"2. If you see that you have already produced 2 points, then add another 2 new points "
" so that the total becomes 10.\n"
"3. Otherwise, just produce the first 2 points.\n"
"4. Return only the final list of points, with no extra explanation."
)
)
evaluator = Agent(
name="Evaluator",
role="Solution evaluator",
goal="Evaluate solutions and provide improvement feedback",
instructions=(
"1. Count how many lines in the response start with a number and a period (like '1. ' or '2. ').\n"
"2. If there are 10 or more, respond with 'done'.\n"
"3. Otherwise, respond with 'more'.\n"
"4. Return only the single word: 'done' or 'more'."
)
)
# Create tasks for the feedback loop
generate_task = Task(
name="generate",
description="Write 2 points about AI incuding if anything exiting from previous points",
expected_output="2 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 = AgentTeam(
agents=[generator, evaluator],
tasks=[generate_task, evaluate_task],
process="workflow", output="verbose"
)
# 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}")