1+ """
2+ Different ways to configure Gemini internal tools in PraisonAI
3+ """
4+
5+ from praisonaiagents import Agent
6+ from praisonaiagents .llm import LLM
7+
8+ # Method 1: Simple boolean flags
9+ print ("=== Method 1: Simple Boolean Flags ===" )
10+ agent1 = Agent (
11+ instructions = "Assistant with search and code capabilities" ,
12+ llm = {
13+ "model" : "gemini/gemini-1.5-flash" ,
14+ "google_search_retrieval" : True ,
15+ "enable_code_execution" : True
16+ }
17+ )
18+ print ("✓ Agent created with boolean flags\n " )
19+
20+ # Method 2: Detailed configuration with thresholds
21+ print ("=== Method 2: Detailed Configuration ===" )
22+ agent2 = Agent (
23+ instructions = "Research assistant with fine-tuned settings" ,
24+ llm = {
25+ "model" : "gemini/gemini-1.5-pro" ,
26+ "google_search_retrieval" : {
27+ "threshold" : 0.9 # High confidence threshold
28+ },
29+ "dynamic_retrieval_config" : {
30+ "mode" : "grounded" ,
31+ "dynamic_threshold" : 0.7
32+ }
33+ }
34+ )
35+ print ("✓ Agent created with detailed configuration\n " )
36+
37+ # Method 3: Using tool_config parameter
38+ print ("=== Method 3: Tool Config Parameter ===" )
39+ agent3 = Agent (
40+ instructions = "Advanced assistant with all tools" ,
41+ llm = {
42+ "model" : "gemini/gemini-1.5-pro-latest" ,
43+ "tool_config" : {
44+ "google_search_retrieval" : {
45+ "threshold" : 0.8
46+ },
47+ "code_execution" : {},
48+ "dynamic_retrieval_config" : {
49+ "mode" : "grounded" ,
50+ "dynamic_threshold" : 0.6
51+ }
52+ }
53+ }
54+ )
55+ print ("✓ Agent created with tool_config\n " )
56+
57+ # Method 4: Direct LLM instance with internal tools
58+ print ("=== Method 4: Direct LLM Instance ===" )
59+ llm = LLM (
60+ model = "gemini/gemini-1.5-flash" ,
61+ google_search_retrieval = True ,
62+ enable_code_execution = True ,
63+ temperature = 0.7 ,
64+ max_tokens = 2000
65+ )
66+
67+ # Use the LLM instance with an agent
68+ agent4 = Agent (
69+ instructions = "Assistant using pre-configured LLM" ,
70+ llm = llm # Pass the LLM instance directly
71+ )
72+ print ("✓ Agent created with pre-configured LLM instance\n " )
73+
74+ # Method 5: Combining with custom tools
75+ print ("=== Method 5: Internal + Custom Tools ===" )
76+
77+ def calculate_compound_interest (principal : float , rate : float , time : int ) -> float :
78+ """Calculate compound interest
79+
80+ Args:
81+ principal: Initial amount
82+ rate: Annual interest rate (as decimal)
83+ time: Time period in years
84+ """
85+ return principal * (1 + rate ) ** time
86+
87+ agent5 = Agent (
88+ instructions = "Financial assistant with search and custom calculation tools" ,
89+ llm = {
90+ "model" : "gemini/gemini-1.5-flash" ,
91+ "google_search_retrieval" : True , # For market research
92+ "enable_code_execution" : True # For complex calculations
93+ },
94+ tools = [calculate_compound_interest ] # Custom tool
95+ )
96+ print ("✓ Agent created with both internal and custom tools\n " )
97+
98+ # Method 6: Environment-specific configuration
99+ print ("=== Method 6: Environment-Specific Config ===" )
100+ import os
101+
102+ # You can set defaults via environment
103+ config = {
104+ "model" : os .getenv ("GEMINI_MODEL" , "gemini/gemini-1.5-flash" ),
105+ "temperature" : float (os .getenv ("GEMINI_TEMPERATURE" , "0.7" ))
106+ }
107+
108+ # Add internal tools based on environment
109+ if os .getenv ("ENABLE_SEARCH" , "true" ).lower () == "true" :
110+ config ["google_search_retrieval" ] = True
111+
112+ if os .getenv ("ENABLE_CODE_EXEC" , "true" ).lower () == "true" :
113+ config ["enable_code_execution" ] = True
114+
115+ agent6 = Agent (
116+ instructions = "Environment-configured assistant" ,
117+ llm = config
118+ )
119+ print ("✓ Agent created with environment-based configuration\n " )
120+
121+ # Example usage demonstrating the tools
122+ print ("\n === Example Usage ===" )
123+ print ("Testing search capability..." )
124+ response = agent1 .start ("What's the current temperature in Tokyo?" )
125+ print (f"Search result preview: { response [:100 ]} ...\n " )
126+
127+ print ("Testing code execution..." )
128+ response = agent1 .start ("Write and run a Python function to check if 2024 is a leap year" )
129+ print (f"Code execution result preview: { response [:100 ]} ...\n " )
130+
131+ print ("Configuration examples complete!" )
0 commit comments