Skip to content

emanueleielo/langgraph-think-tool

Repository files navigation

🧠 LangGraph ReAct Agent with Claude "Think" Tool

CI Integration Tests Open in - LangGraph Studio

This template showcases a ReAct agent implemented using LangGraph, extended with a Claude-style "think" tool that enables structured internal reasoning before taking any action—ideal for complex multi-step workflows and policy-compliant environments.

Inspired by Anthropic’s "think" tool for Claude 3.7 and τ-Bench benchmark: Read the blog post


🚀 Features

  • 🧠 think Tool: Forces the agent to reflect before acting, logging structured reasoning steps.
  • 🔁 ReAct Agent Loop: Reason → Act → Observe → Repeat.
  • 🔌 Pluggable Tooling: Easily integrate new tools (e.g., search, APIs).
  • 📚 Optimized Prompting: Includes domain-style guidance for better decision-making.
  • 🧩 LangGraph Studio Ready: Visualize and edit the graph in-browser.

🔍 What’s New

This fork adds a Claude-inspired think tool with the following logic:

def think(thought: str, config: Annotated[RunnableConfig, InjectedToolArg]) -> str:
    """Think tool for structured intermediate reasoning before actions."""

Used as a scratchpad to:

  • List applicable rules
  • Check required information
  • Validate planned actions
  • Reflect on tool outputs

📌 Prompt template included in THINK_PROMPT, used dynamically with Configuration.


📈 Use Cases

  • Complex workflows (e.g., booking, support, compliance)
  • Long tool-call chains needing internal verification
  • Reasoning transparency and debuggability
  • Agents operating in policy-heavy domains (e.g., airline, finance, legal)

🛠️ Getting Started

  1. Clone the repo
  2. Create a .env file from .env.example
  3. Install all requirements with pip install -r requirements.txt
  4. Add your API keys (OpenAI, Tavily)
  5. Run in LangGraph Studio

🧩 File Overview

File Purpose
src/agent/tools.py Includes think and search tools
src/agent/prompts.py System and think prompt configuration
src/agent/configuration.py Central configuration (e.g. model setup)

📚 Resources


🧰 Tools Configuration

You can modify the tool list in src/agent/tools.py:

TOOLS: List[Callable[..., Any]] = [search, think]

And the system prompt logic in src/agent/prompts.py.


✅ Development Tips

  • Use hot reload in LangGraph Studio
  • Add custom nodes for internal logging or external validation
  • Extend think() to support domain-specific policies or memory

About

This project demonstrates how to integrate a “think” tool into a LangGraph agent workflow, inspired by Anthropic’s research on structured reasoning in tool-based agents. By leveraging the “think” tool, Claude is enabled to pause and reflect on intermediate steps, improving performance in complex, policy-driven, or multi-step decision scenarios.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors