sdk-clients
Use LangGraph Python SDK clients, API resource clients, auth headers, and thread-centric streaming v3; understand JS SDK status.
- License 许可
- MIT
- 最近更新
- 2026-09-03
- Stars
- ★ 351
- Forks
- 27
01 前言 Front Matter
- name
- sdk-clients
- license
- MIT
- metadata
- { "disco-role": "operating" }
- description
- Use LangGraph Python SDK clients, API resource clients, auth headers, and thread-centric streaming v3; understand JS SDK status.
- disable-model-invocation
- true
02 资源文件 4
- 参考文档references/api-clients.md4.9 KB
- 参考文档references/thread-streaming.md6.8 KB
- 参考文档references/troubleshooting.md6.2 KB
- 脚本scripts/inspect_sdk_exports.py5.8 KB
03 SKILL.md 正文
sdk-clients
Use this sub-skill when an agent needs to connect Python code to a running LangGraph API server, manage API resources, or convert polling/run streaming code to thread-centric streaming v3.
Choose This Sub-Skill For
- Creating async or sync SDK clients with
get_client()orget_sync_client(). - Configuring local no-key clients, remote API-key clients, custom headers, or HTTP timeouts.
- Calling resource clients for assistants, threads, runs, cron jobs, and the persistent store.
- Using
client.threads.stream()with typed projections such asmessages,tool_calls,values,output,subgraphs, andextensions. - Explaining reconnect limits, SSE vs WebSocket transport, sync vs async behavior, and JS SDK repository status.
For graph authoring and invocation semantics, use graph-runtime. For prebuilt agent helpers that produce assistant graphs, use prebuilt-agents. For checkpoint and store persistence details, use persistence. For starting or deploying the API server, use cli-deployment when present.
Quick Install And Smoke Check
Install the Python SDK in the target project environment:
python -m pip install langgraph-sdk
Check that the expected exports are present without contacting a server:
python skills/langgraph/sub-skills/sdk-clients/scripts/inspect_sdk_exports.py --json
Expected result: JSON with ok: true, callable get_client and get_sync_client, async/sync top-level client classes, resource client exports, and the auth environment fallback order.
Client Factories
The public factories are:
from langgraph_sdk import get_client, get_sync_client
async_client = get_client(
url="http://localhost:8123",
api_key=None,
headers={"X-Request-Source": "agent"},
timeout=30.0,
)
sync_client = get_sync_client(url="http://localhost:8123", api_key=None)
Parameter notes:
urlis the LangGraph API base URL.get_sync_client()defaults tohttp://localhost:8123when omitted.get_client(url=None)is async and first attempts an in-process server transport when used inside a LangGraph server; otherwise give an explicit URL for normal scripts.api_keyaccepts a string,None, or the default sentinel. A string becomes the bearer credential;Nonedisables environment key lookup.- When
api_keyis omitted, keys auto-load in order:LANGGRAPH_API_KEY, thenLANGSMITH_API_KEY, thenLANGCHAIN_API_KEY. headersmerges additional HTTP headers with auth headers. Do not hard-code secrets in source; prefer environment variables.timeoutaccepts anhttpx.Timeout, a float total timeout, or a(connect, read, write, pool)tuple. Defaults are connect 5s, read 300s, write 300s, pool 5s.
Use context managers in long-running apps so the underlying HTTP client closes cleanly:
async with get_client(url=server_url, api_key=token) as client:
assistants = await client.assistants.search()
with get_sync_client(url=server_url, api_key=token) as client:
assistants = client.assistants.search()
More client details: references/api-clients.md.
API Resource Clients
Top-level clients expose these resources:
client.assistantsfor graph assistant configuration and lookup.client.threadsfor conversational threads, state, history, and thread-centric streaming.client.runsfor starting, waiting, joining, cancelling, and streaming runs.client.cronsfor scheduled runs.client.storefor persistent document store operations.client.httpfor lower-level request helpers when a resource method is not enough.
Keep async and sync styles separate. Await async resource calls from get_client(). Do not await sync calls from get_sync_client().
Thread-Centric Streaming v3
Prefer client.threads.stream() when a workflow needs one thread session with multiple typed views over the same run. The call returns a context manager. assistant_id is required. If thread_id is omitted, the SDK mints a UUIDv4 client-side and the server creates the thread lazily on first run.start.
import asyncio
from langgraph_sdk import get_client
client = get_client(url="http://localhost:8123", api_key=None)
async with client.threads.stream(assistant_id="agent") as thread:
await thread.run.start(input={"messages": [{"role": "user", "content": "hi"}]})
async def collect_messages():
return [stream async for stream in thread.messages]
async def collect_tools():
return [call async for call in thread.tool_calls]
messages, tool_calls = await asyncio.gather(collect_messages(), collect_tools())
final_values = await thread.output
Important streaming rules:
- Start projections concurrently when you need multiple views from the same run; typed projections share the underlying event stream.
- Use
async withfor async streams andwithfor sync streams. Callingrun.start()or subscribing outside the context manager raises a runtime error. headerspassed tothreads.stream()are forwarded to command and event requests for that stream session.transport="sse"is the default. Async thread streaming can usetransport="websocket"when thewebsocketsoptional dependency is installed and the server supports it.- Reconnect attempts are limited to 5 by default for shared stream and lifecycle handling. Persistent network partitions surface as runtime failures on active projections.
- Each
thread.extensions[name]access creates a subscription. Assign it once and reuse it inside the session to avoid duplicate extension subscriptions.
More streaming patterns and conversion guidance: references/thread-streaming.md.
JS SDK Status
The JavaScript/TypeScript SDK content has moved out of this repository to the public LangGraph.js repository. For JS/TS clients, use LangGraph.js and the LangGraph.js docs. Do not infer current JS SDK APIs from this repository beyond that migration notice.
Validation Checklist
python -m pip show langgraph-sdksucceeds in the environment that will run the client code.python skills/langgraph/sub-skills/sdk-clients/scripts/inspect_sdk_exports.pyreportsOK: langgraph-sdk client exports available.- Local API tests use
api_key=Noneunless the local server actually requires auth. - Remote API tests pass credentials through
LANGGRAPH_API_KEYor a secret manager, not literals committed to source. - Async code awaits
client.assistants,client.threads,client.runs,client.crons, andclient.storemethods; sync code does not. - Streaming code enters the context manager before
run.start()and consumes required projections before exiting.
Troubleshooting Router
- Import, install, optional dependency, auth, timeout, and local/remote server issues: references/troubleshooting.md.
- Client factory parameters, auth fallback, and resource inventory: references/api-clients.md.
- Streaming conversion, projections, transport choices, and reconnect limitations: references/thread-streaming.md.
- Use scripts/inspect_sdk_exports.py to verify installed exports without credentials or network.
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).