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)
- 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.
| 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.
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.pypython agent.py "Find today's top ML paper on arxiv and summarize the abstract."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.
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)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. |
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.
- The
shelltool is read-only and enforces a strict command allowlist; pipes, redirection, and command chaining are rejected. - The
python_replruns in-process — treat the agent like a script you wrote. Swap inlangchain-experimental's containerised REPL for hostile inputs. - File tools refuse paths that escape
./workspace.
MIT — do whatever you want, attribution appreciated.