gemini-agent-framework 0.1.4__tar.gz → 0.1.6__tar.gz
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_framework-0.1.4 → gemini_agent_framework-0.1.6}/PKG-INFO +1 -1
- {gemini_agent_framework-0.1.4 → gemini_agent_framework-0.1.6}/pyproject.toml +1 -1
- gemini_agent_framework-0.1.6/src/gemini_agent/__init__.py +4 -0
- {gemini_agent_framework-0.1.4 → gemini_agent_framework-0.1.6}/src/gemini_agent/agent.py +6 -3
- gemini_agent_framework-0.1.6/tests/test_agent.py +76 -0
- gemini_agent_framework-0.1.4/src/gemini_agent/__init__.py +0 -4
- gemini_agent_framework-0.1.4/tests/test_agent.py +0 -66
- {gemini_agent_framework-0.1.4 → gemini_agent_framework-0.1.6}/.gitignore +0 -0
- {gemini_agent_framework-0.1.4 → gemini_agent_framework-0.1.6}/README.md +0 -0
- {gemini_agent_framework-0.1.4 → gemini_agent_framework-0.1.6}/requirements.txt +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: gemini-agent-framework
|
3
|
-
Version: 0.1.
|
3
|
+
Version: 0.1.6
|
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
|
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "gemini-agent-framework"
|
7
|
-
version = "0.1.
|
7
|
+
version = "0.1.6"
|
8
8
|
description = "A framework for building agents that use Gemini's function calling capabilities"
|
9
9
|
readme = "README.md"
|
10
10
|
requires-python = ">=3.8"
|
@@ -213,7 +213,7 @@ class Agent:
|
|
213
213
|
- If a step requires multiple tools, execute them sequentially
|
214
214
|
- If you're unsure about the next step, explain your reasoning
|
215
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
|
216
|
+
- You don't have the ability to set new varaibles during the conversation. and if you need to use them thhen you will need to use its actual value.
|
217
217
|
- When using stored variables, ALWAYS use the {{"variable": "variable_name"}} syntax
|
218
218
|
""".format(
|
219
219
|
tools_list="\n".join([f"- {name}: {desc}" for name, desc in
|
@@ -322,9 +322,11 @@ class Agent:
|
|
322
322
|
}
|
323
323
|
final_mime_type = "application/json"
|
324
324
|
final_response_schema = response_structure
|
325
|
-
|
325
|
+
counter = 0
|
326
326
|
while True:
|
327
|
-
|
327
|
+
with open(f"payload_variable_{counter}.json", "w") as f:
|
328
|
+
json.dump(payload, f)
|
329
|
+
|
328
330
|
response_data = self._call_gemini_api(payload)
|
329
331
|
if "error" in response_data:
|
330
332
|
print(f"API call failed: {response_data['error'].get('message', 'Unknown API error')}")
|
@@ -470,6 +472,7 @@ class Agent:
|
|
470
472
|
print(f"Warning: Failed to parse structured output after formatting call: {e}. Returning intermediate text.")
|
471
473
|
return final_text
|
472
474
|
return final_text
|
475
|
+
counter += 1
|
473
476
|
continue
|
474
477
|
|
475
478
|
|
@@ -0,0 +1,76 @@
|
|
1
|
+
from gemini_agent import Agent
|
2
|
+
from dotenv import load_dotenv
|
3
|
+
import os
|
4
|
+
|
5
|
+
load_dotenv()
|
6
|
+
|
7
|
+
# Load multiple API keys
|
8
|
+
api_keys = os.getenv("GEMINI_APIs").split(",")
|
9
|
+
current_key_idx = 0
|
10
|
+
|
11
|
+
def get_current_api_key():
|
12
|
+
return api_keys[current_key_idx]
|
13
|
+
|
14
|
+
def switch_to_next_api_key():
|
15
|
+
global current_key_idx
|
16
|
+
current_key_idx = (current_key_idx + 1) % len(api_keys)
|
17
|
+
print(f"🔄 [DEBUG] Switching to API key index {current_key_idx}: {api_keys[current_key_idx][:10]}...")
|
18
|
+
|
19
|
+
# Define your tools
|
20
|
+
@Agent.description("Multiplies two numbers.")
|
21
|
+
@Agent.parameters({
|
22
|
+
'a': {'type': int, 'description': 'The first number'},
|
23
|
+
'b': {'type': int, 'description': 'The second number'}
|
24
|
+
})
|
25
|
+
def multiply(a: int, b: int) -> int:
|
26
|
+
return a * b
|
27
|
+
|
28
|
+
@Agent.description("Adds two numbers.")
|
29
|
+
@Agent.parameters({
|
30
|
+
'a': {'type': int, 'description': 'The first number'},
|
31
|
+
'b': {'type': int, 'description': 'The second number'}
|
32
|
+
})
|
33
|
+
def add(a: int, b: int) -> int:
|
34
|
+
return a + b
|
35
|
+
|
36
|
+
# Create agent with the first API key
|
37
|
+
agent = Agent(api_key=get_current_api_key(), tools=[multiply, add])
|
38
|
+
|
39
|
+
# Define a wrapper to rotate API key AFTER the call
|
40
|
+
def agent_prompt_with_key_rotation(agent,*args, **kwargs):
|
41
|
+
# global agent
|
42
|
+
print(f"🚀 [DEBUG] Using API key index {current_key_idx}: {agent.api_key[:10]}...")
|
43
|
+
response = agent.prompt(*args, **kwargs)
|
44
|
+
switch_to_next_api_key()
|
45
|
+
agent.api_key = get_current_api_key()
|
46
|
+
return response
|
47
|
+
|
48
|
+
# Use the agent
|
49
|
+
response = agent_prompt_with_key_rotation(agent,
|
50
|
+
user_prompt="multiply 3 and 7 then add 5 to the result",
|
51
|
+
system_prompt="You are a helpful assistant. Give your response always with ❤️ at the start of the line. In your response you should mention the function you used.",
|
52
|
+
response_structure={
|
53
|
+
"type": "object",
|
54
|
+
"properties": {
|
55
|
+
"used_functions": {
|
56
|
+
"type": "array",
|
57
|
+
"items": {
|
58
|
+
"type": "object",
|
59
|
+
"properties": {
|
60
|
+
"function_name": {"type": "string"},
|
61
|
+
"parameters": {
|
62
|
+
"type": "object",
|
63
|
+
"properties": {
|
64
|
+
"a": {"type": "integer"},
|
65
|
+
"b": {"type": "integer"}
|
66
|
+
}
|
67
|
+
}
|
68
|
+
}
|
69
|
+
}
|
70
|
+
},
|
71
|
+
"answer": {"type": "string"}
|
72
|
+
}
|
73
|
+
}
|
74
|
+
)
|
75
|
+
|
76
|
+
print(response)
|
@@ -1,66 +0,0 @@
|
|
1
|
-
import os
|
2
|
-
from dotenv import load_dotenv
|
3
|
-
from framework_agent import Agent
|
4
|
-
|
5
|
-
load_dotenv()
|
6
|
-
|
7
|
-
def test_basic_operations():
|
8
|
-
# Define some basic math operations
|
9
|
-
@Agent.description("Multiplies two numbers.")
|
10
|
-
@Agent.parameters({
|
11
|
-
'a': {'type': int, 'description': 'The first number'},
|
12
|
-
'b': {'type': int, 'description': 'The second number'}
|
13
|
-
})
|
14
|
-
def multiply(a: int, b: int) -> int:
|
15
|
-
return a * b
|
16
|
-
|
17
|
-
@Agent.description("Adds two numbers.")
|
18
|
-
@Agent.parameters({
|
19
|
-
'a': {'type': int, 'description': 'The first number'},
|
20
|
-
'b': {'type': int, 'description': 'The second number'}
|
21
|
-
})
|
22
|
-
def add(a: int, b: int) -> int:
|
23
|
-
return a + b
|
24
|
-
|
25
|
-
# Create an agent with the math tools
|
26
|
-
agent = Agent(
|
27
|
-
api_key=os.getenv("GEMINI_API_KEY"),
|
28
|
-
tools=[multiply, add]
|
29
|
-
)
|
30
|
-
|
31
|
-
# Test a simple multiplication
|
32
|
-
response = agent.prompt("Multiply 3 and 7")
|
33
|
-
print(f"Multiplication result: {response}") # Should be 21
|
34
|
-
|
35
|
-
# Use the agent
|
36
|
-
response = agent.prompt(user_prompt="multiply 3 and 7 then add 5 to the result" ,
|
37
|
-
system_prompt="You are a helpful assistant give your response always with ❤️ at the start of the line. in your response you should mention the function you used." ,
|
38
|
-
response_structure=
|
39
|
-
{
|
40
|
-
"type": "object",
|
41
|
-
"properties": {
|
42
|
-
"used_functions": {
|
43
|
-
"type": "array",
|
44
|
-
"items": {
|
45
|
-
"type": "object",
|
46
|
-
"properties": {
|
47
|
-
"function_name": {"type": "string"},
|
48
|
-
"parameters": {
|
49
|
-
"type": "object",
|
50
|
-
"properties": {
|
51
|
-
"a": {"type": "integer"},
|
52
|
-
"b": {"type": "integer"}
|
53
|
-
}
|
54
|
-
}
|
55
|
-
}
|
56
|
-
}
|
57
|
-
},
|
58
|
-
"answer": {"type": "string"}
|
59
|
-
|
60
|
-
}
|
61
|
-
}
|
62
|
-
)
|
63
|
-
print(response) # Should output 21
|
64
|
-
|
65
|
-
if __name__ == "__main__":
|
66
|
-
test_basic_operations()
|
File without changes
|
File without changes
|
File without changes
|