# ilijakamenko/llm_pid_tuner architecture

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

- Interactive diagram: https://gitdiagram.com/ilijakamenko/llm_pid_tuner
- Repository: https://github.com/ilijakamenko/llm_pid_tuner

## Overview

This Python application iteratively tunes PID gains against a modeled plant. The user starts `main.py`, which simulates the closed-loop step response and passes it to `LLM_PID_Tuner`; the tuner evaluates response metrics and, unless early stopping applies, requests updated gains from an OpenAI-compatible API. The loop applies those gains, plots responses, and returns a history table. The README documents OpenAI and Ollama options; the sampled source shows both configured through the same client interface. The graph follows sampled runtime code; the standalone delay helper is not wired into this workflow.

Main entry points: [`main.py`](https://github.com/ilijakamenko/llm_pid_tuner/blob/main/main.py) (Tuning Runner), [`llm_pid_tuner.py`](https://github.com/ilijakamenko/llm_pid_tuner/blob/main/llm_pid_tuner.py) (Tuning Logic), [`pid_controller.py`](https://github.com/ilijakamenko/llm_pid_tuner/blob/main/pid_controller.py) (PID Controller)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_execution["Simulation"]
  node_main["Tuning Runner<br/>[main.py]"]
  node_control["Control Library"]
  node_results["Plots and History<br/>[main.py]"]
end

subgraph group_tuning["PID Tuning"]
  node_pid["PID Controller<br/>[pid_controller.py]"]
  node_tuner["Tuning Logic<br/>[llm_pid_tuner.py]"]
  node_metrics["Response Metrics<br/>[llm_pid_tuner.py]"]
end

subgraph group_integrations["External Integrations"]
  node_llm["LLM Client<br/>[llm_pid_tuner.py]"]
  node_openai["OpenAI API"]
  node_ollama["Ollama API"]
end

node_user(("User"))
node_plant["Plant Model"]

node_user -->|"starts"| node_main
node_main -->|"copies and updates"| node_pid
node_main -->|"builds transfer function"| node_pid
node_main -->|"simulates against"| node_plant
node_main -->|"computes response"| node_control
node_main -->|"passes response"| node_tuner
node_tuner -->|"computes metrics"| node_metrics
node_metrics -->|"uses step info"| node_control
node_tuner -->|"requests gains"| node_llm
node_llm -.->|"calls when GPT model"| node_openai
node_llm -.->|"calls otherwise"| node_ollama
node_tuner -->|"returns updated gains"| node_main
node_main -->|"plots and returns"| node_results

click node_main "https://github.com/ilijakamenko/llm_pid_tuner/blob/main/main.py"
click node_pid "https://github.com/ilijakamenko/llm_pid_tuner/blob/main/pid_controller.py"
click node_tuner "https://github.com/ilijakamenko/llm_pid_tuner/blob/main/llm_pid_tuner.py"
click node_metrics "https://github.com/ilijakamenko/llm_pid_tuner/blob/main/llm_pid_tuner.py"
click node_llm "https://github.com/ilijakamenko/llm_pid_tuner/blob/main/llm_pid_tuner.py"
click node_results "https://github.com/ilijakamenko/llm_pid_tuner/blob/main/main.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_main,node_control,node_results,node_user toneBlue
class node_pid,node_tuner,node_metrics toneAmber
class node_llm,node_openai,node_ollama toneMint
class node_plant toneIndigo
```

## Components

### Simulation

- [Tuning Runner](https://github.com/ilijakamenko/llm_pid_tuner/blob/main/main.py): `main.py`
- **Control Library**
- [Plots and History](https://github.com/ilijakamenko/llm_pid_tuner/blob/main/main.py): `main.py`

### PID Tuning

- [PID Controller](https://github.com/ilijakamenko/llm_pid_tuner/blob/main/pid_controller.py): `pid_controller.py`
- [Tuning Logic](https://github.com/ilijakamenko/llm_pid_tuner/blob/main/llm_pid_tuner.py): `llm_pid_tuner.py`
- [Response Metrics](https://github.com/ilijakamenko/llm_pid_tuner/blob/main/llm_pid_tuner.py): `llm_pid_tuner.py`

### External Integrations

- [LLM Client](https://github.com/ilijakamenko/llm_pid_tuner/blob/main/llm_pid_tuner.py): `llm_pid_tuner.py`
- **OpenAI API**
- **Ollama API**

### Other components

- **User**
- **Plant Model**

## Connections

- User → Tuning Runner: starts
- Tuning Runner → PID Controller: copies and updates
- Tuning Runner → PID Controller: builds transfer function
- Tuning Runner → Plant Model: simulates against
- Tuning Runner → Control Library: computes response
- Tuning Runner → Tuning Logic: passes response
- Tuning Logic → Response Metrics: computes metrics
- Response Metrics → Control Library: uses step info
- Tuning Logic → LLM Client: requests gains
- LLM Client → OpenAI API: calls when GPT model
- LLM Client → Ollama API: calls otherwise
- Tuning Logic → Tuning Runner: returns updated gains
- Tuning Runner → Plots and History: plots and returns
