This repository contains a Python-based chatbot powered by Google Gemini. This AI agent is designed to interact with the file system and execute Python code, making it a powerful tool for various automation and development tasks.
- Google Gemini Integration: Leverages the Google Gemini API for natural language understanding and generation.
- File System Interaction: Can list files and directories, read file content, and write to files.
- Code Execution: Capable of executing Python files with specified arguments.
- Conversational Interface: Engages in multi-turn conversations, allowing for complex task execution.
- Detailed Output: Provides detailed output, including token counts and function responses for better debugging and understanding.
The chatbot has access to the following functions:
get_files_info(): Lists files and directories in a specified path.get_file_content(file_path): Reads the content of a specified file.write_file(file_path, content): Writes or overwrites content to a specified file.run_python_file(file_path, args): Executes a Python file with optional arguments.
-
Clone the repository:
git clone <repository_url> cd <repository_directory>
-
Configure your Google Gemini API Key: Obtain a Gemini API key from the Google Cloud Console or AI Studio. Create a
.envfile in the root directory of this project and add your API key:GEMINI_API_KEY="your_api_key_here" -
Install dependencies with
uv: Make sure you haveuvinstalled (if not, you can install it withcurl -LsSf https://astral.sh/uv/install.sh | sh). Then, activate the virtual environment and sync dependencies:uv venv source .venv/bin/activate # On Linux/macOS # Or: .venv\\Scripts\\activate # On Windows uv sync
To run the chatbot, execute the main.py script with an initial prompt:
uv run python main.py "Your initial prompt here"To enable detailed output, use the --verbose flag:
uv run python main.py "Your initial prompt here" --verbosemain.py: The main entry point for the chatbot.available_functions.py: Defines the functions that the Gemini model can call.core/: Contains the core logic for function handling.functions/: Houses the implementations of the AI-callable functions.utils/: Utility functions and configurations.prompts.py: Stores the system prompt used to guide the AI's behavior.config.py: Configuration settings for the chatbot.
To extend the agent's capabilities with new functions, follow these steps:
-
Create a New Function File: Define a new Python file for your function within the
/functionsdirectory (e.g.,functions/my_new_function.py). Implement the function logic in this file. -
Define the Function Schema: In the same file, define the schema for your new function using the
tool_codedecorator. This schema describes the function's purpose, its parameters, and their types, which helps the AI model understand how to use it. -
Add to
available_functions.py: Import your new function and its schema intoavailable_functions.py. Add your function to theavailable_functionslist and its schema to thetoolslist. -
Update the System Prompt: Modify the
prompts.pyfile to include information about your new function in the system prompt. Explain what the function does and when the AI should consider using it. -
Write a Test: Create a corresponding test file in the
/testsdirectory (e.g.,tests/test_my_new_function.py). Write unit tests to ensure your new function works as expected and integrates correctly with the agent.