Skip to content

Commit 9872339

Browse files
author
Gemini Bot
committed
feat: Gemini Internal Tools Support
Gemini: [Issue #867] Enable Use of Model Internal Tools
1 parent 6ac3d78 commit 9872339

2 files changed

Lines changed: 39 additions & 1 deletion

File tree

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

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ def __init__(
217217
max_guardrail_retries: int = 3,
218218
handoffs: Optional[List[Union['Agent', 'Handoff']]] = None,
219219
base_url: Optional[str] = None,
220-
api_key: Optional[str] = None
220+
api_key: Optional[str] = None,
221+
gemini_google_search: bool = False,
222+
gemini_code_execution: bool = False,
221223
):
222224
"""Initialize an Agent instance.
223225
@@ -308,6 +310,10 @@ def __init__(
308310
If provided, automatically creates a custom LLM instance. Defaults to None.
309311
api_key (Optional[str], optional): API key for LLM provider. If not provided,
310312
falls back to environment variables. Defaults to None.
313+
gemini_google_search (bool, optional): Enable Google Search grounding for Gemini models.
314+
Defaults to False.
315+
gemini_code_execution (bool, optional): Enable code execution for Gemini models.
316+
Defaults to False.
311317
312318
Raises:
313319
ValueError: If all of name, role, goal, backstory, and instructions are None.
@@ -479,6 +485,10 @@ def __init__(
479485
self.handoffs = handoffs if handoffs else []
480486
self._process_handoffs()
481487

488+
# Gemini-specific tools
489+
self.gemini_google_search = gemini_google_search
490+
self.gemini_code_execution = gemini_code_execution
491+
482492
# Check if knowledge parameter has any values
483493
if not knowledge:
484494
self.knowledge = None
@@ -1199,6 +1209,18 @@ def chat(self, prompt, temperature=0.2, tools=None, output_json=None, output_pyd
11991209
tool_param = [openai_tool]
12001210
logging.debug(f"Converted MCP tool: {tool_param}")
12011211

1212+
# Add Gemini-specific tools if enabled
1213+
gemini_tools = []
1214+
if self.gemini_google_search:
1215+
gemini_tools.append({"google_search_retrieval": {}})
1216+
if self.gemini_code_execution:
1217+
gemini_tools.append({"code_execution": {}})
1218+
1219+
if gemini_tools:
1220+
if tool_param is None:
1221+
tool_param = []
1222+
tool_param.extend(gemini_tools)
1223+
12021224
# Store chat history length for potential rollback
12031225
chat_history_length = len(self.chat_history)
12041226

@@ -1517,6 +1539,18 @@ async def achat(self, prompt: str, temperature=0.2, tools=None, output_json=None
15171539
prompt = f"{prompt}\n\nKnowledge: {knowledge_content}"
15181540

15191541
if self._using_custom_llm:
1542+
# Add Gemini-specific tools if enabled
1543+
gemini_tools = []
1544+
if self.gemini_google_search:
1545+
gemini_tools.append({"google_search_retrieval": {}})
1546+
if self.gemini_code_execution:
1547+
gemini_tools.append({"code_execution": {}})
1548+
1549+
if gemini_tools:
1550+
if tools is None:
1551+
tools = []
1552+
tools.extend(gemini_tools)
1553+
15201554
# Store chat history length for potential rollback
15211555
chat_history_length = len(self.chat_history)
15221556

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,10 @@ def _format_tools_for_litellm(self, tools: Optional[List[Any]]) -> Optional[List
519519

520520
formatted_tools = []
521521
for tool in tools:
522+
# Check for Gemini-specific tools
523+
if isinstance(tool, dict) and ("google_search_retrieval" in tool or "code_execution" in tool):
524+
formatted_tools.append(tool)
525+
continue
522526
# Check if the tool is already in OpenAI format (e.g. from MCP.to_openai_tool())
523527
if isinstance(tool, dict) and 'type' in tool and tool['type'] == 'function':
524528
# Validate nested dictionary structure before accessing

0 commit comments

Comments
 (0)