gemini-agent-framework 0.1.2__py3-none-any.whl → 0.1.4__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- gemini_agent/__init__.py +1 -1
- gemini_agent/agent.py +90 -5
- {gemini_agent_framework-0.1.2.dist-info → gemini_agent_framework-0.1.4.dist-info}/METADATA +1 -1
- gemini_agent_framework-0.1.4.dist-info/RECORD +5 -0
- gemini_agent_framework-0.1.2.dist-info/RECORD +0 -5
- {gemini_agent_framework-0.1.2.dist-info → gemini_agent_framework-0.1.4.dist-info}/WHEEL +0 -0
gemini_agent/__init__.py
CHANGED
gemini_agent/agent.py
CHANGED
@@ -4,6 +4,7 @@ import inspect
|
|
4
4
|
from functools import wraps
|
5
5
|
from typing import List, Callable, Dict, Any, Optional
|
6
6
|
from dotenv import load_dotenv
|
7
|
+
from datetime import datetime
|
7
8
|
|
8
9
|
load_dotenv()
|
9
10
|
|
@@ -76,6 +77,7 @@ class Agent:
|
|
76
77
|
self._tool_functions: Dict[str, Callable] = {} # Map name to actual function
|
77
78
|
self._tool_instances: Dict[str, Any] = {} # Store instances for class methods
|
78
79
|
self._intermediate_results: Dict[str, Any] = {} # Store intermediate results
|
80
|
+
self._stored_variables: Dict[str, Dict[str, Any]] = {} # Store variables with metadata
|
79
81
|
|
80
82
|
if tools:
|
81
83
|
self._process_tools(tools)
|
@@ -138,8 +140,52 @@ class Agent:
|
|
138
140
|
|
139
141
|
self._registered_tools_json.append(declaration_json)
|
140
142
|
|
143
|
+
def set_variable(self, name: str, value: Any, description: str = "", type_hint: type = None) -> None:
|
144
|
+
"""
|
145
|
+
Stores a variable in the agent's memory with metadata.
|
146
|
+
|
147
|
+
Args:
|
148
|
+
name: The name of the variable
|
149
|
+
value: The actual value to store
|
150
|
+
description: A description of what the variable represents
|
151
|
+
type_hint: Optional type hint for the variable
|
152
|
+
"""
|
153
|
+
self._stored_variables[name] = {
|
154
|
+
'value': value,
|
155
|
+
'description': description,
|
156
|
+
'type': type_hint or type(value).__name__,
|
157
|
+
'created_at': datetime.now().isoformat()
|
158
|
+
}
|
159
|
+
|
160
|
+
def get_variable(self, name: str) -> Any:
|
161
|
+
"""
|
162
|
+
Retrieves a stored variable's value.
|
163
|
+
|
164
|
+
Args:
|
165
|
+
name: The name of the variable to retrieve
|
166
|
+
|
167
|
+
Returns:
|
168
|
+
The stored value or None if not found
|
169
|
+
"""
|
170
|
+
return self._stored_variables.get(name, {}).get('value')
|
171
|
+
|
172
|
+
def list_variables(self) -> Dict[str, Dict[str, Any]]:
|
173
|
+
"""
|
174
|
+
Returns information about all stored variables.
|
175
|
+
|
176
|
+
Returns:
|
177
|
+
Dictionary of variable names to their metadata
|
178
|
+
"""
|
179
|
+
return {name: {k: v for k, v in data.items() if k != 'value'}
|
180
|
+
for name, data in self._stored_variables.items()}
|
181
|
+
|
141
182
|
def _get_system_prompt(self) -> str:
|
142
183
|
"""Returns a system prompt that guides the model in breaking down complex operations."""
|
184
|
+
variables_info = "\n".join([
|
185
|
+
f"- {name}: {data['description']} (Type: {data['type']})"
|
186
|
+
for name, data in self._stored_variables.items()
|
187
|
+
])
|
188
|
+
|
143
189
|
return """You are an AI assistant that can break down complex tasks into sequential steps using available tools.
|
144
190
|
When faced with a complex request:
|
145
191
|
1. Analyze the request to identify which tools can be used
|
@@ -152,13 +198,50 @@ class Agent:
|
|
152
198
|
Available tools:
|
153
199
|
{tools_list}
|
154
200
|
|
201
|
+
Available variables:
|
202
|
+
{variables_list}
|
203
|
+
|
204
|
+
IMPORTANT - Variable Usage:
|
205
|
+
When you need to use a stored variable in a function call, you MUST use the following syntax:
|
206
|
+
- For function arguments: {{"variable": "variable_name"}}
|
207
|
+
- For example, if you want to use the 'current_user' variable in a function call:
|
208
|
+
{{"user_id": {{"variable": "current_user"}}}}
|
209
|
+
|
155
210
|
Remember:
|
156
211
|
- Always perform one operation at a time
|
157
212
|
- Use intermediate results from previous steps
|
158
213
|
- If a step requires multiple tools, execute them sequentially
|
159
214
|
- If you're unsure about the next step, explain your reasoning
|
160
|
-
|
161
|
-
|
215
|
+
- You can use both stored variables and values from the prompt
|
216
|
+
- You don't have the ability to set new varaibles during the conversation
|
217
|
+
- When using stored variables, ALWAYS use the {{"variable": "variable_name"}} syntax
|
218
|
+
""".format(
|
219
|
+
tools_list="\n".join([f"- {name}: {desc}" for name, desc in
|
220
|
+
[(tool['name'], tool['description']) for tool in self._registered_tools_json]]),
|
221
|
+
variables_list=variables_info
|
222
|
+
)
|
223
|
+
|
224
|
+
def _substitute_variables(self, args: Dict[str, Any]) -> Dict[str, Any]:
|
225
|
+
"""
|
226
|
+
Substitutes stored variable values in function arguments.
|
227
|
+
|
228
|
+
Args:
|
229
|
+
args: Dictionary of argument names to values
|
230
|
+
|
231
|
+
Returns:
|
232
|
+
Dictionary with variable values substituted where applicable
|
233
|
+
"""
|
234
|
+
substituted_args = {}
|
235
|
+
for name, value in args.items():
|
236
|
+
if isinstance(value, dict) and "variable" in value:
|
237
|
+
var_name = value["variable"]
|
238
|
+
if var_name in self._stored_variables:
|
239
|
+
substituted_args[name] = self._stored_variables[var_name]['value']
|
240
|
+
else:
|
241
|
+
substituted_args[name] = value
|
242
|
+
else:
|
243
|
+
substituted_args[name] = value
|
244
|
+
return substituted_args
|
162
245
|
|
163
246
|
def _call_gemini_api(self, payload: Dict[str, Any]) -> Dict[str, Any]:
|
164
247
|
"""Makes a POST request to the Gemini generateContent endpoint."""
|
@@ -210,7 +293,7 @@ class Agent:
|
|
210
293
|
current_contents = conversation_history if conversation_history else []
|
211
294
|
if system_prompt and not current_contents:
|
212
295
|
current_contents.append({'role': 'user', 'parts': [{'text': system_prompt}]})
|
213
|
-
current_contents.append({'role': 'model', 'parts': [{'text': "I understand I should break down complex tasks into sequential steps using the available tools."}]})
|
296
|
+
current_contents.append({'role': 'model', 'parts': [{'text': "I understand I should break down complex tasks into sequential steps using the available tools and variables."}]})
|
214
297
|
|
215
298
|
current_contents.append({'role': 'user', 'parts': [{'text': user_prompt}]})
|
216
299
|
payload: Dict[str, Any] = {"contents": current_contents}
|
@@ -241,8 +324,8 @@ class Agent:
|
|
241
324
|
final_response_schema = response_structure
|
242
325
|
|
243
326
|
while True:
|
244
|
-
response_data = self._call_gemini_api(payload)
|
245
327
|
|
328
|
+
response_data = self._call_gemini_api(payload)
|
246
329
|
if "error" in response_data:
|
247
330
|
print(f"API call failed: {response_data['error'].get('message', 'Unknown API error')}")
|
248
331
|
return response_data
|
@@ -285,6 +368,8 @@ class Agent:
|
|
285
368
|
tool_function = self._tool_functions[tool_name]
|
286
369
|
print(f"--- Calling Function: {tool_name}({args}) ---")
|
287
370
|
|
371
|
+
# Substitute both stored variables and intermediate results
|
372
|
+
args = self._substitute_variables(args)
|
288
373
|
for key, value in args.items():
|
289
374
|
if isinstance(value, str) and value.startswith('$'):
|
290
375
|
result_key = value[1:]
|
@@ -385,8 +470,8 @@ class Agent:
|
|
385
470
|
print(f"Warning: Failed to parse structured output after formatting call: {e}. Returning intermediate text.")
|
386
471
|
return final_text
|
387
472
|
return final_text
|
388
|
-
|
389
473
|
continue
|
474
|
+
|
390
475
|
|
391
476
|
except (KeyError, IndexError) as e:
|
392
477
|
print(f"Error parsing API response structure: {e}. Response: {response_data}")
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: gemini-agent-framework
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.4
|
4
4
|
Summary: A framework for building agents that use Gemini's function calling capabilities
|
5
5
|
Project-URL: Homepage, https://github.com/m7mdony/gemini-agent-framework
|
6
6
|
Project-URL: Documentation, https://github.com/m7mdony/gemini-agent-framework#readme
|
@@ -0,0 +1,5 @@
|
|
1
|
+
gemini_agent/__init__.py,sha256=3nn6YdImhRa8SN7VOAJVo2lPbBu2cYjzxgInerYhDvc,71
|
2
|
+
gemini_agent/agent.py,sha256=tMsgexMEsKVvfVTlluihJay4Dadkk6LWf84qe-rv4qc,24146
|
3
|
+
gemini_agent_framework-0.1.4.dist-info/METADATA,sha256=V2RVV60ovE07FCsSfXA3mRKcr5YV6ajU-qvaQ4jeLFQ,2386
|
4
|
+
gemini_agent_framework-0.1.4.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
5
|
+
gemini_agent_framework-0.1.4.dist-info/RECORD,,
|
@@ -1,5 +0,0 @@
|
|
1
|
-
gemini_agent/__init__.py,sha256=-F0v5szfo7HJrUloNdX7J13qO1d3U2wAfxrwt1bJpUQ,71
|
2
|
-
gemini_agent/agent.py,sha256=0slDSnf__jp8j7jxeow12O1XszdTweX2MDorr-JlAmc,20674
|
3
|
-
gemini_agent_framework-0.1.2.dist-info/METADATA,sha256=savJnjAKvUPmN2rMRSohQzdxla1sIPfbmuEJ-YlrHU0,2386
|
4
|
-
gemini_agent_framework-0.1.2.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
5
|
-
gemini_agent_framework-0.1.2.dist-info/RECORD,,
|
File without changes
|