-
Notifications
You must be signed in to change notification settings - Fork 19.8k
Description
Checked other resources
- This is a bug, not a usage question.
- I added a clear and descriptive title that summarizes this issue.
- I used the GitHub search to find a similar question and didn't find it.
- I am sure that this is a bug in LangChain rather than my code.
- The bug is not resolved by updating to the latest stable version of LangChain (or the specific integration package).
- This is not related to the langchain-community package.
- I posted a self-contained, minimal, reproducible example. A maintainer can copy it and run it AS IS.
Package (Required)
- langchain
- langchain-openai
- langchain-anthropic
- langchain-classic
- langchain-core
- langchain-cli
- langchain-model-profiles
- langchain-tests
- langchain-text-splitters
- langchain-chroma
- langchain-deepseek
- langchain-exa
- langchain-fireworks
- langchain-groq
- langchain-huggingface
- langchain-mistralai
- langchain-nomic
- langchain-ollama
- langchain-perplexity
- langchain-prompty
- langchain-qdrant
- langchain-xai
- Other / not sure / general
Example Code (Python)
import asyncio
from langchain_core.runnables.config import RunnableConfig
from langchain_deepseek import ChatDeepSeek
from langfuse.langchain import CallbackHandler
async def main():
# Initialize Langfuse callback handler
handler = CallbackHandler(
secret_key="YOUR_LANGFUSE_SECRET_KEY",
public_key="YOUR_LANGFUSE_PUBLIC_KEY",
base_url="https://cloud.langfuse.com",
)
# Initialize DeepSeek model
llm = ChatDeepSeek(
model="deepseek-chat",
temperature=0,
)
print("\n=== Normal mode ===")
# Non-streaming call (llm_output is present)
resp = await llm.agenerate([[{"role": "user", "content": "hello"}]], callbacks=[handler])
print("response:", resp.generations[0][0].text)
print("\n=== Streaming mode ===")
# Streaming call (llm_output missing → reproduces the issue)
async for chunk in llm.astream("hello", RunnableConfig(callbacks=[handler])):
print(chunk, end="", flush=True)
if __name__ == "__main__":
asyncio.run(main())Error Message and Stack Trace (if applicable)
Description
I’m using LangChain with Langfuse instrumentation (via CallbackHandler). I noticed that the instrumentation does not work when I use streaming mode. After digging into it, I found that on_llm_end is invoked with an LLMResult that has no llm_output, which makes it difficult to extract the model name.
async def agenerate(...):
output = LLMResult(generations=generations, llm_output=llm_output)
...
run_manager.on_llm_end(output)
@override
def stream(...):
run_manager.on_llm_end(LLMResult(generations=[[generation]]))System Info
System Information
OS: Linux
OS Version: #1 SMP PREEMPT_DYNAMIC Wed Sep 25 22:06:14 CST 2024
Python Version: 3.12.11 (main, Jul 8 2025, 20:59:33) [Clang 20.1.4 ]
Package Information
langchain_core: 1.0.4
langchain: 1.0.5
langchain_community: 0.4.1
langsmith: 0.4.42
langchain_classic: 1.0.0
langchain_deepseek: 1.0.0
langchain_mcp_adapters: 0.1.13
langchain_openai: 1.0.2
langchain_text_splitters: 1.0.0
langgraph_sdk: 0.2.9
Optional packages not installed
langserve
Other Dependencies
aiohttp: 3.13.2
dataclasses-json: 0.6.7
httpx: 0.28.1
httpx-sse: 0.4.3
jsonpatch: 1.33
langgraph: 1.0.3
mcp: 1.21.0
numpy: 2.3.4
openai: 2.7.2
opentelemetry-api: 1.38.0
opentelemetry-exporter-otlp-proto-http: 1.38.0
opentelemetry-sdk: 1.38.0
orjson: 3.11.4
packaging: 25.0
pydantic: 2.12.4
pydantic-settings: 2.12.0
pytest: 9.0.1
PyYAML: 6.0.3
pyyaml: 6.0.3
requests: 2.32.5
requests-toolbelt: 1.0.0
rich: 14.2.0
sqlalchemy: 2.0.44
SQLAlchemy: 2.0.44
tenacity: 9.1.2
tiktoken: 0.12.0
typing-extensions: 4.15.0
zstandard: 0.25.0