swarms 7.5.9__py3-none-any.whl → 7.6.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
swarms/agents/__init__.py CHANGED
@@ -23,6 +23,9 @@ from swarms.structs.stopping_conditions import (
23
23
  check_success,
24
24
  )
25
25
 
26
+ from swarms.agents.flexion_agent import ReflexionAgent
27
+ from swarms.agents.gkp_agent import GKPAgent
28
+
26
29
  __all__ = [
27
30
  # "ToolAgent",
28
31
  "check_done",
@@ -41,4 +44,6 @@ __all__ = [
41
44
  "ReasoningDuo",
42
45
  "ReasoningAgentRouter",
43
46
  "agent_types",
47
+ "ReflexionAgent",
48
+ "GKPAgent",
44
49
  ]
@@ -0,0 +1,119 @@
1
+ from typing import List
2
+
3
+ from swarms.prompts.agent_judge_prompt import AGENT_JUDGE_PROMPT
4
+ from swarms.structs.agent import Agent
5
+ from swarms.structs.conversation import Conversation
6
+ from swarms.utils.any_to_str import any_to_str
7
+
8
+ from loguru import logger
9
+
10
+
11
+ class AgentJudge:
12
+ """
13
+ A class to represent an agent judge that processes tasks and generates responses.
14
+
15
+ Attributes:
16
+ agent_name (str): The name of the agent judge.
17
+ system_prompt (str): The system prompt for the agent.
18
+ model_name (str): The model name used for generating responses.
19
+ conversation (Conversation): An instance of the Conversation class to manage conversation history.
20
+ max_loops (int): The maximum number of iterations to run the tasks.
21
+ agent (Agent): An instance of the Agent class that performs the task execution.
22
+
23
+ Methods:
24
+ step(tasks: List[str]) -> str:
25
+ Processes a list of tasks and returns the agent's response.
26
+
27
+ run(tasks: List[str]) -> List[str]:
28
+ Executes the tasks in a loop, updating context and collecting responses.
29
+ """
30
+
31
+ def __init__(
32
+ self,
33
+ agent_name: str = "agent-judge-01",
34
+ system_prompt: str = AGENT_JUDGE_PROMPT,
35
+ model_name: str = "openai/o1",
36
+ max_loops: int = 1,
37
+ ) -> None:
38
+ """
39
+ Initializes the AgentJudge with the specified parameters.
40
+
41
+ Args:
42
+ agent_name (str): The name of the agent judge.
43
+ system_prompt (str): The system prompt for the agent.
44
+ model_name (str): The model name used for generating responses.
45
+ max_loops (int): The maximum number of iterations to run the tasks.
46
+ """
47
+ self.agent_name = agent_name
48
+ self.system_prompt = system_prompt
49
+ self.model_name = model_name
50
+ self.conversation = Conversation(time_enabled=False)
51
+ self.max_loops = max_loops
52
+
53
+ self.agent = Agent(
54
+ agent_name=agent_name,
55
+ agent_description="You're the agent judge",
56
+ system_prompt=AGENT_JUDGE_PROMPT,
57
+ model_name=model_name,
58
+ max_loops=1,
59
+ )
60
+
61
+ def step(self, tasks: List[str]) -> str:
62
+ """
63
+ Processes a list of tasks and returns the agent's response.
64
+
65
+ Args:
66
+ tasks (List[str]): A list of tasks to be processed.
67
+
68
+ Returns:
69
+ str: The response generated by the agent.
70
+ """
71
+ prompt = any_to_str(tasks)
72
+ logger.debug(f"Running step with prompt: {prompt}")
73
+
74
+ print(prompt)
75
+
76
+ response = self.agent.run(
77
+ task=f"Evaluate the following output or outputs: {prompt}"
78
+ )
79
+ logger.debug(f"Received response: {response}")
80
+
81
+ return response
82
+
83
+ def run(self, tasks: List[str]) -> List[str]:
84
+ """
85
+ Executes the tasks in a loop, updating context and collecting responses.
86
+
87
+ Args:
88
+ tasks (List[str]): A list of tasks to be executed.
89
+
90
+ Returns:
91
+ List[str]: A list of responses generated by the agent for each iteration.
92
+ """
93
+ responses = []
94
+ context = ""
95
+
96
+ for _ in range(self.max_loops):
97
+ # Add context to the tasks if available
98
+ if context:
99
+ contextualized_tasks = [
100
+ f"Previous context: {context}\nTask: {task}"
101
+ for task in tasks
102
+ ]
103
+ else:
104
+ contextualized_tasks = tasks
105
+
106
+ # Get response for current iteration
107
+ current_response = self.step(contextualized_tasks)
108
+ responses.append(current_response)
109
+ logger.debug(
110
+ f"Current response added: {current_response}"
111
+ )
112
+
113
+ # Update context for next iteration
114
+ context = current_response
115
+
116
+ # Add to conversation history
117
+ logger.debug("Added message to conversation history.")
118
+
119
+ return responses