# devesh176/py_agent architecture

> Architecture diagram of the GitHub repository devesh176/py_agent, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-12-01). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/devesh176/py_agent
- Repository: https://github.com/devesh176/py_agent

## Overview

py_agent is an interactive Gemini-powered coding assistant. A user submits a task; the CLI sends conversation history and tool definitions to Gemini, executes returned tool calls in the configured calculator sandbox, and feeds results back until Gemini responds or the iteration limit is reached. The tools cover directory inspection, file reading and writing, and Python execution; task metrics record usage and outcomes. The calculator is the shipped example sandbox. The main loop and tools are excerpted; other connections are included only where the README or source index supports them.

Main entry points: [`main.py`](https://github.com/devesh176/py_agent/blob/main/main.py) (Interactive CLI), [`functions/call_function.py`](https://github.com/devesh176/py_agent/blob/main/functions/call_function.py) (Tool dispatcher), [`calculator/main.py`](https://github.com/devesh176/py_agent/blob/main/calculator/main.py) (Calculator CLI), [`prompts.py`](https://github.com/devesh176/py_agent/blob/main/prompts.py) (System prompts)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_agent["Agent runtime"]
  node_cli["Interactive CLI<br/>[main.py]"]
  node_prompts["System prompts<br/>[prompts.py]"]
end

subgraph group_tools["Sandbox tools"]
  node_dispatcher["Tool dispatcher<br/>[call_function.py]"]
  node_listing["Directory listing<br/>[get_files_info.py]"]
  node_reading["File reading"]
  node_writing["File writing<br/>[write_file.py]"]
  node_execution["Python execution<br/>[run_python_file.py]"]
end

subgraph group_observability["Task observability"]
  node_metrics["Task metrics<br/>[metrics.py]"]
end

subgraph group_calculator["Example calculator"]
  node_calculator_cli["Calculator CLI<br/>[main.py]"]
  node_evaluator["Expression evaluator<br/>[calculator.py]"]
  node_renderer["Result renderer<br/>[render.py]"]
end

node_user(("User"))
node_gemini["Gemini API"]

node_user -->|"submits task"| node_cli
node_cli -->|"configures prompt"| node_prompts
node_cli -->|"sends conversation"| node_gemini
node_gemini -->|"returns response"| node_cli
node_cli -->|"dispatches calls"| node_dispatcher
node_dispatcher -->|"dispatches"| node_listing
node_dispatcher -->|"dispatches"| node_reading
node_dispatcher -->|"dispatches"| node_writing
node_dispatcher -->|"dispatches"| node_execution
node_cli -->|"records task data"| node_metrics
node_calculator_cli -->|"evaluates expression"| node_evaluator
node_calculator_cli -->|"formats result"| node_renderer

click node_cli "https://github.com/devesh176/py_agent/blob/main/main.py"
click node_prompts "https://github.com/devesh176/py_agent/blob/main/prompts.py"
click node_dispatcher "https://github.com/devesh176/py_agent/blob/main/functions/call_function.py"
click node_listing "https://github.com/devesh176/py_agent/blob/main/functions/get_files_info.py"
click node_reading "https://github.com/devesh176/py_agent/blob/main/functions/get_file_content.py"
click node_writing "https://github.com/devesh176/py_agent/blob/main/functions/write_file.py"
click node_execution "https://github.com/devesh176/py_agent/blob/main/functions/run_python_file.py"
click node_metrics "https://github.com/devesh176/py_agent/blob/main/metrics.py"
click node_calculator_cli "https://github.com/devesh176/py_agent/blob/main/calculator/main.py"
click node_evaluator "https://github.com/devesh176/py_agent/blob/main/calculator/pkg/calculator.py"
click node_renderer "https://github.com/devesh176/py_agent/blob/main/calculator/pkg/render.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_cli,node_prompts,node_user toneBlue
class node_dispatcher,node_listing,node_reading,node_writing,node_execution toneAmber
class node_metrics,node_gemini toneMint
class node_calculator_cli,node_evaluator,node_renderer toneRose
```

## Components

### Agent runtime

- [Interactive CLI](https://github.com/devesh176/py_agent/blob/main/main.py): `main.py`
- [System prompts](https://github.com/devesh176/py_agent/blob/main/prompts.py): `prompts.py`

### Sandbox tools

- [Tool dispatcher](https://github.com/devesh176/py_agent/blob/main/functions/call_function.py): `functions/call_function.py`
- [Directory listing](https://github.com/devesh176/py_agent/blob/main/functions/get_files_info.py): `functions/get_files_info.py`
- [File reading](https://github.com/devesh176/py_agent/blob/main/functions/get_file_content.py): `functions/get_file_content.py`
- [File writing](https://github.com/devesh176/py_agent/blob/main/functions/write_file.py): `functions/write_file.py`
- [Python execution](https://github.com/devesh176/py_agent/blob/main/functions/run_python_file.py): `functions/run_python_file.py`

### Task observability

- [Task metrics](https://github.com/devesh176/py_agent/blob/main/metrics.py): `metrics.py`

### Example calculator

- [Calculator CLI](https://github.com/devesh176/py_agent/blob/main/calculator/main.py): `calculator/main.py`
- [Expression evaluator](https://github.com/devesh176/py_agent/blob/main/calculator/pkg/calculator.py): `calculator/pkg/calculator.py`
- [Result renderer](https://github.com/devesh176/py_agent/blob/main/calculator/pkg/render.py): `calculator/pkg/render.py`

### Other components

- **User**
- **Gemini API**

## Connections

- User → Interactive CLI: submits task (evidence: `README.md`)
- Interactive CLI → System prompts: configures prompt (evidence: `main.py`)
- Interactive CLI → Gemini API: sends conversation (evidence: `main.py`)
- Gemini API → Interactive CLI: returns response (evidence: `main.py`)
- Interactive CLI → Tool dispatcher: dispatches calls (evidence: `main.py`)
- Tool dispatcher → Directory listing: dispatches (evidence: `functions/call_function.py`)
- Tool dispatcher → File reading: dispatches (evidence: `functions/call_function.py`)
- Tool dispatcher → File writing: dispatches (evidence: `functions/call_function.py`)
- Tool dispatcher → Python execution: dispatches (evidence: `functions/call_function.py`)
- Interactive CLI → Task metrics: records task data (evidence: `main.py`)
- Calculator CLI → Expression evaluator: evaluates expression (evidence: `calculator/main.py`)
- Calculator CLI → Result renderer: formats result (evidence: `calculator/main.py`)
