skills/aimlops/langchain/SKILL.md
Framework for building applications with large language models and chains.
npx skillsauth add alphaonedev/openclaw-graph langchainInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
LangChain is a Python framework for developing applications that integrate large language models (LLMs) into workflows, enabling the creation of chains that combine multiple LLMs or tools for tasks like question answering or data processing.
Use LangChain when building AI-powered apps that require chaining LLMs, such as integrating multiple models for complex queries, or when you need to handle external data sources with LLMs. Apply it for rapid prototyping of AI agents, like chatbots that fetch real-time data, or for ML operations in aimlops clusters where scalable LLM workflows are needed.
LLMChain; for example, combine a prompt template with an LLM call.OpenAI class; handle vector stores with FAISS for semantic search.PromptTemplate to define and render prompts dynamically, e.g., with variables for user input.AgentType.ZERO_SHOT_REACT, allowing dynamic tool selection based on LLM output.To use LangChain, install it via pip install langchain, then import and configure components. For basic chains, create an LLM instance and link it to prompts or tools. Pattern: Initialize an LLM with an API key, build a chain, and run it in a loop for iterative tasks. For agents, define tools and let the agent decide actions based on input.
pip install langchain[all] to include extras; set environment variables like export OPENAI_API_KEY=your_key for authentication.from langchain.llms import OpenAI
from langchain.chains import LLMChain
llm = OpenAI(model_name="gpt-3.5-turbo")
chain = LLMChain(llm=llm, prompt="What is {topic}?")
result = chain.run(topic="LangChain")
https://api.openai.com/v1/chat/completions via LangChain wrappers; pass headers with auth tokens.chains:
- name: simple_chain
llm: OpenAI
prompt: "Summarize {text}"
Load with from langchain.utilities import load_config.langchain serve to run chains as services, or debug with langchain debug --chain my_chain to trace executions.Integrate LangChain with other tools by wrapping them as callable functions. For example, to add a database query tool, use Tool.from_function and pass it to an agent. Set env vars for keys, e.g., $OPENAI_API_KEY for OpenAI models or $SERPAPI_API_KEY for search integrations. When combining with aimlops cluster tools, ensure compatibility by using LangChain's callback system for logging; import from langchain.callbacks import get_openai_callback to track token usage. For vector databases, integrate with Pinecone by initializing from langchain.vectorstores import Pinecone and providing your API key via env var.
Handle errors by wrapping chain runs in try-except blocks, e.g.:
try:
result = chain.run(input_data)
except ValueError as e:
print(f"Invalid input: {e}")
except Exception as e:
print(f"General error: {e} - Check API key or network")
Common issues include API rate limits (check with if e.status_code == 429: retry()), invalid API keys (verify $OPENAI_API_KEY is set), or chain misconfigurations (use chain.validate() if available). Log errors using LangChain's handlers for debugging in production.
Simple Question-Answering Chain: Build a chain to answer questions using an LLM and a vector store. First, set export OPENAI_API_KEY=your_key. Then:
from langchain.chains import RetrievalQA
from langchain.llms import OpenAI
qa_chain = RetrievalQA.from_chain_type(llm=OpenAI(), chain_type="stuff")
answer = qa_chain.run({"query": "What is LangChain?"})
This fetches relevant documents and generates a response.
Agent for Web Search: Create an agent that uses tools for web searches. Set export SERPAPI_API_KEY=your_key. Code:
from langchain.agents import AgentType, load_tools, initialize_agent
from langchain.llms import OpenAI
tools = load_tools(["serpapi"])
agent = initialize_agent(tools, OpenAI(), agent=AgentType.ZERO_SHOT_REACT)
response = agent.run("Search for latest AI news")
The agent dynamically queries the web and returns results.
tools
Root web development: project structure, tooling selection, deployment decisions
development
WebAssembly: Rust/Go/C to WASM, wasm-bindgen, Emscripten, WASM Component Model
development
Vue 3: Composition API script setup, Pinia, Vue Router 4, SFCs, Vite, Nuxt 3
tools
Tailwind CSS 4: utility classes, config, JIT, arbitrary values, darkMode, plugins, shadcn/ui