From 822d1f999795dcead452c0ca56a5c49f084285b8 Mon Sep 17 00:00:00 2001 From: lorenzejay Date: Tue, 20 Jan 2026 10:59:57 -0800 Subject: [PATCH] ensure native tool calling works with liteagent --- lib/crewai/src/crewai/agent/core.py | 28 ++++++++++++++++-------- lib/crewai/src/crewai/utilities/types.py | 4 ++-- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/lib/crewai/src/crewai/agent/core.py b/lib/crewai/src/crewai/agent/core.py index e5cfd024b..efd54cb76 100644 --- a/lib/crewai/src/crewai/agent/core.py +++ b/lib/crewai/src/crewai/agent/core.py @@ -311,6 +311,22 @@ class Agent(BaseAgent): return any(getattr(self.crew, attr) for attr in memory_attributes) + def _supports_native_tool_calling(self, tools: list[BaseTool]) -> bool: + """Check if the LLM supports native function calling with the given tools. + + Args: + tools: List of tools to check against. + + Returns: + True if native function calling is supported and tools are available. + """ + return ( + hasattr(self.llm, "supports_function_calling") + and callable(getattr(self.llm, "supports_function_calling", None)) + and self.llm.supports_function_calling() + and len(tools) > 0 + ) + def execute_task( self, task: Task, @@ -733,12 +749,7 @@ class Agent(BaseAgent): raw_tools: list[BaseTool] = tools or self.tools or [] parsed_tools = parse_tools(raw_tools) - use_native_tool_calling = ( - hasattr(self.llm, "supports_function_calling") - and callable(getattr(self.llm, "supports_function_calling", None)) - and self.llm.supports_function_calling() - and len(raw_tools) > 0 - ) + use_native_tool_calling = self._supports_native_tool_calling(raw_tools) prompt = Prompts( agent=self, @@ -751,8 +762,6 @@ class Agent(BaseAgent): response_template=self.response_template, ).task_execution() - print("prompt", prompt) - stop_words = [self.i18n.slice("observation")] if self.response_template: @@ -1644,9 +1653,11 @@ class Agent(BaseAgent): } # Build prompt for standalone execution + use_native_tool_calling = self._supports_native_tool_calling(raw_tools) prompt = Prompts( agent=self, has_tools=len(raw_tools) > 0, + use_native_tool_calling=use_native_tool_calling, i18n=self.i18n, use_system_prompt=self.use_system_prompt, system_template=self.system_template, @@ -1754,7 +1765,6 @@ class Agent(BaseAgent): ) output = self._execute_and_build_output(executor, inputs, response_format) - if self.guardrail is not None: output = self._process_kickoff_guardrail( output=output, diff --git a/lib/crewai/src/crewai/utilities/types.py b/lib/crewai/src/crewai/utilities/types.py index a4627613d..fe82a0359 100644 --- a/lib/crewai/src/crewai/utilities/types.py +++ b/lib/crewai/src/crewai/utilities/types.py @@ -13,5 +13,5 @@ class LLMMessage(TypedDict): instead of str | list[dict[str, str]] """ - role: Literal["user", "assistant", "system"] - content: str | list[dict[str, Any]] + role: Literal["user", "assistant", "system", "tool"] + content: str | list[dict[str, Any]] | None