[FIX][GKP Agent fix] [Run method] [SwarmRouter fix]

pull/1157/head
Kye Gomez 1 day ago
parent f027bf0cf0
commit 8253f7c3b4

@ -1,11 +1,11 @@
from typing import List, Dict, Any, Union
import time
from typing import Any, Dict, List, Union
from loguru import logger
from swarms.structs.agent import Agent
from swarms.structs.conversation import Conversation
from loguru import logger
class KnowledgeGenerator:
"""
@ -23,6 +23,7 @@ class KnowledgeGenerator:
def __init__(
self,
agent_name: str = "knowledge-generator",
description: str = "Generates factual, relevant knowledge to assist with answering queries",
model_name: str = "openai/o1",
num_knowledge_items: int = 2,
) -> None:
@ -525,7 +526,7 @@ class GKPAgent:
return result
def run(
def _run(
self, queries: List[str], detailed_output: bool = False
) -> Union[List[str], List[Dict[str, Any]]]:
"""
@ -552,6 +553,30 @@ class GKPAgent:
)
return results
def run(self, task: str) -> str:
"""
Run the GKP agent on a single task.
Args:
task (str): The task to process
Returns:
str: The final answer
"""
return self._run([task])[0]
def __call__(self, task: str) -> str:
"""
Run the GKP agent on a single task.
Args:
task (str): The task to process
Returns:
str: The final answer
"""
return self.run(task)
# # Example usage

@ -1,37 +1,3 @@
"""
ReasoningAgentRouter: A flexible router for advanced reasoning agent swarms.
This module provides the ReasoningAgentRouter class, which enables dynamic selection and instantiation
of various advanced reasoning agent types (swarms) for complex problem-solving tasks. It supports
multiple reasoning strategies, including self-consistency, collaborative duo agents, iterative
reflection, knowledge prompting, and agent judging.
Key Features:
- Unified interface for multiple agent types (see `agent_types`)
- Caching of agent instances for efficiency and memory management
- Extensible factory-based architecture for easy addition of new agent types
- Batch and single-task execution
- Customizable agent configuration (model, prompt, memory, etc.)
Supported Agent Types:
- "reasoning-duo" / "reasoning-agent": Dual collaborative agent system
- "self-consistency" / "consistency-agent": Multiple independent solutions with consensus
- "ire" / "ire-agent": Iterative Reflective Expansion agent
- "ReflexionAgent": Reflexion agent with memory
- "GKPAgent": Generated Knowledge Prompting agent
- "AgentJudge": Agent judge for evaluation/critique
Example usage:
>>> router = ReasoningAgentRouter(swarm_type="self-consistency", num_samples=3)
>>> result = router.run("What is the capital of France?")
>>> print(result)
>>> # Batch mode
>>> results = router.batched_run(["2+2?", "3+3?"])
>>> print(results)
"""
import traceback
from typing import (
List,

@ -1,14 +1,14 @@
import pytest
from unittest.mock import Mock, patch
import pytest
from swarms.structs.agent import Agent
from swarms.structs.swarm_router import (
SwarmRouter,
SwarmRouterConfig,
SwarmRouterRunError,
SwarmRouterConfigError,
Document,
SwarmRouterRunError,
)
from swarms.structs.agent import Agent
@pytest.fixture
@ -127,27 +127,6 @@ def test_initialization_with_agent_rearrange_flow(sample_agents):
assert router.rearrange_flow == flow
def test_initialization_with_shared_memory(sample_agents):
"""Test SwarmRouter with shared memory system."""
mock_memory = Mock()
router = SwarmRouter(
agents=sample_agents,
shared_memory_system=mock_memory,
)
assert router.shared_memory_system == mock_memory
def test_initialization_with_worker_tools(sample_agents):
"""Test SwarmRouter with worker tools."""
mock_tool = Mock()
router = SwarmRouter(
agents=sample_agents,
worker_tools=[mock_tool],
)
assert router.worker_tools == [mock_tool]
def test_invalid_swarm_type():
"""Test error when invalid swarm type is provided."""
@ -660,20 +639,6 @@ def test_handle_rules(sample_agents):
)
def test_activate_shared_memory(sample_agents):
"""Test activate_shared_memory method."""
mock_memory = Mock()
router = SwarmRouter(
agents=sample_agents,
shared_memory_system=mock_memory,
)
router.activate_shared_memory()
# Check that all agents have the shared memory system
for agent in router.agents:
assert agent.long_term_memory == mock_memory
def test_update_system_prompt_for_agent_in_swarm(sample_agents):
"""Test update_system_prompt_for_agent_in_swarm method."""
@ -928,13 +893,6 @@ def test_swarm_router_config_model():
assert config.multi_agent_collab_prompt is True
def test_document_model():
"""Test Document model."""
doc = Document(file_path="test.txt", data="Test document content")
assert doc.file_path == "test.txt"
assert doc.data == "Test document content"
if __name__ == "__main__":
pytest.main([__file__, "-v"])

Loading…
Cancel
Save