This project is a learning-purpose AI agent that can:
- List files in a directory
- Read the contents of files
- Write new file contents
- Execute Python files
- Run a calculator application
The agent uses Google’s gemini-2.0-flash-001
model with function calling enabled to execute safe, pre-declared Python functions inside a controlled working directory (./calculator
).
⚠️ Security Note: This project is not production-ready. It can execute Python files within the working directory and is meant for local experiments only.
Use the get_files_info
function to list files and directories (with sizes):
get_files_info({'directory': '.'})
Use the read_file
function to return the text content of a file:
read_file({'file_path': 'example.txt'})
Use the write_file
function to create or update a file:
write_file({'file_path': 'newfile.txt', 'contents': 'Hello World!'})
For safety, avoid overwriting important files.
Use the run_python_file
function to run Python scripts within the working directory:
run_python_file({'file_path': 'tests.py'})
The calculator (main.py
in the calculator
directory) can parse and execute arithmetic operations:
uv run calculator/main.py "3 + 5"
- Functions are declared with
types.FunctionDeclaration
and grouped withtypes.Tool
. - These tools are passed to
gemini-2.0-flash-001
in thegenerate_content
call. - The model returns a
function_call
with:name
: the function name as a stringargs
: a dictionary of arguments
- The call is routed through
call_function()
which:- Injects the working directory (
./calculator
) - Executes the mapped Python function (
get_files_info
,read_file
,write_file
,run_python_file
) - Returns a structured
types.Content
viaPart.from_function_response(...)
- Injects the working directory (
List files in the root directory:
uv run main.py "what files are in the root?"
List files in pkg
:
uv run main.py "what files are in the pkg directory?"
Read the contents of example.txt
:
uv run main.py "read lorem.txt"
Write a new file:
uv run main.py "write hello.txt with the text 'Hello AI Agent!'"
Run calculator tests:
uv run main.py "run the calculator tests"
Verbose mode (prints function calls and results):
uv run main.py "list the directory contents" --verbose
- Python 3.10+
uv
(for running commands)- Google GenAI Python SDK (
google-genai
)
- All file operations and Python execution are restricted to the
./calculator
directory. - Execution timeout is 30 seconds to prevent infinite loops.
- Do not share this agent with untrusted users.
This project is a Boot.dev project for educational purposes only.