mirror of
https://github.com/crewAIInc/crewAI.git
synced 2026-07-03 06:08:15 +00:00
Fix formatting: run ruff format on all modified files
Co-Authored-By: João <joao@crewai.com>
This commit is contained in:
@@ -1310,8 +1310,10 @@ class Agent(BaseAgent):
|
||||
from_agent=self,
|
||||
),
|
||||
)
|
||||
query = get_crew_i18n().slice("knowledge_search_query").format(
|
||||
task_prompt=task_prompt
|
||||
query = (
|
||||
get_crew_i18n()
|
||||
.slice("knowledge_search_query")
|
||||
.format(task_prompt=task_prompt)
|
||||
)
|
||||
rewriter_prompt = get_crew_i18n().slice("knowledge_search_query_system_prompt")
|
||||
if not isinstance(self.llm, BaseLLM):
|
||||
@@ -1488,9 +1490,9 @@ class Agent(BaseAgent):
|
||||
m.format() for m in matches
|
||||
)
|
||||
if memory_block:
|
||||
formatted_messages += "\n\n" + get_crew_i18n().slice("memory").format(
|
||||
memory=memory_block
|
||||
)
|
||||
formatted_messages += "\n\n" + get_crew_i18n().slice(
|
||||
"memory"
|
||||
).format(memory=memory_block)
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
event=MemoryRetrievalCompletedEvent(
|
||||
@@ -1703,8 +1705,10 @@ class Agent(BaseAgent):
|
||||
try:
|
||||
model_schema = generate_model_description(response_format)
|
||||
schema = json.dumps(model_schema, indent=2)
|
||||
instructions = get_crew_i18n().slice("formatted_task_instructions").format(
|
||||
output_format=schema
|
||||
instructions = (
|
||||
get_crew_i18n()
|
||||
.slice("formatted_task_instructions")
|
||||
.format(output_format=schema)
|
||||
)
|
||||
|
||||
converter = Converter(
|
||||
|
||||
@@ -98,8 +98,10 @@ def format_task_with_context(task_prompt: str, context: str | None) -> str:
|
||||
from crewai.utilities.i18n import get_crew_i18n
|
||||
|
||||
if context:
|
||||
return get_crew_i18n().slice("task_with_context").format(
|
||||
task=task_prompt, context=context
|
||||
return (
|
||||
get_crew_i18n()
|
||||
.slice("task_with_context")
|
||||
.format(task=task_prompt, context=context)
|
||||
)
|
||||
return task_prompt
|
||||
|
||||
|
||||
@@ -190,8 +190,10 @@ class LangGraphAgentAdapter(BaseAgentAdapter):
|
||||
task_prompt = task.prompt() if hasattr(task, "prompt") else str(task)
|
||||
|
||||
if context:
|
||||
task_prompt = get_crew_i18n().slice("task_with_context").format(
|
||||
task=task_prompt, context=context
|
||||
task_prompt = (
|
||||
get_crew_i18n()
|
||||
.slice("task_with_context")
|
||||
.format(task=task_prompt, context=context)
|
||||
)
|
||||
|
||||
crewai_event_bus.emit(
|
||||
|
||||
@@ -137,8 +137,10 @@ class OpenAIAgentAdapter(BaseAgentAdapter):
|
||||
try:
|
||||
task_prompt: str = task.prompt()
|
||||
if context:
|
||||
task_prompt = get_crew_i18n().slice("task_with_context").format(
|
||||
task=task_prompt, context=context
|
||||
task_prompt = (
|
||||
get_crew_i18n()
|
||||
.slice("task_with_context")
|
||||
.format(task=task_prompt, context=context)
|
||||
)
|
||||
crewai_event_bus.emit(
|
||||
self,
|
||||
|
||||
@@ -59,8 +59,10 @@ class OpenAIConverterAdapter(BaseConverterAdapter):
|
||||
if not self._output_format:
|
||||
return base_prompt
|
||||
|
||||
output_schema: str = get_crew_i18n().slice("formatted_task_instructions").format(
|
||||
output_format=json.dumps(self._schema, indent=2)
|
||||
output_schema: str = (
|
||||
get_crew_i18n()
|
||||
.slice("formatted_task_instructions")
|
||||
.format(output_format=json.dumps(self._schema, indent=2))
|
||||
)
|
||||
|
||||
return f"{base_prompt}\n\n{output_schema}"
|
||||
|
||||
@@ -231,7 +231,9 @@ class PlannerObserver:
|
||||
task_desc = extract_task_section(self.kickoff_input)
|
||||
task_goal = "Complete the task successfully"
|
||||
|
||||
system_prompt = get_crew_i18n().retrieve("planning", "observation_system_prompt")
|
||||
system_prompt = get_crew_i18n().retrieve(
|
||||
"planning", "observation_system_prompt"
|
||||
)
|
||||
|
||||
completed_summary = ""
|
||||
if all_completed:
|
||||
@@ -256,16 +258,18 @@ class PlannerObserver:
|
||||
remaining_lines
|
||||
)
|
||||
|
||||
user_prompt = get_crew_i18n().retrieve(
|
||||
"planning", "observation_user_prompt"
|
||||
).format(
|
||||
task_description=task_desc,
|
||||
task_goal=task_goal,
|
||||
completed_summary=completed_summary,
|
||||
step_number=completed_step.step_number,
|
||||
step_description=completed_step.description,
|
||||
step_result=result,
|
||||
remaining_summary=remaining_summary,
|
||||
user_prompt = (
|
||||
get_crew_i18n()
|
||||
.retrieve("planning", "observation_user_prompt")
|
||||
.format(
|
||||
task_description=task_desc,
|
||||
task_goal=task_goal,
|
||||
completed_summary=completed_summary,
|
||||
step_number=completed_step.step_number,
|
||||
step_description=completed_step.description,
|
||||
step_result=result,
|
||||
remaining_summary=remaining_summary,
|
||||
)
|
||||
)
|
||||
|
||||
return [
|
||||
|
||||
@@ -210,18 +210,24 @@ class StepExecutor:
|
||||
tools_section = ""
|
||||
if self.tools and not self._use_native_tools:
|
||||
tool_names = ", ".join(sanitize_tool_name(t.name) for t in self.tools)
|
||||
tools_section = get_crew_i18n().retrieve(
|
||||
"planning", "step_executor_tools_section"
|
||||
).format(tool_names=tool_names)
|
||||
tools_section = (
|
||||
get_crew_i18n()
|
||||
.retrieve("planning", "step_executor_tools_section")
|
||||
.format(tool_names=tool_names)
|
||||
)
|
||||
elif self.tools:
|
||||
tool_names = ", ".join(sanitize_tool_name(t.name) for t in self.tools)
|
||||
tools_section = f"\n\nAvailable tools: {tool_names}"
|
||||
|
||||
return get_crew_i18n().retrieve("planning", "step_executor_system_prompt").format(
|
||||
role=role,
|
||||
backstory=backstory,
|
||||
goal=goal,
|
||||
tools_section=tools_section,
|
||||
return (
|
||||
get_crew_i18n()
|
||||
.retrieve("planning", "step_executor_system_prompt")
|
||||
.format(
|
||||
role=role,
|
||||
backstory=backstory,
|
||||
goal=goal,
|
||||
tools_section=tools_section,
|
||||
)
|
||||
)
|
||||
|
||||
def _build_user_prompt(self, todo: TodoItem, context: StepExecutionContext) -> str:
|
||||
@@ -232,24 +238,26 @@ class StepExecutor:
|
||||
task_section = extract_task_section(context.task_description)
|
||||
if task_section:
|
||||
parts.append(
|
||||
get_crew_i18n().retrieve(
|
||||
"planning", "step_executor_task_context"
|
||||
).format(
|
||||
get_crew_i18n()
|
||||
.retrieve("planning", "step_executor_task_context")
|
||||
.format(
|
||||
task_context=task_section,
|
||||
)
|
||||
)
|
||||
|
||||
parts.append(
|
||||
get_crew_i18n().retrieve("planning", "step_executor_user_prompt").format(
|
||||
get_crew_i18n()
|
||||
.retrieve("planning", "step_executor_user_prompt")
|
||||
.format(
|
||||
step_description=todo.description,
|
||||
)
|
||||
)
|
||||
|
||||
if todo.tool_to_use:
|
||||
parts.append(
|
||||
get_crew_i18n().retrieve(
|
||||
"planning", "step_executor_suggested_tool"
|
||||
).format(
|
||||
get_crew_i18n()
|
||||
.retrieve("planning", "step_executor_suggested_tool")
|
||||
.format(
|
||||
tool_to_use=todo.tool_to_use,
|
||||
)
|
||||
)
|
||||
@@ -260,12 +268,14 @@ class StepExecutor:
|
||||
)
|
||||
for step_num, result in sorted(context.dependency_results.items()):
|
||||
parts.append(
|
||||
get_crew_i18n().retrieve(
|
||||
"planning", "step_executor_context_entry"
|
||||
).format(step_number=step_num, result=result)
|
||||
get_crew_i18n()
|
||||
.retrieve("planning", "step_executor_context_entry")
|
||||
.format(step_number=step_num, result=result)
|
||||
)
|
||||
|
||||
parts.append(get_crew_i18n().retrieve("planning", "step_executor_complete_step"))
|
||||
parts.append(
|
||||
get_crew_i18n().retrieve("planning", "step_executor_complete_step")
|
||||
)
|
||||
|
||||
return "\n".join(parts)
|
||||
|
||||
|
||||
@@ -2220,12 +2220,18 @@ class AgentExecutor(Flow[AgentExecutorState], BaseAgentExecutor):
|
||||
# Build synthesis prompt
|
||||
role = self.agent.role if self.agent else "Assistant"
|
||||
|
||||
system_prompt = get_crew_i18n().retrieve(
|
||||
"planning", "synthesis_system_prompt"
|
||||
).format(role=role)
|
||||
user_prompt = get_crew_i18n().retrieve("planning", "synthesis_user_prompt").format(
|
||||
task_description=task_description,
|
||||
combined_steps=combined_steps,
|
||||
system_prompt = (
|
||||
get_crew_i18n()
|
||||
.retrieve("planning", "synthesis_system_prompt")
|
||||
.format(role=role)
|
||||
)
|
||||
user_prompt = (
|
||||
get_crew_i18n()
|
||||
.retrieve("planning", "synthesis_user_prompt")
|
||||
.format(
|
||||
task_description=task_description,
|
||||
combined_steps=combined_steps,
|
||||
)
|
||||
)
|
||||
|
||||
try:
|
||||
@@ -2470,9 +2476,11 @@ class AgentExecutor(Flow[AgentExecutorState], BaseAgentExecutor):
|
||||
self.task.description if self.task else getattr(self, "_kickoff_input", "")
|
||||
)
|
||||
|
||||
enhancement = get_crew_i18n().retrieve(
|
||||
"planning", "replan_enhancement_prompt"
|
||||
).format(previous_context=previous_context)
|
||||
enhancement = (
|
||||
get_crew_i18n()
|
||||
.retrieve("planning", "replan_enhancement_prompt")
|
||||
.format(previous_context=previous_context)
|
||||
)
|
||||
|
||||
return f"{original}{enhancement}"
|
||||
|
||||
|
||||
@@ -650,8 +650,10 @@ class LiteAgent(FlowTrackable, BaseModel):
|
||||
try:
|
||||
model_schema = generate_model_description(active_response_format)
|
||||
schema = json.dumps(model_schema, indent=2)
|
||||
instructions = get_crew_i18n().slice("formatted_task_instructions").format(
|
||||
output_format=schema
|
||||
instructions = (
|
||||
get_crew_i18n()
|
||||
.slice("formatted_task_instructions")
|
||||
.format(output_format=schema)
|
||||
)
|
||||
|
||||
converter = Converter(
|
||||
@@ -799,31 +801,37 @@ class LiteAgent(FlowTrackable, BaseModel):
|
||||
base_prompt = ""
|
||||
if self._parsed_tools:
|
||||
# Use the prompt template for agents with tools
|
||||
base_prompt = get_crew_i18n().slice(
|
||||
"lite_agent_system_prompt_with_tools"
|
||||
).format(
|
||||
role=self.role,
|
||||
backstory=self.backstory,
|
||||
goal=self.goal,
|
||||
tools=render_text_description_and_args(self._parsed_tools),
|
||||
tool_names=get_tool_names(self._parsed_tools),
|
||||
base_prompt = (
|
||||
get_crew_i18n()
|
||||
.slice("lite_agent_system_prompt_with_tools")
|
||||
.format(
|
||||
role=self.role,
|
||||
backstory=self.backstory,
|
||||
goal=self.goal,
|
||||
tools=render_text_description_and_args(self._parsed_tools),
|
||||
tool_names=get_tool_names(self._parsed_tools),
|
||||
)
|
||||
)
|
||||
else:
|
||||
# Use the prompt template for agents without tools
|
||||
base_prompt = get_crew_i18n().slice(
|
||||
"lite_agent_system_prompt_without_tools"
|
||||
).format(
|
||||
role=self.role,
|
||||
backstory=self.backstory,
|
||||
goal=self.goal,
|
||||
base_prompt = (
|
||||
get_crew_i18n()
|
||||
.slice("lite_agent_system_prompt_without_tools")
|
||||
.format(
|
||||
role=self.role,
|
||||
backstory=self.backstory,
|
||||
goal=self.goal,
|
||||
)
|
||||
)
|
||||
|
||||
active_response_format = response_format or self.response_format
|
||||
if active_response_format:
|
||||
model_description = generate_model_description(active_response_format)
|
||||
schema_json = json.dumps(model_description, indent=2)
|
||||
base_prompt += get_crew_i18n().slice("lite_agent_response_format").format(
|
||||
response_format=schema_json
|
||||
base_prompt += (
|
||||
get_crew_i18n()
|
||||
.slice("lite_agent_response_format")
|
||||
.format(response_format=schema_json)
|
||||
)
|
||||
|
||||
return base_prompt
|
||||
|
||||
@@ -970,8 +970,10 @@ class Task(BaseModel):
|
||||
|
||||
tasks_slices = [description]
|
||||
|
||||
output = get_crew_i18n().slice("expected_output").format(
|
||||
expected_output=self.expected_output
|
||||
output = (
|
||||
get_crew_i18n()
|
||||
.slice("expected_output")
|
||||
.format(expected_output=self.expected_output)
|
||||
)
|
||||
tasks_slices = [description, output]
|
||||
|
||||
@@ -1318,9 +1320,13 @@ Follow these guidelines:
|
||||
self.retry_count += 1
|
||||
current_retry_count = self.retry_count
|
||||
|
||||
context = get_crew_i18n().errors("validation_error").format(
|
||||
guardrail_result_error=guardrail_result.error,
|
||||
task_output=task_output.raw,
|
||||
context = (
|
||||
get_crew_i18n()
|
||||
.errors("validation_error")
|
||||
.format(
|
||||
guardrail_result_error=guardrail_result.error,
|
||||
task_output=task_output.raw,
|
||||
)
|
||||
)
|
||||
if agent and agent.verbose:
|
||||
PRINTER.print(
|
||||
@@ -1429,9 +1435,13 @@ Follow these guidelines:
|
||||
self.retry_count += 1
|
||||
current_retry_count = self.retry_count
|
||||
|
||||
context = get_crew_i18n().errors("validation_error").format(
|
||||
guardrail_result_error=guardrail_result.error,
|
||||
task_output=task_output.raw,
|
||||
context = (
|
||||
get_crew_i18n()
|
||||
.errors("validation_error")
|
||||
.format(
|
||||
guardrail_result_error=guardrail_result.error,
|
||||
task_output=task_output.raw,
|
||||
)
|
||||
)
|
||||
if agent and agent.verbose:
|
||||
PRINTER.print(
|
||||
|
||||
@@ -16,7 +16,9 @@ class AddImageToolSchema(BaseModel):
|
||||
class AddImageTool(BaseTool):
|
||||
"""Tool for adding images to the content"""
|
||||
|
||||
name: str = Field(default_factory=lambda: get_crew_i18n().tools("add_image")["name"]) # type: ignore[index]
|
||||
name: str = Field(
|
||||
default_factory=lambda: get_crew_i18n().tools("add_image")["name"]
|
||||
) # type: ignore[index]
|
||||
description: str = Field(
|
||||
default_factory=lambda: get_crew_i18n().tools("add_image")["description"] # type: ignore[index]
|
||||
)
|
||||
|
||||
@@ -25,12 +25,16 @@ class AgentTools:
|
||||
|
||||
delegate_tool = DelegateWorkTool(
|
||||
agents=self.agents,
|
||||
description=get_crew_i18n().tools("delegate_work").format(coworkers=coworkers), # type: ignore
|
||||
description=get_crew_i18n()
|
||||
.tools("delegate_work")
|
||||
.format(coworkers=coworkers), # type: ignore
|
||||
)
|
||||
|
||||
ask_tool = AskQuestionTool(
|
||||
agents=self.agents,
|
||||
description=get_crew_i18n().tools("ask_question").format(coworkers=coworkers), # type: ignore
|
||||
description=get_crew_i18n()
|
||||
.tools("ask_question")
|
||||
.format(coworkers=coworkers), # type: ignore
|
||||
)
|
||||
|
||||
return [delegate_tool, ask_tool]
|
||||
|
||||
@@ -90,26 +90,34 @@ class BaseAgentTool(BaseTool):
|
||||
)
|
||||
except (AttributeError, ValueError) as e:
|
||||
# Handle specific exceptions that might occur during role name processing
|
||||
return get_crew_i18n().errors("agent_tool_unexisting_coworker").format(
|
||||
coworkers="\n".join(
|
||||
[
|
||||
f"- {self.sanitize_agent_name(agent.role)}"
|
||||
for agent in self.agents
|
||||
]
|
||||
),
|
||||
error=str(e),
|
||||
return (
|
||||
get_crew_i18n()
|
||||
.errors("agent_tool_unexisting_coworker")
|
||||
.format(
|
||||
coworkers="\n".join(
|
||||
[
|
||||
f"- {self.sanitize_agent_name(agent.role)}"
|
||||
for agent in self.agents
|
||||
]
|
||||
),
|
||||
error=str(e),
|
||||
)
|
||||
)
|
||||
|
||||
if not agent:
|
||||
# No matching agent found after sanitization
|
||||
return get_crew_i18n().errors("agent_tool_unexisting_coworker").format(
|
||||
coworkers="\n".join(
|
||||
[
|
||||
f"- {self.sanitize_agent_name(agent.role)}"
|
||||
for agent in self.agents
|
||||
]
|
||||
),
|
||||
error=f"No agent found with role '{sanitized_name}'",
|
||||
return (
|
||||
get_crew_i18n()
|
||||
.errors("agent_tool_unexisting_coworker")
|
||||
.format(
|
||||
coworkers="\n".join(
|
||||
[
|
||||
f"- {self.sanitize_agent_name(agent.role)}"
|
||||
for agent in self.agents
|
||||
]
|
||||
),
|
||||
error=f"No agent found with role '{sanitized_name}'",
|
||||
)
|
||||
)
|
||||
|
||||
selected_agent = agent[0]
|
||||
@@ -125,6 +133,11 @@ class BaseAgentTool(BaseTool):
|
||||
return selected_agent.execute_task(task_with_assigned_agent, context)
|
||||
except Exception as e:
|
||||
# Handle task creation or execution errors
|
||||
return get_crew_i18n().errors("agent_tool_execution_error").format(
|
||||
agent_role=self.sanitize_agent_name(selected_agent.role), error=str(e)
|
||||
return (
|
||||
get_crew_i18n()
|
||||
.errors("agent_tool_execution_error")
|
||||
.format(
|
||||
agent_role=self.sanitize_agent_name(selected_agent.role),
|
||||
error=str(e),
|
||||
)
|
||||
)
|
||||
|
||||
@@ -229,8 +229,10 @@ class ToolUsage:
|
||||
"""
|
||||
if self._check_tool_repeated_usage(calling=calling):
|
||||
try:
|
||||
result = get_crew_i18n().errors("task_repeated_usage").format(
|
||||
tool_names=self.tools_names
|
||||
result = (
|
||||
get_crew_i18n()
|
||||
.errors("task_repeated_usage")
|
||||
.format(tool_names=self.tools_names)
|
||||
)
|
||||
self._telemetry.tool_repeated_usage(
|
||||
llm=self.function_calling_llm,
|
||||
@@ -414,12 +416,14 @@ class ToolUsage:
|
||||
self._run_attempts += 1
|
||||
if self._run_attempts > self._max_parsing_attempts:
|
||||
self._telemetry.tool_usage_error(llm=self.function_calling_llm)
|
||||
error_message = get_crew_i18n().errors(
|
||||
"tool_usage_exception"
|
||||
).format(
|
||||
error=e,
|
||||
tool=sanitize_tool_name(tool.name),
|
||||
tool_inputs=tool.description,
|
||||
error_message = (
|
||||
get_crew_i18n()
|
||||
.errors("tool_usage_exception")
|
||||
.format(
|
||||
error=e,
|
||||
tool=sanitize_tool_name(tool.name),
|
||||
tool_inputs=tool.description,
|
||||
)
|
||||
)
|
||||
result = ToolUsageError(
|
||||
f"\n{error_message}.\nMoving on then. {get_crew_i18n().slice('format').format(tool_names=self.tools_names)}"
|
||||
@@ -460,8 +464,10 @@ class ToolUsage:
|
||||
# Repeated usage check happens before event emission - safe to return early
|
||||
if self._check_tool_repeated_usage(calling=calling):
|
||||
try:
|
||||
result = get_crew_i18n().errors("task_repeated_usage").format(
|
||||
tool_names=self.tools_names
|
||||
result = (
|
||||
get_crew_i18n()
|
||||
.errors("task_repeated_usage")
|
||||
.format(tool_names=self.tools_names)
|
||||
)
|
||||
self._telemetry.tool_repeated_usage(
|
||||
llm=self.function_calling_llm,
|
||||
@@ -647,12 +653,14 @@ class ToolUsage:
|
||||
self._run_attempts += 1
|
||||
if self._run_attempts > self._max_parsing_attempts:
|
||||
self._telemetry.tool_usage_error(llm=self.function_calling_llm)
|
||||
error_message = get_crew_i18n().errors(
|
||||
"tool_usage_exception"
|
||||
).format(
|
||||
error=e,
|
||||
tool=sanitize_tool_name(tool.name),
|
||||
tool_inputs=tool.description,
|
||||
error_message = (
|
||||
get_crew_i18n()
|
||||
.errors("tool_usage_exception")
|
||||
.format(
|
||||
error=e,
|
||||
tool=sanitize_tool_name(tool.name),
|
||||
tool_inputs=tool.description,
|
||||
)
|
||||
)
|
||||
result = ToolUsageError(
|
||||
f"\n{error_message}.\nMoving on then. {get_crew_i18n().slice('format').format(tool_names=self.tools_names)}"
|
||||
|
||||
@@ -905,9 +905,9 @@ async def _asummarize_chunks(
|
||||
get_crew_i18n().slice("summarizer_system_message"), role="system"
|
||||
),
|
||||
format_message_for_llm(
|
||||
get_crew_i18n().slice("summarize_instruction").format(
|
||||
conversation=conversation_text
|
||||
),
|
||||
get_crew_i18n()
|
||||
.slice("summarize_instruction")
|
||||
.format(conversation=conversation_text),
|
||||
),
|
||||
]
|
||||
summary = await llm.acall(summarization_messages, callbacks=callbacks)
|
||||
@@ -975,9 +975,9 @@ def summarize_messages(
|
||||
get_crew_i18n().slice("summarizer_system_message"), role="system"
|
||||
),
|
||||
format_message_for_llm(
|
||||
get_crew_i18n().slice("summarize_instruction").format(
|
||||
conversation=conversation_text
|
||||
),
|
||||
get_crew_i18n()
|
||||
.slice("summarize_instruction")
|
||||
.format(conversation=conversation_text),
|
||||
),
|
||||
]
|
||||
summary = llm.call(summarization_messages, callbacks=callbacks)
|
||||
|
||||
@@ -24,7 +24,6 @@ if TYPE_CHECKING:
|
||||
_JSON_PATTERN: Final[re.Pattern[str]] = re.compile(r"({.*})", re.DOTALL)
|
||||
|
||||
|
||||
|
||||
class ConverterError(Exception):
|
||||
"""Error raised when Converter fails to parse the input."""
|
||||
|
||||
@@ -548,15 +547,19 @@ def get_conversion_instructions(
|
||||
):
|
||||
schema_dict = generate_model_description(model)
|
||||
schema = json.dumps(schema_dict, indent=2)
|
||||
formatted_task_instructions = get_crew_i18n().slice("formatted_task_instructions").format(
|
||||
output_format=schema
|
||||
formatted_task_instructions = (
|
||||
get_crew_i18n()
|
||||
.slice("formatted_task_instructions")
|
||||
.format(output_format=schema)
|
||||
)
|
||||
instructions += formatted_task_instructions
|
||||
else:
|
||||
model_description = generate_model_description(model)
|
||||
schema_json = json.dumps(model_description, indent=2)
|
||||
formatted_task_instructions = get_crew_i18n().slice("formatted_task_instructions").format(
|
||||
output_format=schema_json
|
||||
formatted_task_instructions = (
|
||||
get_crew_i18n()
|
||||
.slice("formatted_task_instructions")
|
||||
.format(output_format=schema_json)
|
||||
)
|
||||
instructions += formatted_task_instructions
|
||||
return instructions
|
||||
|
||||
@@ -98,9 +98,11 @@ class TaskEvaluator:
|
||||
|
||||
if not self.llm.supports_function_calling(): # type: ignore[union-attr]
|
||||
schema_dict = generate_model_description(TaskEvaluation)
|
||||
output_schema: str = get_crew_i18n().slice(
|
||||
"formatted_task_instructions"
|
||||
).format(output_format=json.dumps(schema_dict, indent=2))
|
||||
output_schema: str = (
|
||||
get_crew_i18n()
|
||||
.slice("formatted_task_instructions")
|
||||
.format(output_format=json.dumps(schema_dict, indent=2))
|
||||
)
|
||||
instructions = f"{instructions}\n\n{output_schema}"
|
||||
|
||||
converter = Converter(
|
||||
@@ -172,9 +174,11 @@ class TaskEvaluator:
|
||||
|
||||
if not self.llm.supports_function_calling(): # type: ignore[union-attr]
|
||||
schema_dict = generate_model_description(TrainingTaskEvaluation)
|
||||
output_schema: str = get_crew_i18n().slice(
|
||||
"formatted_task_instructions"
|
||||
).format(output_format=json.dumps(schema_dict, indent=2))
|
||||
output_schema: str = (
|
||||
get_crew_i18n()
|
||||
.slice("formatted_task_instructions")
|
||||
.format(output_format=json.dumps(schema_dict, indent=2))
|
||||
)
|
||||
instructions = f"{instructions}\n\n{output_schema}"
|
||||
|
||||
converter = TrainingConverter(
|
||||
|
||||
@@ -492,10 +492,14 @@ class AgentReasoning:
|
||||
return get_crew_i18n().retrieve("planning", "system_prompt")
|
||||
except (KeyError, AttributeError):
|
||||
# Fallback to reasoning section for backward compatibility
|
||||
return get_crew_i18n().retrieve("reasoning", "initial_plan").format(
|
||||
role=self.agent.role,
|
||||
goal=self.agent.goal,
|
||||
backstory=self._get_agent_backstory(),
|
||||
return (
|
||||
get_crew_i18n()
|
||||
.retrieve("reasoning", "initial_plan")
|
||||
.format(
|
||||
role=self.agent.role,
|
||||
goal=self.agent.goal,
|
||||
backstory=self._get_agent_backstory(),
|
||||
)
|
||||
)
|
||||
|
||||
def _get_agent_backstory(self) -> str:
|
||||
@@ -528,21 +532,29 @@ class AgentReasoning:
|
||||
|
||||
# Try new "planning" section first
|
||||
try:
|
||||
return get_crew_i18n().retrieve("planning", "create_plan_prompt").format(
|
||||
description=self.description,
|
||||
expected_output=self.expected_output,
|
||||
tools=available_tools,
|
||||
max_steps=self.config.max_steps,
|
||||
return (
|
||||
get_crew_i18n()
|
||||
.retrieve("planning", "create_plan_prompt")
|
||||
.format(
|
||||
description=self.description,
|
||||
expected_output=self.expected_output,
|
||||
tools=available_tools,
|
||||
max_steps=self.config.max_steps,
|
||||
)
|
||||
)
|
||||
except (KeyError, AttributeError):
|
||||
# Fallback to reasoning section for backward compatibility
|
||||
return get_crew_i18n().retrieve("reasoning", "create_plan_prompt").format(
|
||||
role=self.agent.role,
|
||||
goal=self.agent.goal,
|
||||
backstory=self._get_agent_backstory(),
|
||||
description=self.description,
|
||||
expected_output=self.expected_output,
|
||||
tools=available_tools,
|
||||
return (
|
||||
get_crew_i18n()
|
||||
.retrieve("reasoning", "create_plan_prompt")
|
||||
.format(
|
||||
role=self.agent.role,
|
||||
goal=self.agent.goal,
|
||||
backstory=self._get_agent_backstory(),
|
||||
description=self.description,
|
||||
expected_output=self.expected_output,
|
||||
tools=available_tools,
|
||||
)
|
||||
)
|
||||
|
||||
def _format_available_tools(self) -> str:
|
||||
@@ -585,16 +597,24 @@ class AgentReasoning:
|
||||
|
||||
# Try new "planning" section first
|
||||
try:
|
||||
return get_crew_i18n().retrieve("planning", "refine_plan_prompt").format(
|
||||
current_plan=current_plan,
|
||||
return (
|
||||
get_crew_i18n()
|
||||
.retrieve("planning", "refine_plan_prompt")
|
||||
.format(
|
||||
current_plan=current_plan,
|
||||
)
|
||||
)
|
||||
except (KeyError, AttributeError):
|
||||
# Fallback to reasoning section for backward compatibility
|
||||
return get_crew_i18n().retrieve("reasoning", "refine_plan_prompt").format(
|
||||
role=self.agent.role,
|
||||
goal=self.agent.goal,
|
||||
backstory=self._get_agent_backstory(),
|
||||
current_plan=current_plan,
|
||||
return (
|
||||
get_crew_i18n()
|
||||
.retrieve("reasoning", "refine_plan_prompt")
|
||||
.format(
|
||||
role=self.agent.role,
|
||||
goal=self.agent.goal,
|
||||
backstory=self._get_agent_backstory(),
|
||||
current_plan=current_plan,
|
||||
)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
@@ -643,10 +663,14 @@ def _call_llm_with_reasoning_prompt(
|
||||
Returns:
|
||||
The LLM response.
|
||||
"""
|
||||
system_prompt = get_crew_i18n().retrieve("reasoning", plan_type).format(
|
||||
role=reasoning_agent.role,
|
||||
goal=reasoning_agent.goal,
|
||||
backstory=backstory,
|
||||
system_prompt = (
|
||||
get_crew_i18n()
|
||||
.retrieve("reasoning", plan_type)
|
||||
.format(
|
||||
role=reasoning_agent.role,
|
||||
goal=reasoning_agent.goal,
|
||||
backstory=backstory,
|
||||
)
|
||||
)
|
||||
|
||||
response = llm.call(
|
||||
|
||||
@@ -140,9 +140,13 @@ async def aexecute_tool_and_check_finality(
|
||||
|
||||
return ToolResult(modified_result, tool.result_as_answer)
|
||||
|
||||
tool_result = get_crew_i18n().errors("wrong_tool_name").format(
|
||||
tool=sanitized_tool_name,
|
||||
tools=", ".join(tool_name_to_tool_map.keys()),
|
||||
tool_result = (
|
||||
get_crew_i18n()
|
||||
.errors("wrong_tool_name")
|
||||
.format(
|
||||
tool=sanitized_tool_name,
|
||||
tools=", ".join(tool_name_to_tool_map.keys()),
|
||||
)
|
||||
)
|
||||
return ToolResult(result=tool_result, result_as_answer=False)
|
||||
|
||||
@@ -259,8 +263,12 @@ def execute_tool_and_check_finality(
|
||||
|
||||
return ToolResult(modified_result, tool.result_as_answer)
|
||||
|
||||
tool_result = get_crew_i18n().errors("wrong_tool_name").format(
|
||||
tool=sanitized_tool_name,
|
||||
tools=", ".join(tool_name_to_tool_map.keys()),
|
||||
tool_result = (
|
||||
get_crew_i18n()
|
||||
.errors("wrong_tool_name")
|
||||
.format(
|
||||
tool=sanitized_tool_name,
|
||||
tools=", ".join(tool_name_to_tool_map.keys()),
|
||||
)
|
||||
)
|
||||
return ToolResult(result=tool_result, result_as_answer=False)
|
||||
|
||||
Reference in New Issue
Block a user