Skip to content

Building AI agents, atomically

Added assert to agent running methods.

Koichi KAWAMURAe6beab95d7bc
diff --git a/atomic-agents/atomic_agents/agents/base_agent.py b/atomic-agents/atomic_agents/agents/base_agent.py
index 993710c..183e763 100644
--- a/atomic-agents/atomic_agents/agents/base_agent.py
+++ b/atomic-agents/atomic_agents/agents/base_agent.py
@@ -172,6 +172,9 @@ class BaseAgent:
Returns:
TO: The response from the chat agent.
"""
+ assert not isinstance(
+ self.client, instructor.client.AsyncInstructor
+ ), "The run method is not supported for async clients. Use run_async instead."
if user_input:
self.memory.initialize_turn()
self.current_user_input = user_input
@@ -201,6 +204,9 @@ class BaseAgent:
Returns:
TO: The final response from the chat agent.
"""
+ assert not isinstance(
+ self.client, instructor.client.AsyncInstructor
+ ), "The run_stream method is not supported for async clients. Use run_async instead."
if user_input:
self.memory.initialize_turn()
self.current_user_input = user_input
@@ -238,6 +244,7 @@ class BaseAgent:
NotAsyncIterableError: If used as an async generator (in an async for loop).
Use run_async_stream() method instead for streaming responses.
"""
+ assert isinstance(self.client, instructor.client.AsyncInstructor), "The run_async method is for async clients."
if user_input:
self.memory.initialize_turn()
self.current_user_input = user_input
@@ -262,6 +269,7 @@ class BaseAgent:
Yields:
TO: Partial responses from the chat agent.
"""
+ assert isinstance(self.client, instructor.client.AsyncInstructor), "The run_async method is for async clients."
if user_input:
self.memory.initialize_turn()
self.current_user_input = user_input
diff --git a/atomic-agents/tests/agents/test_base_agent.py b/atomic-agents/tests/agents/test_base_agent.py
index 99cacae..2879696 100644
--- a/atomic-agents/tests/agents/test_base_agent.py
+++ b/atomic-agents/tests/agents/test_base_agent.py
@@ -34,7 +34,8 @@ def mock_instructor():
@pytest.fixture
def mock_instructor_async():
- mock = Mock(spec=instructor.Instructor)
+ # Changed spec from instructor.Instructor to instructor.client.AsyncInstructor
+ mock = Mock(spec=instructor.client.AsyncInstructor)
# Configure chat.completions structure
mock.chat = Mock()