mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-02 07:42:40 +00:00
test: Add knowledge effectiveness test
- Add test to verify knowledge is effectively used in agent execution - Test checks that knowledge from agent is correctly used in response - Verifies fix for issue #2269 Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -36,4 +36,32 @@ def test_extract_knowledge_context_with_missing_context():
|
|||||||
"""Test extracting knowledge context with missing context."""
|
"""Test extracting knowledge context with missing context."""
|
||||||
snippets = [{"score": 0.9}, {"context": "Valid context"}]
|
snippets = [{"score": 0.9}, {"context": "Valid context"}]
|
||||||
result = extract_knowledge_context(snippets)
|
result = extract_knowledge_context(snippets)
|
||||||
assert result == "Additional Information: Valid context"
|
assert result == "Important Context (You MUST use this information to complete your task accurately and effectively):\nValid context\n\nMake sure to incorporate the above context into your response."
|
||||||
|
|
||||||
|
|
||||||
|
def test_knowledge_effectiveness():
|
||||||
|
"""Test that knowledge is effectively used in agent execution."""
|
||||||
|
from crewai import Agent, Task, Crew
|
||||||
|
from crewai.knowledge.source.string_knowledge_source import StringKnowledgeSource
|
||||||
|
|
||||||
|
content = "The capital of France is Paris. The Eiffel Tower is located in Paris."
|
||||||
|
string_source = StringKnowledgeSource(content=content)
|
||||||
|
|
||||||
|
agent = Agent(
|
||||||
|
role="Geography Expert",
|
||||||
|
goal="Answer questions about geography accurately",
|
||||||
|
backstory="You are an expert in geography",
|
||||||
|
knowledge_sources=[string_source],
|
||||||
|
)
|
||||||
|
|
||||||
|
task = Task(
|
||||||
|
description="What is the capital of France?",
|
||||||
|
expected_output="The capital of France",
|
||||||
|
agent=agent,
|
||||||
|
)
|
||||||
|
|
||||||
|
crew = Crew(agents=[agent], tasks=[task])
|
||||||
|
result = crew.kickoff()
|
||||||
|
|
||||||
|
assert "paris" in result.raw.lower()
|
||||||
|
assert "capital" in result.raw.lower()
|
||||||
|
|||||||
Reference in New Issue
Block a user