fix: Include agent context in knowledge queries

- Add agent role, goal, and backstory to knowledge queries
- This helps retrieve more relevant knowledge based on agent context
- Improves knowledge effectiveness in agent execution

Part of #2269

Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
Devin AI
2025-03-04 04:17:00 +00:00
parent 121c3717b9
commit 07639dff30

View File

@@ -210,7 +210,13 @@ class Agent(BaseAgent):
task_prompt += self.i18n.slice("memory").format(memory=memory)
if self.knowledge:
agent_knowledge_snippets = self.knowledge.query([task.prompt()])
query_context = [
task.prompt(),
f"Role: {self.role}",
f"Goal: {self.goal}",
f"Backstory: {self.backstory}"
]
agent_knowledge_snippets = self.knowledge.query(query_context)
if agent_knowledge_snippets:
agent_knowledge_context = extract_knowledge_context(
agent_knowledge_snippets