Skip to content

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

LangChain Framework

A batteries-included AI agent template built with LangChain + LangGraph and powered by Claude Sonnet 4.6 (claude-sonnet-4-6). Drop-in tools, persistent conversation memory, streaming output, and a Rich-powered terminal UI.

              ┌────────────────────────────┐
   you ──────►│   LangGraph ReAct agent     │──► artifacts in ./workspace
              │   (Claude Sonnet 4.6)       │
              └──────────────┬─────────────┘
                             │
        ┌────────────────────┼─────────────────────┐
        ▼                    ▼                     ▼
   web research          computation           filesystem
 (Tavily / DDG /       (calculator,          (read / write /
  fetch_url /           Python REPL)          list / shell)
  wikipedia)
                             │
                             ▼
                    real-world signals
                  (current_time, weather)

✨ Features

  • Claude Sonnet 4.6 through langchain-anthropic — fast, frontier reasoning.
  • LangGraph create_react_agent — robust tool-calling loop with checkpointed memory.
  • 11 production-grade tools out of the box (see below).
  • Persistent conversation threads with MemorySaver.
  • Streaming UI built on rich — see every tool call as it happens.
  • Sandboxed workspace — file ops are scoped to ./workspace, shell is allowlisted.
  • Zero-key fallbacks — DuckDuckGo and Open-Meteo work with no API keys.

🧰 The toolbelt

Tool What it does
web_search Live web search via Tavily (preferred) or DuckDuckGo fallback.
fetch_url Fetch and clean any HTTP(S) page — strips scripts, nav, footers.
wikipedia_lookup English Wikipedia summaries with disambiguation handling.
calculator Safe numeric evaluator (uses numexpr, falls back to math).
python_repl Persistent in-process Python REPL — state survives across calls.
write_file Write a file inside ./workspace (path-traversal protected).
read_file Read a workspace file with truncation.
list_workspace ls-style view of the workspace.
shell Read-only shell with strict command allowlist, no shell metacharacters.
current_time Current ISO-8601 time in any IANA timezone.
weather Live weather via Open-Meteo — no API key required.

Every tool lives in tools.py as a @tool-decorated function so you can pick and choose, replace, or extend the set.

🚀 Quickstart

git clone https://github.com/mauvilar/LangChain-Framework.git
cd LangChain-Framework

python -m venv .venv && source .venv/bin/activate
pip install -r requirements.txt

cp .env.example .env
# edit .env and set ANTHROPIC_API_KEY (and optionally TAVILY_API_KEY)

python agent.py

One-shot question

python agent.py "Find today's top ML paper on arxiv and summarize the abstract."

Interactive chat

python agent.py
you› What's the weather in Madrid right now, in Fahrenheit?

In-chat commands: /reset starts a fresh conversation thread, /exit quits.

Programmatic use

from agent import build_agent
from langchain_core.messages import HumanMessage

agent = build_agent()
result = agent.invoke(
    {"messages": [HumanMessage(content="Compute the 30th Fibonacci number.")]},
    config={"configurable": {"thread_id": "demo"}},
)
print(result["messages"][-1].content)

🔧 Configuration

Environment variables (see .env.example):

Var Default Notes
ANTHROPIC_API_KEY — Required. Get one at console.anthropic.com.
TAVILY_API_KEY — Optional. Enables high-quality web search.
AGENT_MODEL claude-sonnet-4-6 Any Anthropic model id.
AGENT_TEMPERATURE 0.2 Lower = more deterministic.
AGENT_WORKSPACE ./workspace Where file tools read/write.

🧱 Extending

Add a new tool in tools.py:

from langchain_core.tools import tool

@tool
def stock_quote(ticker: str) -> str:
    """Return the latest price for a stock ticker."""
    ...

Then register it in ALL_TOOLS at the bottom of the file. The agent picks it up automatically on next run.

🛡️ Safety notes

  • The shell tool is read-only and enforces a strict command allowlist; pipes, redirection, and command chaining are rejected.
  • The python_repl runs in-process — treat the agent like a script you wrote. Swap in langchain-experimental's containerised REPL for hostile inputs.
  • File tools refuse paths that escape ./workspace.

📜 License

MIT — do whatever you want, attribution appreciated.

About

AI agent template built with LangChain + LangGraph, powered by Claude Sonnet 4.6. Includes web search, Python REPL, filesystem, weather and more.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages