Skip to content

Commit 100c818

Browse files
fix: Add support for Gemini internal tools in tool formatting
- Add explicit handling for Gemini internal tools (googleSearch, urlContext, codeExecution) in both _format_tools_for_litellm() and format_tools() methods - Update docstrings to document new capability - Resolves issue where Gemini internal tools were skipped with ''unsupported type'' error - Maintains backward compatibility with existing tool formats - Fixes #919 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Mervin Praison <MervinPraison@users.noreply.github.com>
1 parent c6a6bfa commit 100c818

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,7 @@ def _format_tools_for_litellm(self, tools: Optional[List[Any]]) -> Optional[List
542542
- Lists of pre-formatted tools
543543
- Callable functions
544544
- String function names
545+
- Gemini internal tools ({"googleSearch": {}}, {"urlContext": {}}, {"codeExecution": {}})
545546
546547
Args:
547548
tools: List of tools in various formats
@@ -588,6 +589,16 @@ def _format_tools_for_litellm(self, tools: Optional[List[Any]]) -> Optional[List
588589
tool_def = self._generate_tool_definition(tool)
589590
if tool_def:
590591
formatted_tools.append(tool_def)
592+
# Handle Gemini internal tools (e.g., {"googleSearch": {}}, {"urlContext": {}}, {"codeExecution": {}})
593+
elif isinstance(tool, dict) and len(tool) == 1:
594+
tool_name = next(iter(tool.keys()))
595+
# List of supported Gemini internal tools
596+
gemini_internal_tools = {'googleSearch', 'urlContext', 'codeExecution'}
597+
if tool_name in gemini_internal_tools:
598+
logging.debug(f"Using Gemini internal tool: {tool_name}")
599+
formatted_tools.append(tool)
600+
else:
601+
logging.debug(f"Skipping unknown tool: {tool_name}")
591602
else:
592603
logging.debug(f"Skipping tool of unsupported type: {type(tool)}")
593604

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,7 @@ def format_tools(self, tools: Optional[List[Any]]) -> Optional[List[Dict]]:
360360
- Callable functions
361361
- String function names
362362
- MCP tools
363+
- Gemini internal tools ({"googleSearch": {}}, {"urlContext": {}}, {"codeExecution": {}})
363364
364365
Args:
365366
tools: List of tools in various formats
@@ -404,6 +405,16 @@ def format_tools(self, tools: Optional[List[Any]]) -> Optional[List[Dict]]:
404405
tool_def = self._generate_tool_definition_from_name(tool)
405406
if tool_def:
406407
formatted_tools.append(tool_def)
408+
# Handle Gemini internal tools (e.g., {"googleSearch": {}}, {"urlContext": {}}, {"codeExecution": {}})
409+
elif isinstance(tool, dict) and len(tool) == 1:
410+
tool_name = next(iter(tool.keys()))
411+
# List of supported Gemini internal tools
412+
gemini_internal_tools = {'googleSearch', 'urlContext', 'codeExecution'}
413+
if tool_name in gemini_internal_tools:
414+
logging.debug(f"Using Gemini internal tool: {tool_name}")
415+
formatted_tools.append(tool)
416+
else:
417+
logging.debug(f"Skipping unknown tool: {tool_name}")
407418
else:
408419
logging.debug(f"Skipping tool of unsupported type: {type(tool)}")
409420

0 commit comments

Comments
 (0)