Index of every page on this site: llms.txt
All skills
jeremylongshore avatar

/langchain-performance-tuning

@0d57af8
Run it yourself

Tune LangChain 1.0 / LangGraph 1.0 Python chains and agents for throughput, latency, and cost — streaming modes, explicit batch concurrency, semantic plus exact caches, persistent message history, and async-safe retriever patterns. Use when p95 latency exceeds target, batching "does not work", cost grows linearly with traffic, or a process restart wipes chat history. Trigger with "langchain performance", "langchain slow batch", "langchain throughput", "langchain p95 latency", "semantic cache hit rate".

Use this Skill: https://skilld.dev/gh/jeremylongshore/tons-of-skills-marketplace/langchain-performance-tuning

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesone-pager.md

≈567 tokens on demand. Your agent reads this file only when SKILL.md points to it.

langchain-performance-tuning — One-Pager

Make a working LangChain 1.0 / LangGraph 1.0 Python app faster and cheaper under real load without rewriting the chain.

The Problem

Production chains miss p95 targets and burn budget because .batch() silently serializes (default max_concurrency=1), sync invoke calls block FastAPI event loops, InMemoryChatMessageHistory wipes on restart, and semantic caches at the default 0.95 threshold return under 5% hit rate. Teams blame "the LLM" when the bottleneck is configuration.

The Solution

Turn on explicit batch concurrency per provider, switch every hot path to ainvoke / astream_events(version="v2"), move exact + semantic caches behind Redis with tuned thresholds on a golden set, and back chat history with RedisChatMessageHistory (TTL) or a LangGraph checkpointer. Result: 5-10x throughput on batch, TTFT under 1s, cache hit rate north of 30%, zero history loss on deploy.

Who / What / When

Aspect Details
Who Senior Python engineers, SREs, and platform leads operating LangChain 1.0 / LangGraph 1.0 chains or agents at scale.
What Latency + throughput + cost tuning playbook: concurrency table, cache configuration, persistent history wiring, async-safety checklist, latency-breakdown template.
When Chain already works functionally but misses p95 latency targets, throughput ceilings, cost budgets, or suffers history loss after a process restart.

Key Features

  1. Batch concurrency fix (P08) — one-line config change (max_concurrency=10) that unlocks 5-10x throughput on .abatch(), with a per-provider RPM table and semaphore patterns for multi-worker saturation.
  2. Redis-backed history + cache — RedisChatMessageHistory with TTL replaces in-process memory (P22), RedisSemanticCache with 0.85-0.90 threshold tuned on a golden set replaces the near-useless default 0.95 (P62).
  3. Async-safety playbook — grep patterns to find sync-in-async (P48), FastAPI lifespan hooks for retriever pool cleanup (P59), the BackgroundTasks-for-streaming gotcha (P60), and astream_events(version="v2") for accurate TTFT instrumentation (P01).

Quick Start

See SKILL.md for full instructions.

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts2mo3 checks · Risk SAFE
  • Gen Agent Trust Hub2mo

    The skill provides comprehensive guidance on performance tuning for LangChain 1.0 and LangGraph applications. It includes best practices for asynchronous programming, batching, caching, and persistent chat history. No security risks, obfuscation, or malicious patterns were identified in the instructions or reference materials.

  • Socket2mo

    No alerts

  • Snyk2mo

    Risk: LOW · No issues

Signed by skilld at 0d57af8. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub yesterday.

Activeupdated 2 months ago
What it can do
Reads files Edits files Runs commands
version
2.7.0
author
Jeremy Longshore <jeremy@intentsolutions.io>
compatibility
Designed for Claude Code
All 5 allowed tools
ReadWriteEditBash(python:*)Bash(redis-cli:*)
Other metadata
tags
[
  "saas",
  "langchain",
  "langgraph",
  "python",
  "langchain-1.0",
  "performance",
  "caching",
  "async"
]

README badge

README badge for jeremylongshore/tons-of-skills-marketplace/langchain-performance-tuning