agents-and-middleware
Work on the actively maintained LangChain v1 agent package: init_chat_model, create_agent, structured output, tools, middleware, embeddings initialization, provider routing, and agent runtime customization. Use for libs/langchain_v1 agent workflows and route low-level core primitives or provider implementation details to sibling skills.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- agents-and-middleware
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Work on the actively maintained LangChain v1 agent package: init_chat_model, create_agent, structured output, tools, middleware, embeddings initialization, provider routing, and agent runtime customization. Use for libs/langchain_v1 agent workflows and route low-level core primitives or provider implementation details to sibling skills.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/agent-workflows.md12.1 KB
- 参考文档references/middleware-reference.md11.2 KB
- 参考文档references/troubleshooting.md10.2 KB
- 脚本scripts/agent_import_smoke.py2.7 KB
03 SKILL.md 正文
Agents and Middleware
Use this sub-skill for practical work in the actively maintained langchain package around v1 agents, middleware, model initialization, structured output, tools, and embeddings. This guidance is distilled from the LangChain v1 source and tests and is self-contained for future coding agents.
When to Use
- User asks about
init_chat_model,create_agent,response_format, tool schemas, injected tool runtime, or configurable chat models. - User asks to add, configure, or debug middleware such as retry, fallback, human-in-the-loop, summarization, tool/model call limits, PII redaction, file search, shell execution, todo planning, provider tool search, tool retry, or tool selection.
- User asks why provider resolution fails for a chat or embedding model, especially when optional integration packages or credentials are missing.
- User asks to customize agent state, runtime context, checkpointer/store usage, interrupts, streaming, or debug behavior at the
langchainv1 layer.
Route Elsewhere
- For low-level runnable, message, tool, callback, language-model, or embedding primitives from
langchain_core, use../core-primitives/SKILL.md. - For provider implementation packages such as
langchain-openai,langchain-anthropic,langchain-ollama, or provider-specific parameters/classes, use../integrations/SKILL.md. - For legacy
langchain-classicimports, chains, retrievers, or classic agents, use the sibling skill that owns classic APIs instead of rewriting v1 guidance.
Reference Map
- Start with references/agent-workflows.md for source layout, import paths, common edit workflows, validation commands, structured output, tools, embeddings, and provider initialization.
- Use references/middleware-reference.md for middleware families, exported classes, hook styles, ordering, state/context patterns, and safety constraints.
- Use references/troubleshooting.md for missing provider packages, credentials/network skips, structured output/tool validation, middleware ordering, HITL/shell/file-search safety, and v1-vs-classic confusion.
- Run scripts/agent_import_smoke.py as a safe import-only smoke check when an environment is available.
Fast Workflow
- Confirm the target package is
libs/langchain_v1; its distribution name islangchainand its package imports arelangchain.*. - Inspect the nearest v1 public API files first:
langchain/chat_models/base.py,langchain/agents/factory.py,langchain/agents/structured_output.py,langchain/agents/middleware/,langchain/tools/, andlangchain/embeddings/base.py. - Prefer tests under
tests/unit_tests/agents,tests/unit_tests/chat_models,tests/unit_tests/tools, andtests/unit_tests/embeddingsfor expected public behavior. - For package validation, use
uvfromlibs/langchain_v1; do not usepip,poetry, orcondadirectly for this monorepo. - Skip network-backed model invocations unless credentials, provider packages, and user permission are present; use fake models or import checks for local validation.
Safe Validation
From libs/langchain_v1, use targeted package tests when uv is available:
uv run --group test pytest tests/unit_tests/chat_models/test_chat_models.py tests/unit_tests/agents/test_response_format.py tests/unit_tests/tools/test_imports.py tests/unit_tests/embeddings/test_base.py
From this sub-skill directory, use the bundled smoke script with any Python environment that already has langchain installed:
python scripts/agent_import_smoke.py
The smoke script imports public APIs only and does not call providers, networks, shell commands, or external files.
Guardrails
- Keep v1 import paths explicit:
langchain.chat_models,langchain.agents,langchain.agents.middleware,langchain.tools, andlangchain.embeddings. - Do not add provider-specific hard dependencies to
langchaincore code unless the package metadata intentionally lists them as optional extras. - Do not run shell/file-search/HITL examples as unattended validation; these require user-reviewed safety decisions.
- Do not link future runtime instructions to source-checkout docs, examples, tests, or absolute local paths; distill facts into this sub-skill or bundled references.
04 同仓库更多 Skills
passnet-triton-opt
Make a single PassNet Triton kernel fast AND numerically faithful: performance model (when a replacement can win at all), block/grid/warp tuning, autotune policy, launch overhead, and per-op numeric recipes to pass the dtype baseline tolerances. Use when a pass matches and is correct but speedup below expected, or when correctness fails by small numeric margins.
passnet-solve
END-TO-END playbook for solving one PassNet sample: analyze the computation graphs, decide the optimization strategy (what to fuse, what to replace, what to leave alone), drive the iteration loop, and maximize the sample score. This is the ENTRY skill — invoke it first for any PassNet optimization task; it tells you when to use passnet-pattern-fusion, passnet-triton-opt and passnet-feedback.
passnet-skill
PassNet GPU kernel optimization via compiler passes. Design and implement Triton-based optimization passes, create pass files under ./pass_dir/, self-evaluate with pass_evaluator, and iterate to maximize GPU speedup.
passnet-pattern-fusion
Author PassNet pass files: write patterns that actually MATCH the FX graph, pick fusion regions (which ops to absorb into one Triton kernel), and structure multi-pass submissions with the mandatory shared-dispatch architecture. Use when creating or fixing pattern()/replacement_args()/replacement_func() files, when a pass "failed to match", or when deciding how to fuse multiple kernels/ops.
passnet-orchestrate
Round/batch planning and decision support for PassNet graph optimization. Use for multi-sample triage, worker allocation, eval-budget policy, and post-eval keep/revert decisions. For solving one concrete sample end to end, use passnet-solve as the entry skill; consult this skill only when you need broader planning or a specific decision gate.
passnet-feedback
Fast, deterministic feedback for PassNet work: pre-flight pattern/match verification WITHOUT burning a GPU evaluation, per-node bottleneck analysis of a sample's graphs, and eval-log parsing into per-variant status + estimated score + failure classification. Use BEFORE every GPU evaluation (check_pattern), at the START of a sample (analyze_graph), and AFTER every evaluation (parse_eval_log).