# amirmasoudcs/react-agent architecture

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

- Interactive diagram: https://gitdiagram.com/amirmasoudcs/react-agent
- Repository: https://github.com/amirmasoudcs/react-agent

## Overview

ReAct-Agent is a local Ollama-backed assistant exposed through a FastAPI web API and a command-line interface. In the web workflow, a user submits a message through the React chat; the backend runs the ReAct loop, optionally invokes tools, and streams a response while conversation state is persisted. Session management, title generation, and context summarization support conversation continuity. The README also documents configurable model settings and several research and utility tools. Some backend API wiring is supported by the source index rather than a complete excerpt, so unsampled details are not expanded.

Main entry points: [`api.py`](https://github.com/amirmasoudcs/react-agent/blob/main/api.py) (HTTP API), [`agent.py`](https://github.com/amirmasoudcs/react-agent/blob/main/agent.py) (ReAct loop), [`tools/registry.py`](https://github.com/amirmasoudcs/react-agent/blob/main/tools/registry.py) (Tool registry), [`llm/client.py`](https://github.com/amirmasoudcs/react-agent/blob/main/llm/client.py) (Ollama client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_frontend["Web interface"]
  node_web["Chat UI<br/>[App.jsx]"]
  node_chat["Chat interaction<br/>[useChat.js]"]
  node_sessions_ui["Session controls<br/>[useSessions.js]"]
  node_chat_view["Messages and activity<br/>[MessageList.jsx]"]
  node_settings["Model settings<br/>[SettingsModal.jsx]"]
end

subgraph group_backend["Agent runtime"]
  node_api["HTTP API<br/>[api.py]"]
  node_cli["Command-line interface<br/>[main.py]"]
  node_agent["ReAct loop<br/>[agent.py]"]
  node_llm["Ollama client<br/>[client.py]"]
  node_parser["ReAct response parser<br/>[react_parser.py]"]
  node_prompt["System prompt<br/>[system_prompt.py]"]
end

subgraph group_sessions["Conversation state"]
  node_context["Context compaction<br/>[context_manager.py]"]
  node_title["Session title generation<br/>[session_title.py]"]
  node_store[("Session storage<br/>[session_manager.py]")]
end

subgraph group_tools["Agent tools"]
  node_calculator["Calculator<br/>[calculator.py]"]
  node_datetime["Date and time<br/>[datetime.py]"]
  node_weather["Weather lookup<br/>[weather.py]"]
  node_web_search["Web search<br/>[web_search.py]"]
  node_wiki["Wikipedia search"]
  node_registry["Tool registry<br/>[registry.py]"]
end

node_user(("User"))
node_ollama(("Ollama service"))
node_external_data(("External search and weather services"))

node_user -->|"submits message"| node_web
node_web -->|"delegates chat"| node_chat
node_chat -->|"sends requests"| node_api
node_api -->|"runs agent"| node_agent
node_agent -->|"requests completion"| node_llm
node_llm -->|"calls model"| node_ollama
node_agent -->|"parses response"| node_parser
node_agent -->|"builds prompt"| node_prompt
node_agent -->|"dispatches tools"| node_registry
node_registry -.->|"registers tool"| node_calculator
node_registry -.->|"registers tool"| node_datetime
node_registry -.->|"registers tool"| node_weather
node_registry -.->|"registers tool"| node_web_search
node_registry -.->|"registers tool"| node_wiki
node_weather -.->|"looks up weather"| node_external_data
node_web_search -.->|"searches web"| node_external_data
node_wiki -->|"queries Wikipedia"| node_external_data
node_agent -->|"builds context"| node_context
node_context -->|"summarizes history"| node_llm
node_context -.->|"loads and saves summary"| node_store
node_api -->|"manages sessions"| node_store
node_api -->|"generates titles"| node_title
node_title -->|"requests title"| node_llm
node_title -->|"checks names"| node_store
node_cli -->|"runs agent"| node_agent
node_cli -->|"manages sessions"| node_store
node_cli -->|"configures context"| node_context
node_api -.->|"streams responses"| node_llm
node_api -.->|"streams responses"| node_chat
node_chat -->|"renders activity"| node_chat_view
node_web -->|"loads sessions"| node_sessions_ui
node_sessions_ui -.->|"manages sessions"| node_api
node_web -->|"opens settings"| node_settings
node_settings -.->|"configures model"| node_api

click node_web "https://github.com/amirmasoudcs/react-agent/blob/main/frontend/src/App.jsx"
click node_chat "https://github.com/amirmasoudcs/react-agent/blob/main/frontend/src/hooks/useChat.js"
click node_sessions_ui "https://github.com/amirmasoudcs/react-agent/blob/main/frontend/src/hooks/useSessions.js"
click node_chat_view "https://github.com/amirmasoudcs/react-agent/blob/main/frontend/src/components/MessageList.jsx"
click node_settings "https://github.com/amirmasoudcs/react-agent/blob/main/frontend/src/components/SettingsModal.jsx"
click node_api "https://github.com/amirmasoudcs/react-agent/blob/main/api.py"
click node_cli "https://github.com/amirmasoudcs/react-agent/blob/main/main.py"
click node_agent "https://github.com/amirmasoudcs/react-agent/blob/main/agent.py"
click node_llm "https://github.com/amirmasoudcs/react-agent/blob/main/llm/client.py"
click node_parser "https://github.com/amirmasoudcs/react-agent/blob/main/utils/react_parser.py"
click node_prompt "https://github.com/amirmasoudcs/react-agent/blob/main/prompts/system_prompt.py"
click node_context "https://github.com/amirmasoudcs/react-agent/blob/main/utils/context_manager.py"
click node_title "https://github.com/amirmasoudcs/react-agent/blob/main/utils/session_title.py"
click node_store "https://github.com/amirmasoudcs/react-agent/blob/main/utils/session_manager.py"
click node_calculator "https://github.com/amirmasoudcs/react-agent/blob/main/tools/calculator.py"
click node_datetime "https://github.com/amirmasoudcs/react-agent/blob/main/tools/datetime.py"
click node_weather "https://github.com/amirmasoudcs/react-agent/blob/main/tools/weather.py"
click node_web_search "https://github.com/amirmasoudcs/react-agent/blob/main/tools/web_search.py"
click node_wiki "https://github.com/amirmasoudcs/react-agent/blob/main/tools/wikipedia_search.py"
click node_registry "https://github.com/amirmasoudcs/react-agent/blob/main/tools/registry.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_web,node_chat,node_sessions_ui,node_chat_view,node_settings,node_user toneBlue
class node_api,node_cli,node_agent,node_llm,node_parser,node_prompt toneAmber
class node_context,node_title,node_store toneMint
class node_calculator,node_datetime,node_weather,node_web_search,node_wiki,node_registry toneRose
class node_ollama,node_external_data toneIndigo
```

## Components

### Web interface

- [Chat UI](https://github.com/amirmasoudcs/react-agent/blob/main/frontend/src/App.jsx): `frontend/src/App.jsx`
- [Chat interaction](https://github.com/amirmasoudcs/react-agent/blob/main/frontend/src/hooks/useChat.js): `frontend/src/hooks/useChat.js`
- [Session controls](https://github.com/amirmasoudcs/react-agent/blob/main/frontend/src/hooks/useSessions.js): `frontend/src/hooks/useSessions.js`
- [Messages and activity](https://github.com/amirmasoudcs/react-agent/blob/main/frontend/src/components/MessageList.jsx): `frontend/src/components/MessageList.jsx`
- [Model settings](https://github.com/amirmasoudcs/react-agent/blob/main/frontend/src/components/SettingsModal.jsx): `frontend/src/components/SettingsModal.jsx`

### Agent runtime

- [HTTP API](https://github.com/amirmasoudcs/react-agent/blob/main/api.py): `api.py`
- [Command-line interface](https://github.com/amirmasoudcs/react-agent/blob/main/main.py): `main.py`
- [ReAct loop](https://github.com/amirmasoudcs/react-agent/blob/main/agent.py): `agent.py`
- [Ollama client](https://github.com/amirmasoudcs/react-agent/blob/main/llm/client.py): `llm/client.py`
- [ReAct response parser](https://github.com/amirmasoudcs/react-agent/blob/main/utils/react_parser.py): `utils/react_parser.py`
- [System prompt](https://github.com/amirmasoudcs/react-agent/blob/main/prompts/system_prompt.py): `prompts/system_prompt.py`

### Conversation state

- [Context compaction](https://github.com/amirmasoudcs/react-agent/blob/main/utils/context_manager.py): `utils/context_manager.py`
- [Session title generation](https://github.com/amirmasoudcs/react-agent/blob/main/utils/session_title.py): `utils/session_title.py`
- [Session storage](https://github.com/amirmasoudcs/react-agent/blob/main/utils/session_manager.py): `utils/session_manager.py`

### Agent tools

- [Calculator](https://github.com/amirmasoudcs/react-agent/blob/main/tools/calculator.py): `tools/calculator.py`
- [Date and time](https://github.com/amirmasoudcs/react-agent/blob/main/tools/datetime.py): `tools/datetime.py`
- [Weather lookup](https://github.com/amirmasoudcs/react-agent/blob/main/tools/weather.py): `tools/weather.py`
- [Web search](https://github.com/amirmasoudcs/react-agent/blob/main/tools/web_search.py): `tools/web_search.py`
- [Wikipedia search](https://github.com/amirmasoudcs/react-agent/blob/main/tools/wikipedia_search.py): `tools/wikipedia_search.py`
- [Tool registry](https://github.com/amirmasoudcs/react-agent/blob/main/tools/registry.py): `tools/registry.py`

### Other components

- **User**
- **Ollama service**
- **External search and weather services**

## Connections

- User → Chat UI: submits message (evidence: `frontend/src/App.jsx`)
- Chat UI → Chat interaction: delegates chat (evidence: `frontend/src/App.jsx`)
- Chat interaction → HTTP API: sends requests (evidence: `frontend/src/hooks/useChat.js`)
- HTTP API → ReAct loop: runs agent (evidence: `api.py`)
- ReAct loop → Ollama client: requests completion (evidence: `agent.py`)
- Ollama client → Ollama service: calls model (evidence: `llm/client.py`)
- ReAct loop → ReAct response parser: parses response (evidence: `agent.py`)
- ReAct loop → System prompt: builds prompt (evidence: `agent.py`)
- ReAct loop → Tool registry: dispatches tools (evidence: `agent.py`)
- Tool registry → Calculator: registers tool
- Tool registry → Date and time: registers tool
- Tool registry → Weather lookup: registers tool
- Tool registry → Web search: registers tool
- Tool registry → Wikipedia search: registers tool
- Weather lookup → External search and weather services: looks up weather
- Web search → External search and weather services: searches web
- Wikipedia search → External search and weather services: queries Wikipedia (evidence: `tools/wikipedia_search.py`)
- ReAct loop → Context compaction: builds context (evidence: `agent.py`)
- Context compaction → Ollama client: summarizes history (evidence: `utils/context_manager.py`)
- Context compaction → Session storage: loads and saves summary
- HTTP API → Session storage: manages sessions (evidence: `api.py`)
- HTTP API → Session title generation: generates titles (evidence: `api.py`)
- Session title generation → Ollama client: requests title (evidence: `utils/session_title.py`)
- Session title generation → Session storage: checks names (evidence: `utils/session_title.py`)
- Command-line interface → ReAct loop: runs agent (evidence: `main.py`)
- Command-line interface → Session storage: manages sessions (evidence: `main.py`)
- Command-line interface → Context compaction: configures context (evidence: `main.py`)
- HTTP API → Ollama client: streams responses (evidence: `api.py`)
- HTTP API → Chat interaction: streams responses
- Chat interaction → Messages and activity: renders activity (evidence: `frontend/src/App.jsx`)
- Chat UI → Session controls: loads sessions (evidence: `frontend/src/App.jsx`)
- Session controls → HTTP API: manages sessions
- Chat UI → Model settings: opens settings (evidence: `frontend/src/App.jsx`)
- Model settings → HTTP API: configures model
