# ananyasingh456/intern-assignment-llm-cost-optimization architecture

> Architecture diagram of the GitHub repository ananyasingh456/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/ananyasingh456/intern-assignment-llm-cost-optimization
- Repository: https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization

## Overview

ShopAssist is an e-commerce Tier-1 support copilot with two implementations: a single-call baseline and a multi-stage pipeline. Both take a ticket, load its order and conversation, consult help-center content, and return an action with a cited article; the baseline also drafts a customer reply. Shared tools read ticket/order files, while the local LLM simulator applies decision rules and records token-based call costs. Pipeline stages and their handoffs are shown separately. Data directories are identified by the README and tree; unsampled data internals and integrations are not expanded.

Main entry points: [`question2/agent.py`](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py) (Support pipeline), [`shared/llm.py`](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/shared/llm.py) (Local LLM client), [`question1/agent.py`](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question1/agent.py) (Single-call copilot), [`shared/kb.py`](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/shared/kb.py) (Help-center articles)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_agents["Support agents"]
  node_q1["Single-call copilot<br/>[agent.py]"]
  node_q2["Support pipeline<br/>[agent.py]"]
  node_triage["Triage<br/>[agent.py]"]
  node_retrieve["Article retrieval<br/>[agent.py]"]
  node_compose["Reply composition<br/>[agent.py]"]
  node_audit["Resolution audit<br/>[agent.py]"]
  node_parser["Resolution parser<br/>[agent.py]"]
end

subgraph group_policy["Policy and decisions"]
  node_kb["Help-center articles<br/>[kb.py]"]
  node_rules["Order decision rules<br/>[reference.py]"]
end

subgraph group_shared["Shared runtime"]
  node_llm["Local LLM client<br/>[llm.py]"]
  node_billing["Cost session<br/>[billing.py]"]
  node_tokens["Token counter<br/>[tokens.py]"]
  node_tools["Ticket and order tools<br/>[tools.py]"]
end

subgraph group_records["Support records"]
  node_tickets[("Ticket records")]
  node_orders[("Order records")]
  node_articles[("Article files")]
end

node_customer(("Support requester"))

node_customer -->|"submits ticket"| node_q1
node_customer -->|"submits ticket"| node_q2
node_q1 -->|"loads ticket and order"| node_tools
node_tools -->|"reads"| node_tickets
node_tools -->|"reads"| node_orders
node_q1 -->|"loads articles"| node_kb
node_kb -->|"reads"| node_articles
node_q1 -->|"sends prompt"| node_llm
node_q1 -->|"parses completion"| node_parser
node_q2 -->|"loads ticket and order"| node_tools
node_q2 -->|"loads pipeline articles"| node_kb
node_q2 -->|"starts"| node_triage
node_triage -->|"sends triage prompt"| node_llm
node_q2 -->|"passes triage"| node_retrieve
node_retrieve -->|"sends retrieval prompt"| node_llm
node_q2 -->|"passes retrieved content"| node_compose
node_compose -->|"sends composition prompt"| node_llm
node_q2 -->|"passes draft"| node_audit
node_audit -->|"sends audit prompt"| node_llm
node_q2 -->|"parses final output"| node_parser
node_llm -->|"gets outcome"| node_rules
node_llm -->|"records call"| node_billing
node_billing -->|"counts usage"| node_tokens
node_llm -->|"checks cached prefix"| node_tokens
node_kb -->|"measures expanded content"| node_tokens

click node_q1 "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question1/agent.py"
click node_q2 "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py"
click node_triage "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py"
click node_retrieve "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py"
click node_compose "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py"
click node_audit "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py"
click node_parser "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question1/agent.py"
click node_kb "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/shared/kb.py"
click node_rules "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/eval/reference.py"
click node_llm "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/shared/llm.py"
click node_billing "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/shared/billing.py"
click node_tokens "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/shared/tokens.py"
click node_tools "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/shared/tools.py"
click node_tickets "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/tree/main/data/tickets"
click node_orders "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/tree/main/data/orders"
click node_articles "https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/tree/main/data/kb"

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,node_parser toneBlue
class node_kb,node_rules toneAmber
class node_llm,node_billing,node_tokens,node_tools,node_customer toneMint
class node_tickets,node_orders,node_articles toneRose
```

## Components

### Support agents

- [Single-call copilot](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question1/agent.py): `question1/agent.py`
- [Support pipeline](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py): `question2/agent.py`
- [Triage](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py): `question2/agent.py`
- [Article retrieval](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py): `question2/agent.py`
- [Reply composition](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py): `question2/agent.py`
- [Resolution audit](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question2/agent.py): `question2/agent.py`
- [Resolution parser](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/question1/agent.py): `question1/agent.py`

### Policy and decisions

- [Help-center articles](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/shared/kb.py): `shared/kb.py`
- [Order decision rules](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/eval/reference.py): `eval/reference.py`

### Shared runtime

- [Local LLM client](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/shared/llm.py): `shared/llm.py`
- [Cost session](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/shared/billing.py): `shared/billing.py`
- [Token counter](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/shared/tokens.py): `shared/tokens.py`
- [Ticket and order tools](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/blob/main/shared/tools.py): `shared/tools.py`

### Support records

- [Ticket records](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/tree/main/data/tickets): `data/tickets`
- [Order records](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/tree/main/data/orders): `data/orders`
- [Article files](https://github.com/ananyasingh456/intern-assignment-llm-cost-optimization/tree/main/data/kb): `data/kb`

### Other components

- **Support requester**

## Connections

- Support requester → Single-call copilot: submits ticket (evidence: `README.md`)
- Support requester → Support pipeline: submits ticket (evidence: `README.md`)
- Single-call copilot → Ticket and order tools: loads ticket and order (evidence: `question1/agent.py`)
- Ticket and order tools → Ticket records: reads (evidence: `shared/tools.py`)
- Ticket and order tools → Order records: reads (evidence: `shared/tools.py`)
- Single-call copilot → Help-center articles: loads articles (evidence: `question1/agent.py`)
- Help-center articles → Article files: reads (evidence: `shared/kb.py`)
- Single-call copilot → Local LLM client: sends prompt (evidence: `question1/agent.py`)
- Single-call copilot → Resolution parser: parses completion (evidence: `question1/agent.py`)
- Support pipeline → Ticket and order tools: loads ticket and order (evidence: `question2/agent.py`)
- Support pipeline → Help-center articles: loads pipeline articles (evidence: `question2/agent.py`)
- Support pipeline → Triage: starts (evidence: `question2/agent.py`)
- Triage → Local LLM client: sends triage prompt (evidence: `question2/agent.py`)
- Support pipeline → Article retrieval: passes triage (evidence: `question2/agent.py`)
- Article retrieval → Local LLM client: sends retrieval prompt (evidence: `question2/agent.py`)
- Support pipeline → Reply composition: passes retrieved content (evidence: `question2/agent.py`)
- Reply composition → Local LLM client: sends composition prompt (evidence: `question2/agent.py`)
- Support pipeline → Resolution audit: passes draft (evidence: `question2/agent.py`)
- Resolution audit → Local LLM client: sends audit prompt (evidence: `question2/agent.py`)
- Support pipeline → Resolution parser: parses final output (evidence: `question2/agent.py`)
- Local LLM client → Order decision rules: gets outcome (evidence: `shared/llm.py`)
- Local LLM client → Cost session: records call (evidence: `shared/llm.py`)
- Cost session → Token counter: counts usage (evidence: `shared/billing.py`)
- Local LLM client → Token counter: checks cached prefix (evidence: `shared/llm.py`)
- Help-center articles → Token counter: measures expanded content (evidence: `shared/kb.py`)
