|
|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
|
|
# from unittest.mock import Mock, patch
|
|
|
|
|
|
|
|
|
|
from swarms.structs.agent_router import AgentRouter
|
|
|
|
|
@ -133,9 +133,13 @@ def test_add_agent_success():
|
|
|
|
|
def streaming_callback(chunk: str):
|
|
|
|
|
streamed_chunks.append(chunk)
|
|
|
|
|
|
|
|
|
|
response = agent.run("Say hello", streaming_callback=streaming_callback)
|
|
|
|
|
response = agent.run(
|
|
|
|
|
"Say hello", streaming_callback=streaming_callback
|
|
|
|
|
)
|
|
|
|
|
assert response is not None
|
|
|
|
|
assert len(streamed_chunks) > 0 or response != "", "Agent should stream or return response"
|
|
|
|
|
assert (
|
|
|
|
|
len(streamed_chunks) > 0 or response != ""
|
|
|
|
|
), "Agent should stream or return response"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_add_agents_multiple():
|
|
|
|
|
@ -181,9 +185,13 @@ def test_add_agents_multiple():
|
|
|
|
|
def streaming_callback(chunk: str):
|
|
|
|
|
streamed_chunks.append(chunk)
|
|
|
|
|
|
|
|
|
|
response = agent.run("Say hi", streaming_callback=streaming_callback)
|
|
|
|
|
response = agent.run(
|
|
|
|
|
"Say hi", streaming_callback=streaming_callback
|
|
|
|
|
)
|
|
|
|
|
assert response is not None
|
|
|
|
|
assert len(streamed_chunks) > 0 or response != "", f"Agent {agent.agent_name} should stream or return response"
|
|
|
|
|
assert (
|
|
|
|
|
len(streamed_chunks) > 0 or response != ""
|
|
|
|
|
), f"Agent {agent.agent_name} should stream or return response"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_find_best_agent_success():
|
|
|
|
|
@ -224,9 +232,13 @@ def test_find_best_agent_success():
|
|
|
|
|
def streaming_callback(chunk: str):
|
|
|
|
|
streamed_chunks.append(chunk)
|
|
|
|
|
|
|
|
|
|
response = result.run("Test task", streaming_callback=streaming_callback)
|
|
|
|
|
response = result.run(
|
|
|
|
|
"Test task", streaming_callback=streaming_callback
|
|
|
|
|
)
|
|
|
|
|
assert response is not None
|
|
|
|
|
assert len(streamed_chunks) > 0 or response != "", "Found agent should stream or return response"
|
|
|
|
|
assert (
|
|
|
|
|
len(streamed_chunks) > 0 or response != ""
|
|
|
|
|
), "Found agent should stream or return response"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_find_best_agent_no_agents():
|
|
|
|
|
@ -260,7 +272,9 @@ def test_update_agent_history_success():
|
|
|
|
|
def streaming_callback(chunk: str):
|
|
|
|
|
streamed_chunks.append(chunk)
|
|
|
|
|
|
|
|
|
|
agent.run("Hello, how are you?", streaming_callback=streaming_callback)
|
|
|
|
|
agent.run(
|
|
|
|
|
"Hello, how are you?", streaming_callback=streaming_callback
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# Update agent history
|
|
|
|
|
router.update_agent_history("test_agent")
|
|
|
|
|
@ -356,9 +370,14 @@ def test_router_with_agent_streaming():
|
|
|
|
|
if chunk:
|
|
|
|
|
streamed_chunks.append(chunk)
|
|
|
|
|
|
|
|
|
|
response = agent.run("Tell me a short joke", streaming_callback=streaming_callback)
|
|
|
|
|
response = agent.run(
|
|
|
|
|
"Tell me a short joke",
|
|
|
|
|
streaming_callback=streaming_callback,
|
|
|
|
|
)
|
|
|
|
|
assert response is not None
|
|
|
|
|
assert len(streamed_chunks) > 0 or response != "", f"Agent {agent.agent_name} should stream"
|
|
|
|
|
assert (
|
|
|
|
|
len(streamed_chunks) > 0 or response != ""
|
|
|
|
|
), f"Agent {agent.agent_name} should stream"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def test_router_find_and_run_with_streaming():
|
|
|
|
|
@ -400,9 +419,13 @@ def test_router_find_and_run_with_streaming():
|
|
|
|
|
if chunk:
|
|
|
|
|
streamed_chunks.append(chunk)
|
|
|
|
|
|
|
|
|
|
response = best_agent.run("What is 2 + 2?", streaming_callback=streaming_callback)
|
|
|
|
|
response = best_agent.run(
|
|
|
|
|
"What is 2 + 2?", streaming_callback=streaming_callback
|
|
|
|
|
)
|
|
|
|
|
assert response is not None
|
|
|
|
|
assert len(streamed_chunks) > 0 or response != "", "Best agent should stream when run"
|
|
|
|
|
assert (
|
|
|
|
|
len(streamed_chunks) > 0 or response != ""
|
|
|
|
|
), "Best agent should stream when run"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
|
@ -444,6 +467,7 @@ if __name__ == "__main__":
|
|
|
|
|
print(f"✗ FAILED: {test_func.__name__}")
|
|
|
|
|
print(f" Error: {str(e)}")
|
|
|
|
|
import traceback
|
|
|
|
|
|
|
|
|
|
traceback.print_exc()
|
|
|
|
|
failed += 1
|
|
|
|
|
|
|
|
|
|
|