From 23730e40a9f18bda7ca5f953e5710ceb9d1d8487 Mon Sep 17 00:00:00 2001 From: claude89757 <138977524+claude89757@users.noreply.github.com> Date: Wed, 19 Nov 2025 12:06:54 +0800 Subject: [PATCH] Python: fix Langfuse observability to capture ChatAgent system instructions Fix bug where ChatAgent system instructions were not captured in Langfuse traces due to incorrect attribute access. The observability code was attempting to retrieve instructions using getattr(self, "instructions", None), but ChatAgent stores instructions in self.chat_options.instructions. This caused system_instructions to always be None in Langfuse traces. Changed both _trace_agent_run and _trace_agent_run_stream functions to correctly retrieve instructions from chat_options.instructions. Fixes affect: - Line 1123: _trace_agent_run (non-streaming) - Line 1192: _trace_agent_run_stream (streaming) --- python/packages/core/agent_framework/observability.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/python/packages/core/agent_framework/observability.py b/python/packages/core/agent_framework/observability.py index 3e44fae23c..d26cc1c4b7 100644 --- a/python/packages/core/agent_framework/observability.py +++ b/python/packages/core/agent_framework/observability.py @@ -1120,7 +1120,7 @@ async def trace_run( span=span, provider_name=provider_name, messages=messages, - system_instructions=getattr(self, "instructions", None), + system_instructions=getattr(getattr(self, "chat_options", None), "instructions", None), ) try: response = await run_func(self, messages=messages, thread=thread, **kwargs) @@ -1189,7 +1189,7 @@ async def trace_run_streaming( span=span, provider_name=provider_name, messages=messages, - system_instructions=getattr(self, "instructions", None), + system_instructions=getattr(getattr(self, "chat_options", None), "instructions", None), ) try: async for update in run_streaming_func(self, messages=messages, thread=thread, **kwargs):