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:
lorenzejay
2025-05-05 21:37:48 -07:00
parent e54a470493
commit a9decb54c8
2 changed files with 6 additions and 15 deletions

View File

@@ -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,