# induseuro-labs/intern-assignment-llm-cost-optimization architecture

> Architecture diagram of the GitHub repository induseuro-labs/intern-assignment-llm-cost-optimization, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-14). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/induseuro-labs/intern-assignment-llm-cost-optimization
- Repository: https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization

## Overview

ShopAssist is an e-commerce Tier-1 support copilot: it loads a ticket and its order, chooses a resolution, cites a help-center policy, and (in Q1) drafts a customer reply. Q1 makes one model-simulator call; Q2 orchestrates triage, retrieval, composition, and audit calls before parsing a resolution. Shared runtime modules provide ticket/order access, article loading, simulated decisions, token counting, and per-call cost accounting. The README documents these capabilities; edges below reflect shown calls and data reads, not an assumed live-model integration.

Main entry points: [`shared/llm.py`](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/shared/llm.py) (Local LLM simulator), [`question2/agent.py`](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py) (Pipeline controller), [`question1/agent.py`](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/question1/agent.py) (Single-call copilot), [`shared/tools.py`](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/shared/tools.py) (Ticket and order access)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_workflows["Support workflows"]
  node_q1["Single-call copilot<br/>[agent.py]"]
  node_q2["Pipeline controller<br/>[agent.py]"]
  node_triage["Triage stage<br/>[agent.py]"]
  node_retrieve["Article retrieval<br/>[agent.py]"]
  node_compose["Reply composition<br/>[agent.py]"]
  node_audit["Policy audit<br/>[agent.py]"]
end

subgraph group_shared["Shared runtime"]
  node_ticket_order_tools["Ticket and order access<br/>[tools.py]"]
  node_llm_simulator["Local LLM simulator<br/>[llm.py]"]
  node_decision_rules["Resolution rules<br/>[reference.py]"]
  node_kb_loader["Help-center loader<br/>[kb.py]"]
  node_token_counter["Token counter<br/>[tokens.py]"]
end

subgraph group_policy_data["Policy and case data"]
  node_ticket_data[("Ticket records")]
  node_order_data[("Order records")]
  node_articles["Policy articles"]
end

subgraph group_accounting["Cost accounting"]
  node_cost_session["Call cost session<br/>[billing.py]"]
end

node_support_user(("Support operator"))

node_support_user -->|"submits ticket"| node_q1
node_support_user -->|"submits ticket"| node_q2
node_q1 -->|"loads case"| node_ticket_order_tools
node_q1 -->|"loads articles"| node_kb_loader
node_q1 -->|"requests resolution"| node_llm_simulator
node_q1 -->|"creates session"| node_cost_session
node_q2 -->|"loads case"| node_ticket_order_tools
node_q2 -->|"loads help center"| node_kb_loader
node_q2 -->|"runs"| node_triage
node_triage -->|"requests triage"| node_llm_simulator
node_triage -->|"passes triage"| node_retrieve
node_retrieve -->|"requests articles"| node_llm_simulator
node_retrieve -->|"passes articles"| node_compose
node_compose -->|"requests draft"| node_llm_simulator
node_compose -->|"passes draft"| node_audit
node_audit -->|"requests audit"| node_llm_simulator
node_q2 -->|"creates session"| node_cost_session
node_ticket_order_tools -->|"reads tickets"| node_ticket_data
node_ticket_order_tools -->|"reads orders"| node_order_data
node_kb_loader -->|"reads articles"| node_articles
node_llm_simulator -->|"gets outcome"| node_decision_rules
node_llm_simulator -->|"records call"| node_cost_session
node_llm_simulator -->|"counts prefix"| node_token_counter
node_cost_session -->|"counts tokens"| node_token_counter
node_kb_loader -->|"sizes articles"| node_token_counter
node_q2 -->|"parses resolution"| node_q1

click node_q1 "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/question1/agent.py"
click node_q2 "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py"
click node_triage "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py"
click node_retrieve "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py"
click node_compose "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py"
click node_audit "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py"
click node_ticket_order_tools "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/shared/tools.py"
click node_llm_simulator "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/shared/llm.py"
click node_decision_rules "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/eval/reference.py"
click node_kb_loader "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/shared/kb.py"
click node_token_counter "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/shared/tokens.py"
click node_ticket_data "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/tree/main/data/tickets"
click node_order_data "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/tree/main/data/orders"
click node_articles "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/tree/main/data/kb"
click node_cost_session "https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/shared/billing.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_q1,node_q2,node_triage,node_retrieve,node_compose,node_audit toneBlue
class node_ticket_order_tools,node_llm_simulator,node_decision_rules,node_kb_loader,node_token_counter toneAmber
class node_ticket_data,node_order_data,node_articles toneMint
class node_cost_session toneRose
class node_support_user toneIndigo
```

## Components

### Support workflows

- [Single-call copilot](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/question1/agent.py): `question1/agent.py`
- [Pipeline controller](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py): `question2/agent.py`
- [Triage stage](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py): `question2/agent.py`
- [Article retrieval](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py): `question2/agent.py`
- [Reply composition](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py): `question2/agent.py`
- [Policy audit](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py): `question2/agent.py`

### Shared runtime

- [Ticket and order access](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/shared/tools.py): `shared/tools.py`
- [Local LLM simulator](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/shared/llm.py): `shared/llm.py`
- [Resolution rules](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/eval/reference.py): `eval/reference.py`
- [Help-center loader](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/shared/kb.py): `shared/kb.py`
- [Token counter](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/shared/tokens.py): `shared/tokens.py`

### Policy and case data

- [Ticket records](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/tree/main/data/tickets): `data/tickets`
- [Order records](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/tree/main/data/orders): `data/orders`
- [Policy articles](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/tree/main/data/kb): `data/kb`

### Cost accounting

- [Call cost session](https://github.com/induseuro-labs/intern-assignment-llm-cost-optimization/blob/main/shared/billing.py): `shared/billing.py`

### Other components

- **Support operator**

## Connections

- Support operator → Single-call copilot: submits ticket (evidence: `README.md`)
- Support operator → Pipeline controller: submits ticket (evidence: `README.md`)
- Single-call copilot → Ticket and order access: loads case (evidence: `question1/agent.py`)
- Single-call copilot → Help-center loader: loads articles (evidence: `question1/agent.py`)
- Single-call copilot → Local LLM simulator: requests resolution (evidence: `question1/agent.py`)
- Single-call copilot → Call cost session: creates session (evidence: `question1/agent.py`)
- Pipeline controller → Ticket and order access: loads case (evidence: `question2/agent.py`)
- Pipeline controller → Help-center loader: loads help center (evidence: `question2/agent.py`)
- Pipeline controller → Triage stage: runs (evidence: `question2/agent.py`)
- Triage stage → Local LLM simulator: requests triage (evidence: `question2/agent.py`)
- Triage stage → Article retrieval: passes triage (evidence: `question2/agent.py`)
- Article retrieval → Local LLM simulator: requests articles (evidence: `question2/agent.py`)
- Article retrieval → Reply composition: passes articles (evidence: `question2/agent.py`)
- Reply composition → Local LLM simulator: requests draft (evidence: `question2/agent.py`)
- Reply composition → Policy audit: passes draft (evidence: `question2/agent.py`)
- Policy audit → Local LLM simulator: requests audit (evidence: `question2/agent.py`)
- Pipeline controller → Call cost session: creates session (evidence: `question2/agent.py`)
- Ticket and order access → Ticket records: reads tickets (evidence: `shared/tools.py`)
- Ticket and order access → Order records: reads orders (evidence: `shared/tools.py`)
- Help-center loader → Policy articles: reads articles (evidence: `shared/kb.py`)
- Local LLM simulator → Resolution rules: gets outcome (evidence: `shared/llm.py`)
- Local LLM simulator → Call cost session: records call (evidence: `shared/llm.py`)
- Local LLM simulator → Token counter: counts prefix (evidence: `shared/llm.py`)
- Call cost session → Token counter: counts tokens (evidence: `shared/billing.py`)
- Help-center loader → Token counter: sizes articles (evidence: `shared/kb.py`)
- Pipeline controller → Single-call copilot: parses resolution (evidence: `question2/agent.py`)
