langchain-python
БесплатноБез исполняемых скриптовНе проверенInstructions for using LangChain with Python Triggers on: **/*.py
от diegosouzapw★ 68 звёзд на GitHubОб этом скилле
LangChain Python Instructions
These instructions guide GitHub Copilot in generating code and documentation for LangChain applications in Python. Focus on LangChain-specific patterns, APIs, and best practices.
Runnable Interface (LangChain-specific)
LangChain's Runnable interface is the foundation for composing and executing chains, chat models, output parsers, retrievers, and LangGraph graphs. It provides a unified API for invoking, batching, streaming, inspecting, and composing components.
Key LangChain-specific features:
- All major LangChain components (chat models, output parsers, retrievers, graphs) implement the Runnable interface.
- Supports synchronous (
invoke,batch,stream) and asynchronous (ainvoke,abatch,astream) execution. - Batching (
batch,batch_as_completed) is optimized for parallel API calls; setmax_concurrencyinRunnableConfigto control parallelism. - Streaming APIs (
stream,astream,astream_events) yield outputs as they are produced, critical for responsive LLM apps. - Input/output types are component-specific (e.g., chat models accept messages, retrievers accept strings, output parsers accept model outputs).
- Inspect schemas with
get_input_schema,get_output_schema, and their JSONSchema variants for validation and OpenAPI generation. - Use
with_typesto override inferred input/output types for complex LCEL chains. - Compose Runnables declaratively with LCEL:
chain = prompt | chat_model | output_parser. - Propagate
RunnableConfig(tags, metadata, callbacks, concurrency) automatically in Python 3.11+; manually in async code for Python 3.9/3.10. - Create custom runnables with
RunnableLambda(simple transforms) orRunnableGenerator(streaming transforms); avoid subclassing directly. - Configure runtime attributes and alternatives with
configurable_fieldsandconfigurable_alternativesfor dynamic chains and LangServe deployments.
LangChain best practices:
Use batching for parallel API calls to LLMs or retrievers; set
max_concurrencyto avoid rate limits.Prefer streaming APIs for chat UIs and long outputs.
Always validate input/output schemas for custom chains and deployed endpoints.
Use tags and metadata in
RunnableConfigfor tracing in LangSmith and debugging complex chains.For custom logic, wrap functions with
RunnableLambdaorRunnableGeneratorinstead of subclassing.For advanced configuration, expose fields and alternatives via
configurable_fieldsandconfigurable_alternatives.Use LangChain's chat model integrations for conversational AI:
Import from
langchain.chat_modelsorlangchain_openai(e.g.,ChatOpenAI).Compose messages using
SystemMessage,HumanMessage,AIMessage.For tool calling, use
bind_tools(tools)method.For structured outputs, use
with_structured_output(schema).
Example:
from langchain_openai import ChatOpenAI
from langchain.schema import HumanMessage, SystemMessage
chat = ChatOpenAI(model="gpt-4", temperature=0)
messages = [
SystemMessage(content="You are a helpful assistant."),
HumanMessage(content="What is LangChain?")
]
response = chat.invoke(messages)
print(response.content)
- Compose messages as a list of
SystemMessage,HumanMessage, and optionallyAIMessageobjects. - For RAG, combine chat models with retrievers/vectorstores for context injection.
- Use
streaming=Truefor real-time token streaming (if supported). - Use
toolsargument for function/tool calling (OpenAI, Anthropic, etc.). - Use
response_format="json"for structured outputs (OpenAI models).
Best practices:
Always validate model outputs before using them in downstream tasks.
Prefer explicit message types for clarity and reliability.
For Copilot, provide clear, actionable prompts and document expected outputs.
LLM client factory: centralize provider configs (API keys), timeouts, retries, and telemetry. Provide a single place to switch providers or client settings.
Prompt templates: store templates under
prompts/and load via a safe helper. Keep templates small and testable.Chains vs Agents: prefer Chains for deterministic pipelines (RAG, summarization). Use Agents when you require planning or dynamic tool selection.
Tools: implement typed adapter interfaces for tools; validate inputs and outputs strictly.
Memory: default to stateless design. When memory is needed, store minimal context and document retention/erasure policies.
Retrievers: build retrieval + rerank pipelines. Keep vectorstore schema stable (id, text, metadata).
Patterns
- Callbacks & tracing: use LangChain callbacks and integrate with LangSmith or your tracing system to capture request/response lifecycle.
- Separation of concerns: keep prompt construction, LLM wiring, and business logic separate to simplify testing and reduce accidental prompt changes.
Embeddings & vectorstores
- Use consistent chunking and metadata fields (source, page, ch
Установить langchain-python в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл langchain-python?
Instructions for using LangChain with Python Triggers on: **/*.py
Как установить скилл langchain-python?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл langchain-python запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic