Building AI agents, atomically
feat: add Eden AI as a provider option
Victor M. SMITH48a42e9072d1
diff --git a/README.md b/README.mdindex d0fed80..ba505fa 100644--- a/README.md+++ b/README.md@@ -402,7 +402,7 @@ uv sync --all-packages## Provider & Model Compatibility-Atomic Agents depends on the [Instructor](https://github.com/jxnl/instructor) package. This means that in all examples where OpenAI is used, any other API supported by Instructor can also be used, such as Ollama, Groq, Mistral, Cohere, Anthropic, Gemini, [MiniMax](https://www.minimax.io/), and more. For a complete list, please refer to the Instructor documentation on its [GitHub page](https://github.com/jxnl/instructor).+Atomic Agents depends on the [Instructor](https://github.com/jxnl/instructor) package. This means that in all examples where OpenAI is used, any other API supported by Instructor can also be used, such as Ollama, Groq, Mistral, Cohere, Anthropic, Gemini, [MiniMax](https://www.minimax.io/), [Eden AI](https://www.edenai.co/), and more. For a complete list, please refer to the Instructor documentation on its [GitHub page](https://github.com/jxnl/instructor).## Supportdiff --git a/atomic-agents/tests/agents/test_edenai_integration.py b/atomic-agents/tests/agents/test_edenai_integration.pynew file mode 100644index 0000000..6999276--- /dev/null+++ b/atomic-agents/tests/agents/test_edenai_integration.py@@ -0,0 +1,79 @@+"""Integration tests for Eden AI provider with Atomic Agents.++These tests require a valid EDENAI_API_KEY environment variable.+Run with: pytest -m integration tests/agents/test_edenai_integration.py+"""++import os+import pytest+import instructor+from pydantic import Field+from atomic_agents import (+ AtomicAgent,+ AgentConfig,+ BasicChatInputSchema,+ BasicChatOutputSchema,+ BaseIOSchema,+)++pytestmark = pytest.mark.skipif(+ not os.getenv("EDENAI_API_KEY"),+ reason="EDENAI_API_KEY not set",+)+++def _make_edenai_agent(model="openai/gpt-4o-mini", **agent_kwargs):+ """Helper to create an Eden AI-backed agent."""+ from openai import OpenAI++ raw = OpenAI(+ base_url="https://api.edenai.run/v3",+ api_key=os.environ["EDENAI_API_KEY"],+ )+ client = instructor.from_openai(raw)+ config = AgentConfig(client=client, model=model, **agent_kwargs)+ return AtomicAgent[BasicChatInputSchema, BasicChatOutputSchema](config)+++class TestEdenAILiveChat:+ """Live integration tests against Eden AI API."""++ def test_basic_chat(self):+ """Test a basic chat completion with Eden AI."""+ agent = _make_edenai_agent()+ response = agent.run(BasicChatInputSchema(chat_message="Say hello in one word."))+ assert response.chat_message+ assert len(response.chat_message) > 0++ def test_multi_turn_conversation(self):+ """Test multi-turn conversation with Eden AI."""+ agent = _make_edenai_agent()+ r1 = agent.run(BasicChatInputSchema(chat_message="Remember the number 42."))+ assert r1.chat_message # first response should be non-empty+ r2 = agent.run(BasicChatInputSchema(chat_message="What number did I ask you to remember?"))+ assert r2.chat_message+ # The model should recall "42" from the conversation history+ assert "42" in r2.chat_message++ def test_custom_output_schema(self):+ """Test structured output with a custom schema via Eden AI."""+ from openai import OpenAI++ class AnalysisOutput(BaseIOSchema):+ """Analysis output schema."""++ sentiment: str = Field(..., description="One of: positive, negative, neutral")+ confidence: float = Field(..., description="Confidence score between 0 and 1")++ raw = OpenAI(+ base_url="https://api.edenai.run/v3",+ api_key=os.environ["EDENAI_API_KEY"],+ )+ client = instructor.from_openai(raw)+ config = AgentConfig(client=client, model="openai/gpt-4o-mini")+ agent = AtomicAgent[BasicChatInputSchema, AnalysisOutput](config)++ response = agent.run(BasicChatInputSchema(chat_message="I love this product, it's amazing!"))+ assert response.sentiment in ("positive", "negative", "neutral")+ assert 0 <= response.confidence <= 1diff --git a/atomic-agents/tests/agents/test_edenai_provider.py b/atomic-agents/tests/agents/test_edenai_provider.pynew file mode 100644index 0000000..3130421--- /dev/null+++ b/atomic-agents/tests/agents/test_edenai_provider.py@@ -0,0 +1,171 @@+"""Unit tests for Eden AI provider integration with Atomic Agents."""++import os+import pytest+from unittest.mock import Mock, patch+import instructor+from atomic_agents import (+ AtomicAgent,+ AgentConfig,+ BasicChatInputSchema,+ BasicChatOutputSchema,+)+from atomic_agents.context import SystemPromptGenerator+++def _create_edenai_client(api_key="test-key"):+ """Create an Eden AI client via OpenAI-compatible interface."""+ from openai import OpenAI++ return instructor.from_openai(OpenAI(base_url="https://api.edenai.run/v3", api_key=api_key))+++class TestEdenAIClientSetup:+ """Tests for Eden AI client initialization."""++ def test_edenai_client_creation(self):+ """Test that Eden AI client can be created with correct base_url."""+ from openai import OpenAI++ raw_client = OpenAI(base_url="https://api.edenai.run/v3", api_key="test-key")+ assert raw_client.base_url == "https://api.edenai.run/v3/"++ def test_edenai_instructor_wrapping(self):+ """Test that Eden AI client can be wrapped with instructor."""+ client = _create_edenai_client()+ assert isinstance(client, instructor.Instructor)++ def test_edenai_agent_config(self):+ """Test that AgentConfig accepts Eden AI client and model."""+ client = _create_edenai_client()+ config = AgentConfig(+ client=client,+ model="openai/gpt-4o-mini",+ )+ assert config.model == "openai/gpt-4o-mini"+ assert config.assistant_role == "assistant"++ def test_edenai_agent_initialization(self):+ """Test that AtomicAgent can be initialized with Eden AI config."""+ client = _create_edenai_client()+ config = AgentConfig(+ client=client,+ model="openai/gpt-4o-mini",+ )+ agent = AtomicAgent[BasicChatInputSchema, BasicChatOutputSchema](config)+ assert agent.model == "openai/gpt-4o-mini"+ assert agent.assistant_role == "assistant"++ def test_edenai_vendor_prefixed_model(self):+ """Test that a different vendor-prefixed Eden AI model id works."""+ client = _create_edenai_client()+ config = AgentConfig(+ client=client,+ model="anthropic/claude-haiku-4-5",+ )+ agent = AtomicAgent[BasicChatInputSchema, BasicChatOutputSchema](config)+ assert agent.model == "anthropic/claude-haiku-4-5"+++class TestEdenAIAgentBehavior:+ """Tests for agent behavior with Eden AI provider."""++ @pytest.fixture+ def mock_edenai_instructor(self):+ mock = Mock(spec=instructor.Instructor)+ mock.chat = Mock()+ mock.chat.completions = Mock()+ mock.chat.completions.create = Mock(return_value=BasicChatOutputSchema(chat_message="Eden AI response"))+ mock_response = BasicChatOutputSchema(chat_message="Eden AI response")+ mock_iter = Mock()+ mock_iter.__iter__ = Mock(return_value=iter([mock_response]))+ mock.chat.completions.create_partial.return_value = mock_iter+ return mock++ @pytest.fixture+ def edenai_agent(self, mock_edenai_instructor):+ config = AgentConfig(+ client=mock_edenai_instructor,+ model="openai/gpt-4o-mini",+ )+ return AtomicAgent[BasicChatInputSchema, BasicChatOutputSchema](config)++ def test_run_with_edenai(self, edenai_agent, mock_edenai_instructor):+ """Test that agent.run works with Eden AI mock client."""+ user_input = BasicChatInputSchema(chat_message="Hello from Eden AI test")+ response = edenai_agent.run(user_input)+ assert response.chat_message == "Eden AI response"+ mock_edenai_instructor.chat.completions.create.assert_called_once()++ def test_run_passes_correct_model(self, edenai_agent, mock_edenai_instructor):+ """Test that the correct model name is passed to the API."""+ user_input = BasicChatInputSchema(chat_message="Test")+ edenai_agent.run(user_input)+ call_kwargs = mock_edenai_instructor.chat.completions.create.call_args+ assert call_kwargs.kwargs["model"] == "openai/gpt-4o-mini"++ def test_run_stream_with_edenai(self, edenai_agent):+ """Test that streaming works with Eden AI mock client."""+ user_input = BasicChatInputSchema(chat_message="Stream test")+ responses = list(edenai_agent.run_stream(user_input))+ assert len(responses) == 1+ assert responses[0].chat_message == "Eden AI response"++ def test_history_tracking_with_edenai(self, edenai_agent):+ """Test that chat history is properly tracked."""+ user_input = BasicChatInputSchema(chat_message="First message")+ edenai_agent.run(user_input)+ history = edenai_agent.history.get_history()+ assert len(history) == 2 # user + assistant++ def test_system_prompt_with_edenai(self, mock_edenai_instructor):+ """Test that system prompt works correctly with Eden AI."""+ spg = SystemPromptGenerator(+ background=["You are a helpful Eden AI-powered assistant."],+ )+ config = AgentConfig(+ client=mock_edenai_instructor,+ model="openai/gpt-4o-mini",+ system_prompt_generator=spg,+ )+ agent = AtomicAgent[BasicChatInputSchema, BasicChatOutputSchema](config)+ prompt = agent.system_prompt_generator.generate_prompt()+ assert "Eden AI" in prompt++ def test_model_api_parameters_with_edenai(self, mock_edenai_instructor):+ """Test that custom API parameters are passed through."""+ config = AgentConfig(+ client=mock_edenai_instructor,+ model="openai/gpt-4o-mini",+ model_api_parameters={"temperature": 0.7, "max_tokens": 1024},+ )+ agent = AtomicAgent[BasicChatInputSchema, BasicChatOutputSchema](config)+ assert agent.model_api_parameters["temperature"] == 0.7+ assert agent.model_api_parameters["max_tokens"] == 1024++ def test_edenai_reset_history(self, edenai_agent):+ """Test that history reset works with Eden AI agent."""+ user_input = BasicChatInputSchema(chat_message="Test")+ edenai_agent.run(user_input)+ edenai_agent.reset_history()+ history = edenai_agent.history.get_history()+ assert len(history) == 0+++class TestEdenAIProviderSetup:+ """Tests for the provider setup function from the quickstart example."""++ def test_setup_client_edenai_pattern(self):+ """Test the Eden AI client setup pattern used by the quickstart example."""+ from openai import OpenAI++ api_key = "test-edenai-key"+ raw_client = OpenAI(base_url="https://api.edenai.run/v3", api_key=api_key)+ client = instructor.from_openai(raw_client)+ assert isinstance(client, instructor.Instructor)++ def test_edenai_env_var_detection(self):+ """Test that EDENAI_API_KEY env var can be used."""+ with patch.dict(os.environ, {"EDENAI_API_KEY": "test-env-key"}):+ api_key = os.getenv("EDENAI_API_KEY")+ assert api_key == "test-env-key"diff --git a/atomic-examples/quickstart/quickstart/4_basic_chatbot_different_providers.py b/atomic-examples/quickstart/quickstart/4_basic_chatbot_different_providers.pyindex 7b27980..7f8d10e 100644--- a/atomic-examples/quickstart/quickstart/4_basic_chatbot_different_providers.py+++ b/atomic-examples/quickstart/quickstart/4_basic_chatbot_different_providers.py@@ -82,6 +82,14 @@ def setup_client(provider):model = "MiniMax-M3"model_api_parameters = {"max_tokens": 2048}assistant_role = "assistant"+ elif provider == "8" or provider == "edenai":+ from openai import OpenAI as EdenAIClient++ api_key = os.getenv("EDENAI_API_KEY")+ client = instructor.from_openai(EdenAIClient(base_url="https://api.edenai.run/v3", api_key=api_key))+ model = "openai/gpt-4o-mini"+ model_api_parameters = {"max_tokens": 2048}+ assistant_role = "assistant"else:raise ValueError(f"Unsupported provider: {provider}")@@ -89,7 +97,7 @@ def setup_client(provider):# Prompt the user to choose a provider from one in the list below.-providers_list = ["openai", "anthropic", "groq", "ollama", "gemini", "openrouter", "minimax"]+providers_list = ["openai", "anthropic", "groq", "ollama", "gemini", "openrouter", "minimax", "edenai"]y = "bold yellow"b = "bold blue"g = "bold green"