
Langchain
Scaffold LangChain agents with ReAct reasoning, tool calling, model choice, and streaming patterns inside your Python agent stack.
Overview
langchain is an agent skill for the Build phase that teaches how to create LangChain agents using the ReAct pattern, tools, and streaming-friendly invoke flows in Python.
Install
npx skills add https://github.com/davila7/claude-code-templates --skill langchainWhat is this skill?
- ReAct loop: reasoning, tool execution, observation, repeat until the task completes
- create_agent pattern with ChatAnthropic and ChatOpenAI model examples
- Tool definitions (calculator, search) wired into agent invoke and message history
- Coverage of agent components: model selection, tools, system prompts, and streaming-oriented structure
- Python-first snippets aligned with langchain_anthropic and langchain_openai packages
Adoption & trust: 738 installs on skills.sh; 27.8k GitHub stars; 2/3 security scanners passed (skills.sh audits).
What problem does it solve?
You know you need an LLM agent with tools but lack a clear LangChain structure for models, tools, and the reason-act loop.
Who is it for?
Indie builders shipping Python agents who want LangChain ReAct and tool-calling basics in one skill-shaped guide.
Skip if: Teams standardizing on non-Python stacks only, or production deployments that need this skill to replace security review of arbitrary tool code.
When should I use this skill?
You are implementing LangChain agents with ReAct, tool calling, or streaming and need the create_agent-oriented pattern.
What do I get? / Deliverables
You can wire create_agent with chosen chat models and Python tools and run a first invoke loop you can extend with safer tools and streaming.
- Working create_agent setup with tools and system prompt
- Documented model and tool component boundaries for extension
Recommended Skills
Journey fit
Agent-tooling is the canonical shelf for framework guides that teach how LLMs loop through reason-act-observe cycles during product build. LangChain agent creation is implementation knowledge for builders coding assistants, not validation research or ship-time security review.
How it compares
Framework how-to for LangChain agents, not a Prism MCP server or a no-code workflow template.
Common Questions / FAQ
Who is langchain for?
Solo developers building LLM-powered agents in Python with LangChain who want ReAct and tool-calling patterns in agent-invokable form.
When should I use langchain?
During Build / agent-tooling while implementing assistants, automations, or APIs that need models plus callable tools.
Is langchain safe to install?
The skill is documentation; example tools may use eval or external calls—review the Security Audits panel on this page and harden tools before production.
SKILL.md
READMESKILL.md - Langchain
# LangChain Agents Guide Complete guide to building agents with ReAct, tool calling, and streaming. ## What are agents? Agents combine language models with tools to solve complex tasks through reasoning and action: 1. **Reasoning**: LLM decides what to do 2. **Acting**: Execute tools based on reasoning 3. **Observation**: Receive tool results 4. **Loop**: Repeat until task complete This is the **ReAct pattern** (Reasoning + Acting). ## Basic agent creation ```python from langchain.agents import create_agent from langchain_anthropic import ChatAnthropic # Define tools def calculator(expression: str) -> str: """Evaluate a math expression.""" return str(eval(expression)) def search(query: str) -> str: """Search for information.""" return f"Results for: {query}" # Create agent agent = create_agent( model=ChatAnthropic(model="claude-sonnet-4-5-20250929"), tools=[calculator, search], system_prompt="You are a helpful assistant. Use tools when needed." ) # Run agent result = agent.invoke({ "messages": [{"role": "user", "content": "What is 25 * 17?"}] }) print(result["messages"][-1].content) ``` ## Agent components ### 1. Model - The reasoning engine ```python from langchain_openai import ChatOpenAI from langchain_anthropic import ChatAnthropic # OpenAI model = ChatOpenAI(model="gpt-4o", temperature=0) # Anthropic (better for complex reasoning) model = ChatAnthropic(model="claude-sonnet-4-5-20250929", temperature=0) # Dynamic model selection def select_model(task_complexity: str): if task_complexity == "high": return ChatAnthropic(model="claude-sonnet-4-5-20250929") else: return ChatOpenAI(model="gpt-4o-mini") ``` ### 2. Tools - Actions the agent can take ```python from langchain.tools import tool # Simple function tool @tool def get_current_time() -> str: """Get the current time.""" from datetime import datetime return datetime.now().strftime("%H:%M:%S") # Tool with parameters @tool def fetch_weather(city: str, units: str = "fahrenheit") -> str: """Fetch weather for a city. Args: city: City name units: Temperature units (fahrenheit or celsius) """ # Your weather API call here return f"Weather in {city}: 72°{units[0].upper()}" # Tool with error handling @tool def risky_api_call(endpoint: str) -> str: """Call an external API that might fail.""" try: response = requests.get(endpoint, timeout=5) return response.text except Exception as e: return f"Error calling API: {str(e)}" ``` ### 3. System prompt - Agent behavior ```python # General assistant system_prompt = "You are a helpful assistant. Use tools when needed." # Domain expert system_prompt = """You are a financial analyst assistant. - Use the calculator for precise calculations - Search for recent financial data - Provide data-driven recommendations - Always cite your sources""" # Constrained agent system_prompt = """You are a customer support agent. - Only use search_kb tool to find answers - If answer not found, escalate to human - Be concise and professional - Never make up information""" ``` ## Agent types ### 1. Tool-calling agent (recommended) Uses native function calling for best performance: ```python from langchain.agents import create_tool_calling_agent, AgentExecutor from langchain.prompts import ChatPromptTemplate # Create prompt prompt = ChatPromptTemplate.from_messages([ ("system", "You are a helpful assistant"), ("human", "{input}"), ("placeholder", "{agent_scratchpad}"), ]) # Create agent agent = create_tool_calling_agent( llm=model, tools=[calculator, search], prompt=prompt ) # Wrap in executor agent_executor = AgentExecutor( agent=agent, tools=[calculator, search], verbose=True, max_iterations=5, handle_parsing_errors=True ) # Run result = agent_executor.invoke({"input": "What is the weather in Paris?"}) ``` ### 2. ReAct agent (reasoning trace) Show