mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-05-03 00:02:36 +00:00
refactor: update knowledge query handling in Agent
This commit refines the knowledge query processing in the Agent class by renaming variables for clarity and optimizing the query rewriting logic. The system prompt has been updated in the translation file to enhance clarity and context for the query rewriting process. These changes aim to improve the overall readability and maintainability of the code.
This commit is contained in:
@@ -611,27 +611,18 @@ class Agent(BaseAgent):
|
||||
query = self.i18n.slice("knowledge_search_query").format(
|
||||
task_prompt=task_prompt
|
||||
)
|
||||
system_prompt = self.i18n.slice("knowledge_search_query_system_prompt")
|
||||
rewriter_prompt = self.i18n.slice("knowledge_search_query_system_prompt")
|
||||
if isinstance(self.llm, BaseLLM):
|
||||
try:
|
||||
query_converted = self.llm.call(
|
||||
rewritten_query = self.llm.call(
|
||||
[
|
||||
{
|
||||
"role": "system",
|
||||
"content": system_prompt,
|
||||
"content": rewriter_prompt,
|
||||
},
|
||||
{"role": "user", "content": query},
|
||||
]
|
||||
)
|
||||
query_rewritten = self.llm.call(
|
||||
[
|
||||
{
|
||||
"role": "system",
|
||||
"content": system_prompt,
|
||||
},
|
||||
{"role": "user", "content": query_converted},
|
||||
]
|
||||
)
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=KnowledgeQueryCompletedEvent(
|
||||
@@ -639,7 +630,7 @@ class Agent(BaseAgent):
|
||||
agent=self,
|
||||
),
|
||||
)
|
||||
return query_rewritten
|
||||
return rewritten_query
|
||||
except Exception as e:
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
|
||||
Reference in New Issue
Block a user