Gemini Tool Agent
A lightweight, tool-aware Gemini agent to handle structured prompts and tool usage in conversations.
Overview
Gemini Tool Agent is a Python library that provides a simple interface for creating tool-aware agents powered by Google's Gemini AI models. It enables developers to define custom tools with structured input schemas and seamlessly integrate them into conversational flows.
Features
- Tool-aware conversation handling
- Structured prompt processing
- Automatic context management
- JSON response parsing
- Conversation history tracking
Installation
pip install gemini-tool-agent
Requirements
- Python 3.8 or higher
- Google Generative AI Python SDK (google-genai >= 0.3.2)
Usage
from gemini_tool_agent.agent import Agent
# Initialize the agent with your API key
agent = Agent(key="your-api-key")
# Define your tools
agent.tools = [
{
"name": "save_note",
"description": "Save a note to the database",
"input_schema": {
"title": "string",
"content": "string"
}
}
]
# Process a query that might use tools
response = agent.process_query("Save a note about AI agents")
print(response)
Response Format
The agent returns a structured response in JSON format:
{
"needs_tool": true,
"tool_name": "save_note",
"needs_direct_response": true,
"direct_response_first": false,
"reasoning": "The query explicitly asks to save a note, which requires the save_note tool",
"direct_response": "AI agents are software entities that can perform tasks autonomously..."
}
Tool Parameter Extraction
After identifying that a tool needs to be used, you can extract parameters from the conversation:
# First process the query to determine if a tool is needed
response = agent.process_query("Save a note titled 'AI Agents' with content about machine learning")
# If a tool is needed, extract the parameters
if response.get("needs_tool", False):
tool_name = response.get("tool_name")
tool_params = agent.process_use_tool(tool_name)
# Now you can use the extracted parameters to execute the tool
print(tool_params)
# Output: {'tool_name': 'save_note', 'input': {'title': 'AI Agents', 'content': '...'}}
#You can then execute the tool with the extracted parameters
Optimized Response Generation
The agent automatically handles large prompts for memory efficiency:
# For direct usage (normally used internally by the agent)
response_text = agent.generate_response(large_prompt)
# The method automatically optimizes prompts over 10,000 characters by:
# - Trimming conversation history to the most recent 15 lines when needed
# - Truncating large direct responses while preserving start and end content
Advanced Usage
You can access the conversation history:
# Get the conversation history
history = agent.history
License
MIT
Author
Paul Fruitful (fruitful2007@outlook.com)
Metadata
Release files for gemini-tool-agent 0.1.5
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| gemini_tool_agent-0.1.5.tar.gz | 4.6 kB | Without provenance | Details for gemini_tool_agent-0.1.5.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| gemini_tool_agent-0.1.5-py3-none-any.whl | Python 3 | none | any | Details for gemini_tool_agent-0.1.5-py3-none-any.whl |
Total release size: 9.4 kB
Release files / gemini_tool_agent-0.1.5.tar.gz
| Download URL | gemini_tool_agent-0.1.5.tar.gz |
|---|---|
| Size | 4.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
faa8a585962d6aeec1e850df708e630c238cbfce2dee9d8cff3c2a722583b864
|
|
BLAKE2b-256 checksum How to use checksums |
fcba5a5a21bdcccba3e2d827a8f5eb64bcfa9d154155bd4689265f0551b24999
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Release files / gemini_tool_agent-0.1.5-py3-none-any.whl
| Download URL | gemini_tool_agent-0.1.5-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
85a2a2220b3194ad8d8f2baad76beb265a4f1f27c081fd2c5efa816685566a2c
|
|
BLAKE2b-256 checksum How to use checksums |
1e6882c7b9282e941881a20262e45261ac289a3253efad18486632ae5a00d256
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.3
|
Security for gemini-tool-agent 0.1.5
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.