An AI-powered code agent built with Python and Google's Gemini 2.5 Flash. This agent can understand natural language instructions and autonomously perform file operations, read code, and execute Python scripts.
- File Exploration - List files and directories with metadata
- File Reading - Read and analyze file contents
- Python Execution - Run Python scripts and capture output
- File Writing - Create or modify files
- Agentic Loop - Automatically chains multiple operations to complete complex tasks
- Python >= 3.13
- Google Gemini API key
- Clone the repository:
git clone https://github.com/sanchezcodes/my-first-agent.git
cd my-first-agent- Install dependencies using
uv:
uv sync- Create a
.envfile with your Gemini API key:
GEMINI_API_KEY='your-api-key-here'
Run the agent with a natural language instruction:
python main.py "your instruction here"# List all files in the working directory
python main.py "List all files in the working directory"
# Run the calculator
python main.py "Run the calculator with expression 3 + 5"
# Create a new file
python main.py "Create a file called hello.txt with the content 'Hello World!'"
# Run tests and get results
python main.py "Run all tests in the calculator and tell me the results"Add --verbose to see detailed information about token usage and function calls:
python main.py "your instruction" --verbosemy-first-agent/
├── main.py # Agent entry point
├── call_function.py # Function routing and execution
├── config.py # Configuration constants
├── prompts.py # System prompts for the LLM
├── functions/ # Tool implementations
│ ├── get_files_info.py
│ ├── get_file_content.py
│ ├── run_python_file.py
│ └── write_file.py
└── calculator/ # Sample application for testing
├── main.py
├── tests.py
└── pkg/
├── calculator.py
└── render.py
| Tool | Description |
|---|---|
get_files_info |
Lists files and directories with size and type information |
get_file_content |
Reads the content of a file (up to 10,000 characters) |
run_python_file |
Executes a Python script with optional arguments |
write_file |
Creates or overwrites a file with specified content |
Edit config.py to customize:
MAX_CHARS = 10000 # Max characters to read from files
WORKING_DIR = "./calculator" # Restricted working directory
MAX_ITERS = 20 # Max agent loop iterationsThe agent includes several safety measures:
- Path validation to prevent directory traversal
- Working directory sandboxing
- Process execution timeout (30 seconds)
- File size limits
MIT