gemini-agent-framework 0.1.1__py3-none-any.whl → 0.1.2__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 +25 -4
- {gemini_agent_framework-0.1.1.dist-info → gemini_agent_framework-0.1.2.dist-info}/METADATA +1 -1
- gemini_agent_framework-0.1.2.dist-info/RECORD +5 -0
- gemini_agent_framework-0.1.1.dist-info/RECORD +0 -5
- {gemini_agent_framework-0.1.1.dist-info → gemini_agent_framework-0.1.2.dist-info}/WHEEL +0 -0
gemini_agent/__init__.py
CHANGED
gemini_agent/agent.py
CHANGED
@@ -31,6 +31,7 @@ class Agent:
|
|
31
31
|
Agent._tools_registry[func.__name__]['description'] = desc
|
32
32
|
Agent._tools_registry[func.__name__]['signature'] = inspect.signature(func)
|
33
33
|
Agent._tools_registry[func.__name__]['function_ref'] = func
|
34
|
+
Agent._tools_registry[func.__name__]['is_method'] = inspect.ismethod(func)
|
34
35
|
@wraps(func)
|
35
36
|
def wrapper(*args, **kwargs):
|
36
37
|
return func(*args, **kwargs)
|
@@ -48,6 +49,7 @@ class Agent:
|
|
48
49
|
Agent._tools_registry[func.__name__]['signature'] = inspect.signature(func)
|
49
50
|
if 'function_ref' not in Agent._tools_registry[func.__name__]:
|
50
51
|
Agent._tools_registry[func.__name__]['function_ref'] = func
|
52
|
+
Agent._tools_registry[func.__name__]['is_method'] = inspect.ismethod(func)
|
51
53
|
@wraps(func)
|
52
54
|
def wrapper(*args, **kwargs):
|
53
55
|
return func(*args, **kwargs)
|
@@ -60,7 +62,7 @@ class Agent:
|
|
60
62
|
|
61
63
|
Args:
|
62
64
|
api_key: Your Google Generative AI API key.
|
63
|
-
tools: A list of Python functions decorated as tools.
|
65
|
+
tools: A list of Python functions or class methods decorated as tools.
|
64
66
|
model_name: The name of the Gemini model to use.
|
65
67
|
"""
|
66
68
|
if not api_key:
|
@@ -72,6 +74,7 @@ class Agent:
|
|
72
74
|
|
73
75
|
self._registered_tools_json: List[Dict[str, Any]] = [] # Store JSON representation
|
74
76
|
self._tool_functions: Dict[str, Callable] = {} # Map name to actual function
|
77
|
+
self._tool_instances: Dict[str, Any] = {} # Store instances for class methods
|
75
78
|
self._intermediate_results: Dict[str, Any] = {} # Store intermediate results
|
76
79
|
|
77
80
|
if tools:
|
@@ -90,6 +93,12 @@ class Agent:
|
|
90
93
|
print(f"Warning: Function '{tool_name}' is missing @Agent.description. Skipping.")
|
91
94
|
continue
|
92
95
|
|
96
|
+
# Store the bound method directly if it's a class method
|
97
|
+
if inspect.ismethod(func):
|
98
|
+
self._tool_functions[tool_name] = func
|
99
|
+
else:
|
100
|
+
self._tool_functions[tool_name] = metadata['function_ref']
|
101
|
+
|
93
102
|
# Build the parameters schema JSON
|
94
103
|
gemini_params_schema = {
|
95
104
|
"type": "OBJECT",
|
@@ -102,6 +111,9 @@ class Agent:
|
|
102
111
|
if not params_def and signature:
|
103
112
|
params_def = {}
|
104
113
|
for name, param in signature.parameters.items():
|
114
|
+
# Skip 'self' parameter for class methods
|
115
|
+
if name == 'self' and inspect.ismethod(func):
|
116
|
+
continue
|
105
117
|
py_type = param.annotation if param.annotation != inspect.Parameter.empty else str
|
106
118
|
params_def[name] = {'type': py_type, 'description': f'Parameter {name}'}
|
107
119
|
|
@@ -125,7 +137,6 @@ class Agent:
|
|
125
137
|
del declaration_json["parameters"]
|
126
138
|
|
127
139
|
self._registered_tools_json.append(declaration_json)
|
128
|
-
self._tool_functions[tool_name] = metadata['function_ref']
|
129
140
|
|
130
141
|
def _get_system_prompt(self) -> str:
|
131
142
|
"""Returns a system prompt that guides the model in breaking down complex operations."""
|
@@ -192,9 +203,9 @@ class Agent:
|
|
192
203
|
self._intermediate_results = {}
|
193
204
|
|
194
205
|
if not system_prompt:
|
195
|
-
system_prompt = self._get_system_prompt() + system_prompt
|
196
|
-
else:
|
197
206
|
system_prompt = self._get_system_prompt()
|
207
|
+
else:
|
208
|
+
system_prompt = self._get_system_prompt() + system_prompt
|
198
209
|
|
199
210
|
current_contents = conversation_history if conversation_history else []
|
200
211
|
if system_prompt and not current_contents:
|
@@ -214,6 +225,14 @@ class Agent:
|
|
214
225
|
|
215
226
|
if response_structure and not self._registered_tools_json:
|
216
227
|
apply_structure_later = False
|
228
|
+
# If response_structure is a string type, make it more flexible
|
229
|
+
if response_structure.get("type") == "string":
|
230
|
+
response_structure = {
|
231
|
+
"type": ["string", "object"],
|
232
|
+
"properties": {
|
233
|
+
"value": {"type": "string"}
|
234
|
+
}
|
235
|
+
}
|
217
236
|
payload["generationConfig"] = {
|
218
237
|
"response_mime_type": "application/json",
|
219
238
|
"response_schema": response_structure
|
@@ -272,7 +291,9 @@ class Agent:
|
|
272
291
|
if result_key in self._intermediate_results:
|
273
292
|
args[key] = self._intermediate_results[result_key]
|
274
293
|
|
294
|
+
# Call the function directly - it's already bound if it's a method
|
275
295
|
function_result = tool_function(**args)
|
296
|
+
|
276
297
|
print(f"--- Function Result: {function_result} ---")
|
277
298
|
|
278
299
|
result_key = f"result_{len(self._intermediate_results)}"
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: gemini-agent-framework
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.2
|
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=-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,,
|
@@ -1,5 +0,0 @@
|
|
1
|
-
gemini_agent/__init__.py,sha256=2AgrBW0ePFgOvwoNNqRcZaMPdbOaKPoNHXUo_VlFX-M,71
|
2
|
-
gemini_agent/agent.py,sha256=DqbUBsiI3qzEVAeKAMvlTp0yC0HuK8RAgpmxIJWbPYM,19552
|
3
|
-
gemini_agent_framework-0.1.1.dist-info/METADATA,sha256=glzOEjvwQP2wswyz_NPzPjdQYfaMOooDCMU3ewbGMBs,2386
|
4
|
-
gemini_agent_framework-0.1.1.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
5
|
-
gemini_agent_framework-0.1.1.dist-info/RECORD,,
|
File without changes
|