# top-q/agent-q architecture

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

- Interactive diagram: https://gitdiagram.com/top-q/agent-q
- Repository: https://github.com/top-q/agent-q

## Overview

Agent Q turns a user task into generated Python actions through a specialized Web, filesystem, or REST agent. Each agent supplies domain-specific instructions and tools to the shared AgentQ runtime, which either executes cached code or asks its model-backed CodeAgent to generate and run code; successful generated code is saved for reuse. The domain tools act on browser pages, local files, or REST endpoints, with web HTML sanitized before use. The README also documents model flexibility and extensibility. Some subsystem links are supported by the SOURCE INDEX rather than full excerpts; the Ollama adapter is included, but its runtime wiring is not established by the sampled evidence.

Main entry points: [`src/agent/agentq.py`](https://github.com/top-q/agent-q/blob/main/src/agent/agentq.py) (AgentQ runtime), [`src/agent/web_agent/web_agent.py`](https://github.com/top-q/agent-q/blob/main/src/agent/web_agent/web_agent.py) (WebAgent), [`src/agent/fs_agent/fs_agent.py`](https://github.com/top-q/agent-q/blob/main/src/agent/fs_agent/fs_agent.py) (FsAgent), [`src/agent/rest_agent/rest_agent.py`](https://github.com/top-q/agent-q/blob/main/src/agent/rest_agent/rest_agent.py) (RestAgent)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_runtime["Agent Runtime"]
  node_agentq["AgentQ runtime<br/>[agentq.py]"]
  node_shared_prompt["Shared instructions<br/>[prompt.py]"]
  node_definitions["Root path config<br/>[definitions.py]"]
end

subgraph group_web["Web Automation"]
  node_web_agent["WebAgent<br/>[web_agent.py]"]
  node_web_prompt["Web instructions<br/>[prompt.py]"]
  node_web_tools["Browser tools<br/>[web_tools.py]"]
  node_sanitizer["HTML sanitizer<br/>[sanitizer.py]"]
end

subgraph group_filesystem["Filesystem Tasks"]
  node_fs_agent["FsAgent<br/>[fs_agent.py]"]
  node_fs_prompt["Filesystem instructions<br/>[prompt.py]"]
  node_fs_tools["Filesystem tools<br/>[fs_tools.py]"]
end

subgraph group_rest["REST API Testing"]
  node_rest_agent["RestAgent<br/>[rest_agent.py]"]
  node_rest_prompt["REST instructions<br/>[prompt.py]"]
  node_rest_tools["HTTP and JSON tools<br/>[rest_tools.py]"]
  node_swagger["Petstore Swagger spec"]
end

subgraph group_models["Models and State"]
  node_code_store[("Code cache<br/>[code_store.py]")]
  node_model["Language model"]
  node_ollama["Ollama adapter<br/>[ollama_model.py]"]
end

node_user(("Task user"))
node_browser["Playwright page"]
node_local_files["Local filesystem"]
node_api["REST API"]

node_user -->|"requests task"| node_web_agent
node_user -->|"requests task"| node_fs_agent
node_user -->|"requests task"| node_rest_agent
node_web_agent -->|"delegates"| node_agentq
node_fs_agent -->|"delegates"| node_agentq
node_rest_agent -->|"delegates"| node_agentq
node_agentq -->|"combines instructions"| node_shared_prompt
node_agentq -->|"checks and saves code"| node_code_store
node_agentq -->|"reads root path"| node_definitions
node_agentq -->|"runs code agent"| node_model
node_web_agent -->|"configures"| node_web_prompt
node_web_agent -->|"registers tools"| node_web_tools
node_web_agent -->|"sets page context"| node_browser
node_web_tools -->|"reads and acts on"| node_browser
node_web_tools -->|"sanitizes page HTML"| node_sanitizer
node_fs_agent -->|"configures"| node_fs_prompt
node_fs_agent -->|"registers tools"| node_fs_tools
node_fs_tools -->|"reads and lists"| node_local_files
node_rest_agent -->|"configures"| node_rest_prompt
node_rest_agent -->|"registers tools"| node_rest_tools
node_rest_tools -->|"sends HTTP requests"| node_api
node_user -->|"provides API spec"| node_swagger

click node_agentq "https://github.com/top-q/agent-q/blob/main/src/agent/agentq.py"
click node_shared_prompt "https://github.com/top-q/agent-q/blob/main/src/agent/prompt.py"
click node_code_store "https://github.com/top-q/agent-q/blob/main/src/agent/code_store.py"
click node_definitions "https://github.com/top-q/agent-q/blob/main/definitions.py"
click node_web_agent "https://github.com/top-q/agent-q/blob/main/src/agent/web_agent/web_agent.py"
click node_web_prompt "https://github.com/top-q/agent-q/blob/main/src/agent/web_agent/prompt.py"
click node_web_tools "https://github.com/top-q/agent-q/blob/main/src/agent/web_agent/web_tools.py"
click node_sanitizer "https://github.com/top-q/agent-q/blob/main/src/agent/web_agent/sanitizer.py"
click node_fs_agent "https://github.com/top-q/agent-q/blob/main/src/agent/fs_agent/fs_agent.py"
click node_fs_prompt "https://github.com/top-q/agent-q/blob/main/src/agent/fs_agent/prompt.py"
click node_fs_tools "https://github.com/top-q/agent-q/blob/main/src/agent/fs_agent/fs_tools.py"
click node_rest_agent "https://github.com/top-q/agent-q/blob/main/src/agent/rest_agent/rest_agent.py"
click node_rest_prompt "https://github.com/top-q/agent-q/blob/main/src/agent/rest_agent/prompt.py"
click node_rest_tools "https://github.com/top-q/agent-q/blob/main/src/agent/rest_agent/rest_tools.py"
click node_swagger "https://github.com/top-q/agent-q/blob/main/swagger/swagger_petstore.json"
click node_ollama "https://github.com/top-q/agent-q/blob/main/src/model/ollama_model.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_agentq,node_shared_prompt,node_definitions toneBlue
class node_web_agent,node_web_prompt,node_web_tools,node_sanitizer toneAmber
class node_fs_agent,node_fs_prompt,node_fs_tools,node_api toneMint
class node_rest_agent,node_rest_prompt,node_rest_tools,node_swagger,node_user toneRose
class node_code_store,node_model,node_ollama,node_browser,node_local_files toneIndigo
```

## Components

### Agent Runtime

- [AgentQ runtime](https://github.com/top-q/agent-q/blob/main/src/agent/agentq.py): `src/agent/agentq.py`
- [Shared instructions](https://github.com/top-q/agent-q/blob/main/src/agent/prompt.py): `src/agent/prompt.py`
- [Root path config](https://github.com/top-q/agent-q/blob/main/definitions.py): `definitions.py`

### Web Automation

- [WebAgent](https://github.com/top-q/agent-q/blob/main/src/agent/web_agent/web_agent.py): `src/agent/web_agent/web_agent.py`
- [Web instructions](https://github.com/top-q/agent-q/blob/main/src/agent/web_agent/prompt.py): `src/agent/web_agent/prompt.py`
- [Browser tools](https://github.com/top-q/agent-q/blob/main/src/agent/web_agent/web_tools.py): `src/agent/web_agent/web_tools.py`
- [HTML sanitizer](https://github.com/top-q/agent-q/blob/main/src/agent/web_agent/sanitizer.py): `src/agent/web_agent/sanitizer.py`

### Filesystem Tasks

- [FsAgent](https://github.com/top-q/agent-q/blob/main/src/agent/fs_agent/fs_agent.py): `src/agent/fs_agent/fs_agent.py`
- [Filesystem instructions](https://github.com/top-q/agent-q/blob/main/src/agent/fs_agent/prompt.py): `src/agent/fs_agent/prompt.py`
- [Filesystem tools](https://github.com/top-q/agent-q/blob/main/src/agent/fs_agent/fs_tools.py): `src/agent/fs_agent/fs_tools.py`

### REST API Testing

- [RestAgent](https://github.com/top-q/agent-q/blob/main/src/agent/rest_agent/rest_agent.py): `src/agent/rest_agent/rest_agent.py`
- [REST instructions](https://github.com/top-q/agent-q/blob/main/src/agent/rest_agent/prompt.py): `src/agent/rest_agent/prompt.py`
- [HTTP and JSON tools](https://github.com/top-q/agent-q/blob/main/src/agent/rest_agent/rest_tools.py): `src/agent/rest_agent/rest_tools.py`
- [Petstore Swagger spec](https://github.com/top-q/agent-q/blob/main/swagger/swagger_petstore.json): `swagger/swagger_petstore.json`

### Models and State

- [Code cache](https://github.com/top-q/agent-q/blob/main/src/agent/code_store.py): `src/agent/code_store.py`
- **Language model**
- [Ollama adapter](https://github.com/top-q/agent-q/blob/main/src/model/ollama_model.py): `src/model/ollama_model.py`

### Other components

- **Task user**
- **Playwright page**
- **Local filesystem**
- **REST API**

## Connections

- Task user → WebAgent: requests task (evidence: `README.md`)
- Task user → FsAgent: requests task (evidence: `README.md`)
- Task user → RestAgent: requests task (evidence: `README.md`)
- WebAgent → AgentQ runtime: delegates (evidence: `src/agent/web_agent/web_agent.py`)
- FsAgent → AgentQ runtime: delegates (evidence: `src/agent/fs_agent/fs_agent.py`)
- RestAgent → AgentQ runtime: delegates (evidence: `src/agent/rest_agent/rest_agent.py`)
- AgentQ runtime → Shared instructions: combines instructions (evidence: `src/agent/agentq.py`)
- AgentQ runtime → Code cache: checks and saves code (evidence: `src/agent/agentq.py`)
- AgentQ runtime → Root path config: reads root path (evidence: `src/agent/agentq.py`)
- AgentQ runtime → Language model: runs code agent (evidence: `src/agent/agentq.py`)
- WebAgent → Web instructions: configures (evidence: `src/agent/web_agent/web_agent.py`)
- WebAgent → Browser tools: registers tools (evidence: `src/agent/web_agent/web_agent.py`)
- WebAgent → Playwright page: sets page context (evidence: `src/agent/web_agent/web_agent.py`)
- Browser tools → Playwright page: reads and acts on (evidence: `src/agent/web_agent/web_tools.py`)
- Browser tools → HTML sanitizer: sanitizes page HTML (evidence: `src/agent/web_agent/web_tools.py`)
- FsAgent → Filesystem instructions: configures (evidence: `src/agent/fs_agent/fs_agent.py`)
- FsAgent → Filesystem tools: registers tools (evidence: `src/agent/fs_agent/fs_agent.py`)
- Filesystem tools → Local filesystem: reads and lists (evidence: `src/agent/fs_agent/fs_tools.py`)
- RestAgent → REST instructions: configures (evidence: `src/agent/rest_agent/rest_agent.py`)
- RestAgent → HTTP and JSON tools: registers tools (evidence: `src/agent/rest_agent/rest_agent.py`)
- HTTP and JSON tools → REST API: sends HTTP requests (evidence: `src/agent/rest_agent/rest_tools.py`)
- Task user → Petstore Swagger spec: provides API spec (evidence: `README.md`)
