Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Bitext Data‑Analyst Agent (LangGraph Edition)

This repo re‑implements Assignment 1 using LangGraph and extends it with:

  1. Query classifier – routes user requests to either a structured or unstructured agent.
  2. Persistent sessions – chat continues across browser tabs/reloads via a session_id.
  3. Summarised user memory – stores concise, long‑term facts.
  4. (Bonus) next‑query recommender – TODO (easy to add a new node).

Project layout

.
├── agents.py          # builders for structured/unstructured agents + summary node
├── classifier.py      # LLM‑powered router (structured / unstructured / oos)
├── config.py          # existing – API keys, logging helper
├── graph.py           # LangGraph definition (nodes + routing)
├── memory.py          # JSONL checkpoint store (one file per session)
├── tools.py           # **provided** helper functions + TOOL_SCHEMAS
├── ui_streamlit.py    # Streamlit chat front‑end (with session IDs)
├── requirements.txt   # exact version pins
└── README.md          # you’re here

Quick‑start

# 1. Create env
python -m venv .venv && source .venv/bin/activate

# 2. Install deps
pip install -r requirements.txt

# 3. Export your OpenAI key
export OPENAI_API_KEY=sk‑…

# 4. Prepare the dataset (one‑time)
python data_setup.py  # downloads → bitext_df.pkl (~25 MB)

# 5. Launch the chat UI
streamlit run ui_streamlit.py

Open http://localhost:8501 – the first text box lets you fix your session_id so the agent remembers you across refreshes.


How it works

1. graph.py

Organises the flow:

        ┌──────────┐
        │classifier│
        └─────┬────┘
              │structured     unstructured│
              ▼                           ▼
      ┌───────────────┐         ┌────────────────┐
      │structured_node│         │unstructured_node│
      └──────┬────────┘         └────────┬───────┘
             └───────────────────┬───────┘
                                 ▼
                           ┌───────────┐
                           │ summary   │
                           └────┬──────┘
                                ▼
                              (end)

2. JSONL checkpoints (memory.py)

Each turn, LangGraph calls persist_checkpoint(session_id, state); reloading a page loads previous exchanges so the agent remembers.

3. Summarised memory (agents.build_summary_writer)

A tiny LLM call decides whether to store remember::<fact> lines. These are kept in state["memories"] and will be available to any node.


Troubleshooting

Symptom Fix
KeyError: OPENAI_API_KEY Export the key in your shell or a .env file
OSError: bitext_df.pkl not found Run python data_setup.py first
Chat forgets history Re‑use the same session_id; check checkpoints/<id>.jsonl exists

License

MIT © 2025 Asaf Cohen

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages