mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-16 03:28:30 +00:00
Implement context-aware knowledge search feature
- Add optional context parameter to _get_knowledge_search_query method - Update knowledge search query generation to include context from previous tasks - Add new prompt template for context-aware knowledge queries - Maintain backward compatibility with existing knowledge search - Add comprehensive tests for context-aware functionality - Addresses issue #3332 Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -1756,6 +1756,35 @@ def test_agent_with_knowledge_sources_with_query_limit_and_score_threshold():
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||
def test_agent_knowledge_search_with_context_parameter():
|
||||
"""Test that agent knowledge search accepts context parameter."""
|
||||
content = "Brandon's favorite color is red and he likes Mexican food."
|
||||
string_source = StringKnowledgeSource(content=content)
|
||||
|
||||
agent = Agent(
|
||||
role="Information Agent",
|
||||
goal="Provide information based on knowledge sources",
|
||||
backstory="You have access to specific knowledge sources.",
|
||||
llm=LLM(model="gpt-4o-mini"),
|
||||
knowledge_sources=[string_source],
|
||||
)
|
||||
|
||||
task_prompt = "What is Brandon's favorite color?"
|
||||
context = "Previous conversation mentioned Brandon's preferences."
|
||||
|
||||
with patch.object(agent.llm, 'call') as mock_call:
|
||||
mock_call.return_value = "Brandon likes red"
|
||||
result = agent._get_knowledge_search_query(task_prompt, context)
|
||||
|
||||
assert result == "Brandon likes red"
|
||||
mock_call.assert_called_once()
|
||||
|
||||
call_args = mock_call.call_args[0][0]
|
||||
user_message = call_args[1]['content']
|
||||
assert context in user_message
|
||||
|
||||
|
||||
@pytest.mark.vcr(filter_headers=["authorization"])
|
||||
def test_agent_with_knowledge_sources_with_query_limit_and_score_threshold_default():
|
||||
content = "Brandon's favorite color is red and he likes Mexican food."
|
||||
|
||||
Reference in New Issue
Block a user