Skip to content

Abernaughty/langchain-price-agent

Repository files navigation

langchain-price-agent

Python scripts exploring LangChain and LangGraph for AI agent development, with a focus on Pokémon card price analysis. These are standalone experiments and learning exercises — not production code.

Scripts

Script Description
langchain-agent.py Basic LangGraph agent using Claude. A starting point for tool-using agents with create_react_agent.
langchain-agent-v2.py Extended version with conversation memory (InMemorySaver) for multi-turn interactions.
agent-api.py LangGraph agent wrapped in a FastAPI server. Accepts chat via REST, maintains state per thread_id.
price-analysis-agent.py Pokémon card price analyzer using the Anthropic SDK directly (not LangChain). Loads historical JSON, runs Claude analysis on trends.
historic-pricing-script.py Fetches historical pricing from the Pokémon TCG API (via RapidAPI) and saves as JSON.
get-historic-pricing-v2.py Updated version of the above with expanded set coverage.
test_setup.py Validates environment setup and API key configuration.
verify_data_parsing.py Tests data parsing logic against sample JSON output.

What I Learned

LangGraph ReAct patterncreate_react_agent handles the think→act→observe loop automatically, but you need to be intentional about when to use tool-calling vs. direct completion.

InMemorySaver for conversation state — trivial to add multi-turn memory to a LangGraph agent, but the state is lost on process restart. For persistent memory, you'd need a database checkpointer.

FastAPI + LangGraph (agent-api.py) — wrapping an agent as an HTTP service is straightforward. The key insight: thread_id in the config is how LangGraph separates conversation state across concurrent users.

Direct Anthropic SDK vs. LangChainprice-analysis-agent.py intentionally bypasses LangChain and calls the Anthropic API directly. It's simpler for single-turn analysis tasks where you don't need the agent loop overhead.

Setup

pip install -r requirements.txt

Create a .env file:

ANTHROPIC_API_KEY=sk-ant-...
POKEMON_TCG_API_KEY=...     # Required for historic-pricing-script.py only

Usage

# Run basic agent
python langchain-agent.py

# Start agent API server
uvicorn agent-api:app --reload
# POST http://localhost:8000/chat
# {"message": "What's a Charizard worth?", "thread_id": "user-1"}

# Run price analysis (uses Anthropic SDK directly)
python price-analysis-agent.py

Requirements

  • Python 3.10+
  • See requirements.txt

Related Projects

  • agent-dev — Containerized dev environment (Docker + MCP servers) that these agent scripts can be run inside
  • PCPC — The production version of the Pokémon price checker that informed the data analysis work in these experiments

About

LangChain-based price lookup agent

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages