From 32508ae9d4fad06b52b70be1e5f15c59d75a9001 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9C=B1=E6=BD=AE?= Date: Thu, 14 May 2026 17:14:37 +0800 Subject: [PATCH] fix: langfuse CallbackHandler API and tarfile dereference parameter - Update langfuse CallbackHandler to use trace_context instead of removed trace_id/session_id/user_id params - Pass session_id/user_id via LangChain metadata with langfuse_ prefix - Move dereference param from TarFile.add() to tarfile.open() Co-Authored-By: Claude Opus 4.6 --- agent/agent_config.py | 15 +++++++++++---- utils/daytona_sync.py | 6 +++--- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/agent/agent_config.py b/agent/agent_config.py index bd12fc5..456bba1 100644 --- a/agent/agent_config.py +++ b/agent/agent_config.py @@ -234,16 +234,23 @@ class AgentConfig: from utils.settings import LANGFUSE_ENABLED if LANGFUSE_ENABLED: from langfuse.langchain import CallbackHandler as LangfuseCallbackHandler + trace_context = {"trace_id": self.trace_id} if self.trace_id else None langfuse_handler = LangfuseCallbackHandler( - trace_id=self.trace_id, - session_id=self.session_id, - user_id=self.user_identifier, - metadata={"bot_id": self.bot_id, "model": self.model_name}, + trace_context=trace_context, ) callbacks.append(langfuse_handler) + langfuse_metadata = {} + if LANGFUSE_ENABLED: + if self.session_id: + langfuse_metadata["langfuse_session_id"] = self.session_id + if self.user_identifier: + langfuse_metadata["langfuse_user_id"] = self.user_identifier + if callbacks: config["callbacks"] = callbacks + if langfuse_metadata: + config["metadata"] = langfuse_metadata if self.session_id: config["configurable"] = {"thread_id": self.session_id} return config diff --git a/utils/daytona_sync.py b/utils/daytona_sync.py index fee8629..b09a7a9 100644 --- a/utils/daytona_sync.py +++ b/utils/daytona_sync.py @@ -61,12 +61,12 @@ def _list_local_changed_files(workspace_path: Path) -> tuple[bool, list[str]]: def _tar_workspace_entries(workspace_path: Path, entries: list[Path]) -> bytes: buf = io.BytesIO() - with tarfile.open(fileobj=buf, mode="w:gz") as tar: + with tarfile.open(fileobj=buf, mode="w:gz", dereference=True) as tar: for entry in entries: if entry.is_absolute(): - tar.add(str(entry), arcname=entry.relative_to(workspace_path).as_posix(), dereference=True) + tar.add(str(entry), arcname=entry.relative_to(workspace_path).as_posix()) else: - tar.add(str(workspace_path / entry), arcname=entry.as_posix(), dereference=True) + tar.add(str(workspace_path / entry), arcname=entry.as_posix()) buf.seek(0) return buf.read()