From c2ae1ec33681a5f570cec9c9f9fbee1d4d48e657 Mon Sep 17 00:00:00 2001 From: Steve-Dusty Date: Sat, 22 Nov 2025 01:34:29 -0800 Subject: [PATCH] added ire test --- tests/structs/test_i_agent.py | 86 +++++++++++++++++++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 tests/structs/test_i_agent.py diff --git a/tests/structs/test_i_agent.py b/tests/structs/test_i_agent.py new file mode 100644 index 00000000..3edf9a8e --- /dev/null +++ b/tests/structs/test_i_agent.py @@ -0,0 +1,86 @@ +import pytest + +from swarms.agents.i_agent import IterativeReflectiveExpansion + + +def test_ire_agent_initialization(): + """Test IRE agent initialization with default parameters""" + agent = IterativeReflectiveExpansion() + + assert agent is not None + assert agent.agent_name == "General-Reasoning-Agent" + assert agent.max_iterations == 5 + assert agent.output_type == "dict" + assert agent.agent is not None + + +def test_ire_agent_custom_initialization(): + """Test IRE agent initialization with custom parameters""" + agent = IterativeReflectiveExpansion( + agent_name="Custom-IRE-Agent", + description="A custom reasoning agent", + max_iterations=3, + model_name="gpt-4o", + output_type="string", + ) + + assert agent.agent_name == "Custom-IRE-Agent" + assert agent.description == "A custom reasoning agent" + assert agent.max_iterations == 3 + assert agent.output_type == "string" + + +def test_ire_agent_execution(): + """Test IRE agent execution with a simple problem""" + agent = IterativeReflectiveExpansion( + agent_name="Test-IRE-Agent", + model_name="gpt-4o", + max_iterations=2, + output_type="dict", + ) + + # Test with a simple reasoning task + task = "What are three main benefits of renewable energy?" + result = agent.run(task) + + # Result should not be None + assert result is not None + # Result should be dict or string based on output_type + assert isinstance(result, (str, dict)) + + +def test_ire_agent_generate_hypotheses(): + """Test IRE agent hypothesis generation""" + agent = IterativeReflectiveExpansion( + agent_name="Hypothesis-Test-Agent", + max_iterations=1, + ) + + task = "How can we reduce carbon emissions?" + hypotheses = agent.generate_initial_hypotheses(task) + + assert hypotheses is not None + assert isinstance(hypotheses, list) + assert len(hypotheses) > 0 + + +def test_ire_agent_workflow(): + """Test complete IRE agent workflow with iterative refinement""" + agent = IterativeReflectiveExpansion( + agent_name="Workflow-Test-Agent", + description="Agent for testing complete workflow", + model_name="gpt-4o", + max_iterations=2, + output_type="dict", + ) + + # Test with a problem that requires iterative refinement + task = "Design an efficient public transportation system for a small city" + result = agent.run(task) + + # Verify the result is valid + assert result is not None + assert isinstance(result, (str, dict)) + + # Check that conversation was populated during execution + assert agent.conversation is not None