The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
[LangChainTracer] Omit Chunk (#26602)
William FH55af6fbd022e
diff --git a/libs/core/langchain_core/tracers/langchain.py b/libs/core/langchain_core/tracers/langchain.pyindex 5ac1f6496f..73aebab048 100644--- a/libs/core/langchain_core/tracers/langchain.py+++ b/libs/core/langchain_core/tracers/langchain.py@@ -23,6 +23,7 @@ from tenacity import (from langchain_core.env import get_runtime_environmentfrom langchain_core.load import dumpd+from langchain_core.outputs import ChatGenerationChunk, GenerationChunkfrom langchain_core.tracers.base import BaseTracerfrom langchain_core.tracers.schemas import Run@@ -240,6 +241,26 @@ class LangChainTracer(BaseTracer):run.reference_example_id = self.example_idself._persist_run_single(run)+ def _llm_run_with_token_event(+ self,+ token: str,+ run_id: UUID,+ chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None,+ parent_run_id: Optional[UUID] = None,+ **kwargs: Any,+ ) -> Run:+ """+ Append token event to LLM run and return the run.+ """+ return super()._llm_run_with_token_event(+ # Drop the chunk; we don't need to save it+ token,+ run_id,+ chunk=None,+ parent_run_id=parent_run_id,+ **kwargs,+ )+def _on_chat_model_start(self, run: Run) -> None:"""Persist an LLM run."""if run.parent_run_id is None: