feat: Add validation and improve documentation for embedder_config

- Add validation for embedder_config in Agent class
- Add test cases for invalid embedder configurations
- Improve docstrings with examples and error cases

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-02-19 15:28:34 +00:00
parent 59977a5f7c
commit 566ea3ced8
3 changed files with 53 additions and 3 deletions

View File

@@ -36,6 +36,26 @@ def mock_vector_db():
instance.reset.return_value = None
yield instance
def test_agent_invalid_embedder_config():
"""Test that an invalid embedder configuration raises a ValueError."""
with pytest.raises(ValueError, match="embedder_config must contain 'provider' key"):
Agent(
role="test role",
goal="test goal",
backstory="test backstory",
knowledge_sources=[StringKnowledgeSource(content="test content")],
embedder_config={"invalid": "config"}
)
with pytest.raises(ValueError, match="embedder_config must contain 'config' key"):
Agent(
role="test role",
goal="test goal",
backstory="test backstory",
knowledge_sources=[StringKnowledgeSource(content="test content")],
embedder_config={"provider": "custom"}
)
def test_agent_knowledge_with_custom_embedder(mock_vector_db):
agent = Agent(
role="test role",