mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-01-26 16:48:13 +00:00
fix: Improve knowledge context formatting for better LLM effectiveness
- Make knowledge context more explicit and instructive for LLM - Add clear instructions to use provided context - Add comprehensive test coverage for knowledge utils Fixes #2269 Co-Authored-By: Joe Moura <joao@crewai.com>
This commit is contained in:
@@ -2,11 +2,19 @@ from typing import Any, Dict, List
|
||||
|
||||
|
||||
def extract_knowledge_context(knowledge_snippets: List[Dict[str, Any]]) -> str:
|
||||
"""Extract knowledge from the task prompt."""
|
||||
"""Extract knowledge from the task prompt and format it for effective LLM usage."""
|
||||
valid_snippets = [
|
||||
result["context"]
|
||||
for result in knowledge_snippets
|
||||
if result and result.get("context")
|
||||
]
|
||||
if not valid_snippets:
|
||||
return ""
|
||||
|
||||
snippet = "\n".join(valid_snippets)
|
||||
return f"Additional Information: {snippet}" if valid_snippets else ""
|
||||
return (
|
||||
"Important Context (You MUST use this information to complete your task "
|
||||
"accurately and effectively):\n"
|
||||
f"{snippet}\n\n"
|
||||
"Make sure to incorporate the above context into your response."
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user