Skip to content

Commit 8253f7c

Browse files
committed
[FIX][GKP Agent fix] [Run method] [SwarmRouter fix]
1 parent f027bf0 commit 8253f7c

3 files changed

Lines changed: 33 additions & 84 deletions

File tree

swarms/agents/gkp_agent.py

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
from typing import List, Dict, Any, Union
21
import time
2+
from typing import Any, Dict, List, Union
3+
4+
from loguru import logger
35

46
from swarms.structs.agent import Agent
57
from swarms.structs.conversation import Conversation
68

7-
from loguru import logger
8-
99

1010
class KnowledgeGenerator:
1111
"""
@@ -23,6 +23,7 @@ class KnowledgeGenerator:
2323
def __init__(
2424
self,
2525
agent_name: str = "knowledge-generator",
26+
description: str = "Generates factual, relevant knowledge to assist with answering queries",
2627
model_name: str = "openai/o1",
2728
num_knowledge_items: int = 2,
2829
) -> None:
@@ -525,7 +526,7 @@ def _coordinate_answers(
525526

526527
return result
527528

528-
def run(
529+
def _run(
529530
self, queries: List[str], detailed_output: bool = False
530531
) -> Union[List[str], List[Dict[str, Any]]]:
531532
"""
@@ -552,6 +553,30 @@ def run(
552553
)
553554

554555
return results
556+
557+
def run(self, task: str) -> str:
558+
"""
559+
Run the GKP agent on a single task.
560+
561+
Args:
562+
task (str): The task to process
563+
564+
Returns:
565+
str: The final answer
566+
"""
567+
return self._run([task])[0]
568+
569+
def __call__(self, task: str) -> str:
570+
"""
571+
Run the GKP agent on a single task.
572+
573+
Args:
574+
task (str): The task to process
575+
576+
Returns:
577+
str: The final answer
578+
"""
579+
return self.run(task)
555580

556581

557582
# # Example usage

swarms/agents/reasoning_agents.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,3 @@
1-
"""
2-
ReasoningAgentRouter: A flexible router for advanced reasoning agent swarms.
3-
4-
This module provides the ReasoningAgentRouter class, which enables dynamic selection and instantiation
5-
of various advanced reasoning agent types (swarms) for complex problem-solving tasks. It supports
6-
multiple reasoning strategies, including self-consistency, collaborative duo agents, iterative
7-
reflection, knowledge prompting, and agent judging.
8-
9-
Key Features:
10-
- Unified interface for multiple agent types (see `agent_types`)
11-
- Caching of agent instances for efficiency and memory management
12-
- Extensible factory-based architecture for easy addition of new agent types
13-
- Batch and single-task execution
14-
- Customizable agent configuration (model, prompt, memory, etc.)
15-
16-
Supported Agent Types:
17-
- "reasoning-duo" / "reasoning-agent": Dual collaborative agent system
18-
- "self-consistency" / "consistency-agent": Multiple independent solutions with consensus
19-
- "ire" / "ire-agent": Iterative Reflective Expansion agent
20-
- "ReflexionAgent": Reflexion agent with memory
21-
- "GKPAgent": Generated Knowledge Prompting agent
22-
- "AgentJudge": Agent judge for evaluation/critique
23-
24-
Example usage:
25-
>>> router = ReasoningAgentRouter(swarm_type="self-consistency", num_samples=3)
26-
>>> result = router.run("What is the capital of France?")
27-
>>> print(result)
28-
29-
>>> # Batch mode
30-
>>> results = router.batched_run(["2+2?", "3+3?"])
31-
>>> print(results)
32-
33-
"""
34-
351
import traceback
362
from typing import (
373
List,

tests/structs/test_swarm_router.py

Lines changed: 4 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
import pytest
21
from unittest.mock import Mock, patch
32

3+
import pytest
4+
5+
from swarms.structs.agent import Agent
46
from swarms.structs.swarm_router import (
57
SwarmRouter,
68
SwarmRouterConfig,
7-
SwarmRouterRunError,
89
SwarmRouterConfigError,
9-
Document,
10+
SwarmRouterRunError,
1011
)
11-
from swarms.structs.agent import Agent
1212

1313

1414
@pytest.fixture
@@ -127,27 +127,6 @@ def test_initialization_with_agent_rearrange_flow(sample_agents):
127127
assert router.rearrange_flow == flow
128128

129129

130-
def test_initialization_with_shared_memory(sample_agents):
131-
"""Test SwarmRouter with shared memory system."""
132-
mock_memory = Mock()
133-
router = SwarmRouter(
134-
agents=sample_agents,
135-
shared_memory_system=mock_memory,
136-
)
137-
138-
assert router.shared_memory_system == mock_memory
139-
140-
141-
def test_initialization_with_worker_tools(sample_agents):
142-
"""Test SwarmRouter with worker tools."""
143-
mock_tool = Mock()
144-
router = SwarmRouter(
145-
agents=sample_agents,
146-
worker_tools=[mock_tool],
147-
)
148-
149-
assert router.worker_tools == [mock_tool]
150-
151130

152131
def test_invalid_swarm_type():
153132
"""Test error when invalid swarm type is provided."""
@@ -660,20 +639,6 @@ def test_handle_rules(sample_agents):
660639
)
661640

662641

663-
def test_activate_shared_memory(sample_agents):
664-
"""Test activate_shared_memory method."""
665-
mock_memory = Mock()
666-
router = SwarmRouter(
667-
agents=sample_agents,
668-
shared_memory_system=mock_memory,
669-
)
670-
671-
router.activate_shared_memory()
672-
673-
# Check that all agents have the shared memory system
674-
for agent in router.agents:
675-
assert agent.long_term_memory == mock_memory
676-
677642

678643
def test_update_system_prompt_for_agent_in_swarm(sample_agents):
679644
"""Test update_system_prompt_for_agent_in_swarm method."""
@@ -928,13 +893,6 @@ def test_swarm_router_config_model():
928893
assert config.multi_agent_collab_prompt is True
929894

930895

931-
def test_document_model():
932-
"""Test Document model."""
933-
doc = Document(file_path="test.txt", data="Test document content")
934-
935-
assert doc.file_path == "test.txt"
936-
assert doc.data == "Test document content"
937-
938896

939897
if __name__ == "__main__":
940898
pytest.main([__file__, "-v"])

0 commit comments

Comments
 (0)