# shahzaibkaramat67-coder/langchain_tool_agent architecture

> Architecture diagram of the GitHub repository shahzaibkaramat67-coder/langchain_tool_agent, 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/shahzaibkaramat67-coder/langchain_tool_agent
- Repository: https://github.com/shahzaibkaramat67-coder/langchain_tool_agent

## Overview

This is a command-line research assistant. A user submits a question; the agent decides whether to use search, webpage reading, or calculation, then a formatter model turns the agent’s result into a structured answer. Search results are followed by webpage extraction. The model factory configures the OpenRouter-backed chat model. Edges reflect the calls and tool registration visible in agent.py and the tool implementations; external services are shown only where the code supports them.

Main entry points: [`agent.py`](https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/agent.py) (Question agent), [`research_tool.py`](https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/research_tool.py) (Web search tool), [`web_reader.py`](https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/web_reader.py) (Webpage reader), [`model.py`](https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/model.py) (Chat model client)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_orchestration["Question workflow"]
  node_agent["Question agent<br/>[agent.py]"]
  node_formatter["Answer formatter<br/>[agent.py]"]
end

subgraph group_tools["Research tools"]
  node_search_tool["Web search tool<br/>[research_tool.py]"]
  node_web_reader["Webpage reader<br/>[web_reader.py]"]
  node_calculator["Calculator<br/>[calculator.py]"]
end

subgraph group_models["Model integration"]
  node_model_factory["Model factory<br/>[model.py]"]
  node_chat_model["Chat model client<br/>[model.py]"]
end

node_user(("User"))
node_openrouter{{"OpenRouter API"}}
node_search_service{{"DuckDuckGo search"}}
node_websites{{"Websites"}}

node_user -->|"submits question"| node_agent
node_agent -->|"prints answer"| node_user
node_agent -->|"creates clients"| node_model_factory
node_model_factory -->|"configures"| node_chat_model
node_chat_model -->|"calls API"| node_openrouter
node_agent -->|"formats result"| node_formatter
node_formatter -->|"streams completion"| node_chat_model
node_agent -->|"registers tool"| node_search_tool
node_agent -->|"registers tool"| node_web_reader
node_agent -->|"registers tool"| node_calculator
node_search_tool -->|"searches query"| node_search_service
node_search_tool -->|"reads result pages"| node_web_reader
node_web_reader -->|"fetches page"| node_websites

click node_agent "https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/agent.py"
click node_formatter "https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/agent.py"
click node_model_factory "https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/model.py"
click node_chat_model "https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/model.py"
click node_search_tool "https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/research_tool.py"
click node_web_reader "https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/web_reader.py"
click node_calculator "https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/calculator.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_agent,node_formatter,node_user toneBlue
class node_search_tool,node_web_reader,node_calculator toneAmber
class node_model_factory,node_chat_model,node_openrouter toneMint
class node_search_service,node_websites toneIndigo
```

## Components

### Question workflow

- [Question agent](https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/agent.py): `agent.py`
- [Answer formatter](https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/agent.py): `agent.py`

### Research tools

- [Web search tool](https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/research_tool.py): `research_tool.py`
- [Webpage reader](https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/web_reader.py): `web_reader.py`
- [Calculator](https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/calculator.py): `calculator.py`

### Model integration

- [Model factory](https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/model.py): `model.py`
- [Chat model client](https://github.com/shahzaibkaramat67-coder/langchain_tool_agent/blob/main/model.py): `model.py`

### Other components

- **User**
- **OpenRouter API**
- **DuckDuckGo search**
- **Websites**

## Connections

- User → Question agent: submits question (evidence: `agent.py`)
- Question agent → User: prints answer (evidence: `agent.py`)
- Question agent → Model factory: creates clients (evidence: `agent.py`)
- Model factory → Chat model client: configures (evidence: `model.py`)
- Chat model client → OpenRouter API: calls API (evidence: `model.py`)
- Question agent → Answer formatter: formats result (evidence: `agent.py`)
- Answer formatter → Chat model client: streams completion (evidence: `agent.py`)
- Question agent → Web search tool: registers tool (evidence: `agent.py`)
- Question agent → Webpage reader: registers tool (evidence: `agent.py`)
- Question agent → Calculator: registers tool (evidence: `agent.py`)
- Web search tool → DuckDuckGo search: searches query (evidence: `research_tool.py`)
- Web search tool → Webpage reader: reads result pages (evidence: `research_tool.py`)
- Webpage reader → Websites: fetches page (evidence: `web_reader.py`)
