Skip to content

Commit cf386cf

Browse files
Merge pull request #923 from MervinPraison/claude/issue-919-20250715_061529
fix: Add support for Gemini internal tools in tool formatting
2 parents 4277460 + 75cf3b7 commit cf386cf

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

src/praisonai-agents/praisonaiagents/llm/llm.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
ReflectionOutput,
1717
execute_sync_callback,
1818
)
19+
from .model_capabilities import is_gemini_internal_tool
1920
from rich.console import Console
2021
from rich.live import Live
2122

@@ -542,6 +543,7 @@ def _format_tools_for_litellm(self, tools: Optional[List[Any]]) -> Optional[List
542543
- Lists of pre-formatted tools
543544
- Callable functions
544545
- String function names
546+
- Gemini internal tools ({"googleSearch": {}}, {"urlContext": {}}, {"codeExecution": {}})
545547
546548
Args:
547549
tools: List of tools in various formats
@@ -588,6 +590,11 @@ def _format_tools_for_litellm(self, tools: Optional[List[Any]]) -> Optional[List
588590
tool_def = self._generate_tool_definition(tool)
589591
if tool_def:
590592
formatted_tools.append(tool_def)
593+
# Handle Gemini internal tools (e.g., {"googleSearch": {}}, {"urlContext": {}}, {"codeExecution": {}})
594+
elif is_gemini_internal_tool(tool):
595+
tool_name = next(iter(tool.keys()))
596+
logging.debug(f"Using Gemini internal tool: {tool_name}")
597+
formatted_tools.append(tool)
591598
else:
592599
logging.debug(f"Skipping tool of unsupported type: {type(tool)}")
593600

src/praisonai-agents/praisonaiagents/llm/model_capabilities.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,4 +104,27 @@ def supports_streaming_with_tools(model_name: str) -> bool:
104104
"""
105105
# For now, use the same logic as structured outputs
106106
# In the future, this could be a separate list if needed
107-
return supports_structured_outputs(model_name)
107+
return supports_structured_outputs(model_name)
108+
109+
110+
# Supported Gemini internal tools
111+
GEMINI_INTERNAL_TOOLS = {'googleSearch', 'urlContext', 'codeExecution'}
112+
113+
114+
def is_gemini_internal_tool(tool) -> bool:
115+
"""
116+
Check if a tool is a Gemini internal tool and should be included in formatted tools.
117+
118+
Gemini internal tools are single-key dictionaries with specific tool names.
119+
Examples: {"googleSearch": {}}, {"urlContext": {}}, {"codeExecution": {}}
120+
121+
Args:
122+
tool: The tool to check
123+
124+
Returns:
125+
bool: True if the tool is a recognized Gemini internal tool, False otherwise
126+
"""
127+
if isinstance(tool, dict) and len(tool) == 1:
128+
tool_name = next(iter(tool.keys()))
129+
return tool_name in GEMINI_INTERNAL_TOOLS
130+
return False

src/praisonai-agents/praisonaiagents/llm/openai_client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from rich.console import Console
1919
from rich.live import Live
2020
import inspect
21+
from .model_capabilities import is_gemini_internal_tool
2122

2223
# Constants
2324
LOCAL_SERVER_API_KEY_PLACEHOLDER = "not-needed"
@@ -360,6 +361,7 @@ def format_tools(self, tools: Optional[List[Any]]) -> Optional[List[Dict]]:
360361
- Callable functions
361362
- String function names
362363
- MCP tools
364+
- Gemini internal tools ({"googleSearch": {}}, {"urlContext": {}}, {"codeExecution": {}})
363365
364366
Args:
365367
tools: List of tools in various formats
@@ -404,6 +406,11 @@ def format_tools(self, tools: Optional[List[Any]]) -> Optional[List[Dict]]:
404406
tool_def = self._generate_tool_definition_from_name(tool)
405407
if tool_def:
406408
formatted_tools.append(tool_def)
409+
# Handle Gemini internal tools (e.g., {"googleSearch": {}}, {"urlContext": {}}, {"codeExecution": {}})
410+
elif is_gemini_internal_tool(tool):
411+
tool_name = next(iter(tool.keys()))
412+
logging.debug(f"Using Gemini internal tool: {tool_name}")
413+
formatted_tools.append(tool)
407414
else:
408415
logging.debug(f"Skipping tool of unsupported type: {type(tool)}")
409416

0 commit comments

Comments
 (0)