惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Recent Announcements
Recent Announcements
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog
T
The Blog of Author Tim Ferriss
J
Java Code Geeks
腾讯CDC
D
Docker
G
Google Developers Blog
D
DataBreaches.Net
雷峰网
雷峰网
Blog — PlanetScale
Blog — PlanetScale
S
SegmentFault 最新的问题
The Cloudflare Blog
有赞技术团队
有赞技术团队
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
Stack Overflow Blog
Stack Overflow Blog
大猫的无限游戏
大猫的无限游戏
量子位
美团技术团队
aimingoo的专栏
aimingoo的专栏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Engineering at Meta
Engineering at Meta
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More

LangChain Forum - Topics tagged python-help

Llama-server process has terminated: invalid argument --load-mode with Ollama client 0.32.6 and langchain-ollama 1.1.0 Langchain Certified Agent Engineer Exam - Exam link not received and no response Null-drift: A bare-metal O(1) Memory Store for continuous LangGraph agents Clarification needed: Assistant config vs context and graph initialization Proposal: a small local helper for readable run traces via PR Proxy Authentication Required 407 What is the right way to dynamically create and run a graph? Re-Implement claude code's dynamic workflow using langchian & deepagents How to define a correct state for multi-agent system Response Format Groq Model Pydantic I hope to get some recommendations for practical skills Interrupt does not work correctly in LangGraph The Qwen3.6b model in fireworks through initchatmodel reporting hugely inflated tokens For parallel execution in Node, should i use the functional API? Potential Enhancement: Django-Managed PostgresSaver Pre-interrupt() code re-runs on resume — anti-pattern, or is there a sanctioned way to detect resume? Interrupt parallel branch execution Best practices for self-hosting LangGraph Server OSS without LangGraph keys Dynamically Enabling/Disabling Graphs in a LangGraph Server at Runtime LangGraph thread copy can take 12+ minutes: recommended production pattern? Will DeltaChannel be the default for AgentState.messages, or expected to stay opt-in? Proposal: additional docs for implementing custom DB checkpointers or a guide on generic base checkpointer Prompt_cache_retention: '24h' supported in langchain agents and where to provide it, inside invoke or while creating client? Could RAG pipelines realistically cause deployment timeouts, is Render suitable for first-time RAG deployments? How do I use langchain_postgres' init_vectorstore_table correctly? Proposal: Graph-wide default error handler for StateGraph (fallback for nodes without error_handler) Support timedelta for CachePolicy.ttl, consistent with TimeoutPolicy Anyone confirms this issue that deepagent ui streaming is disturb by update in deepagent or bug issue Best Stack for Building AI Applications Seeking help regarding the connection between Websocket and tool calls
Parallel astream() on the same compiled graph leaks messa...
@kzoltan Zol · 2026-04-23 · via LangChain Forum - Topics tagged python-help
Hi, I ran into the below issue. The script might need to be executed several times to hit the bug. Is this referenced somewhere in the doc? Is this expected? Thanks! “”"Minimal reproduction of LangGraph concurrent astream() token-leak bug. Bug: When the same compiled graph (and therefore the same underlying chat model instance) is streamed concurrently from two asyncio tasks with stream_mode="messages", token chunks emitted by the model during one task’s call can surface inside the other task’s astream() iterator. Root cause (short version): stream_mode="messages" installs a streaming callback handler through LangChain’s callback-manager contextvar. The contextvar is per-asyncio- Task in theory, but the compiled graph holds bound references to the shared model’s configuration, and the BaseChatModel’s streaming path can pick up the “wrong” callback manager when two tasks interleave inside _astream. The result: token T produced by the model during Task B’s invocation gets delivered to Task A’s queue. Expected output when the bug reproduces: Task A collected chunks that include text meant for Task B (or vice versa). The script asserts isolation at the end; it raises AssertionError when the bug is present. “”" from future import annotations import asyncio from typing import Any from langchain_core.language_models.fake_chat_models import GenericFakeChatModel from langchain_core.messages import AIMessage, HumanMessage from langgraph.graph import END, START, MessagesState, StateGraph def build_shared_graph(responses: list[str]) → Any: “”"Build ONE compiled graph whose LLM node cycles through responses. Using ``GenericFakeChatModel`` here keeps the repro hermetic — no network, no API key — while still going through LangChain's ``BaseChatModel`` streaming machinery (which is where the leak originates). """ # ``GenericFakeChatModel`` accepts an iterator of AIMessages and # streams their content char-by-char through BaseChatModel._astream, # which is the exact path LangGraph hooks its "messages" stream-mode # callback into. messages_iter = iter(AIMessage(content=r) for r in responses) model = GenericFakeChatModel(messages=messages_iter) async def call_model(state: MessagesState) -> dict: # Note: no explicit config plumbing. This mirrors what agent # middleware does internally — the model is called under whatever # RunnableConfig is current in the contextvar. reply = await model.ainvoke(state["messages"]) return {"messages": [reply]} builder: StateGraph = StateGraph(MessagesState) builder.add_node("chat", call_model) builder.add_edge(START, "chat") builder.add_edge("chat", END) return builder.compile() async def run_stream(graph: Any, label: str, prompt: str, out: list[str]) → None: “”"Drive graph.astream with stream_mode="messages". Collects every AIMessageChunk text into ``out``. Each concurrent caller gets its own ``out`` list — if isolation held, each list should contain only the content produced for *its own* prompt. """ async for chunk, _metadata in graph.astream( {"messages": [HumanMessage(content=prompt)]}, {"configurable": {"thread_id": label}}, stream_mode="messages", ): # AIMessageChunk.content can be str or a list of content blocks. text = chunk.content if isinstance(chunk.content, str) else str(chunk.content) if text: out.append(text) # Small sleep to maximise interleaving between the two tasks. await asyncio.sleep(0) print(f"[{label}] collected: {''.join(out)!r}") async def main() → None: Two clearly distinguishable responses so we can tell which task’s stream a chunk belongs to by eyeballing the text alone. response_a = “AAAA-AAAA-AAAA-AAAA-AAAA” response_b = “BBBB-BBBB-BBBB-BBBB-BBBB” # One shared compiled graph (same instance for both tasks) — this is # exactly the condition under which the bug manifests in production. # The model's internal iterator yields response_a first, then # response_b; the two concurrent astreams will race to consume them. graph = build_shared_graph([response_a, response_b]) collected_a: list[str] = [] collected_b: list[str] = [] await asyncio.gather( run_stream(graph, "A", "say AAAA", collected_a), run_stream(graph, "B", "say BBBB", collected_b), ) text_a = "".join(collected_a) text_b = "".join(collected_b) print() print(f"Task A final text: {text_a!r}") print(f"Task B final text: {text_b!r}") print() # Isolation assertions. If the bug is present at least one of these # will fail — a task will have received some of the *other* task's # characters (or will be missing its own). a_has_b_chunks = "B" in text_a b_has_a_chunks = "A" in text_b if a_has_b_chunks or b_has_a_chunks: print("LEAK DETECTED:") if a_has_b_chunks: print(" - Task A received B-chunks (should only contain A)") if b_has_a_chunks: print(" - Task B received A-chunks (should only contain B)") raise AssertionError("concurrent astream() leaked tokens across tasks") print("No leak observed in this run.") if name == “main”: asyncio.run(main())