Skip to content

Commit 037349f

Browse files
authored
Python: fix Langfuse observability to capture ChatAgent system instructions (#2316)
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)
1 parent 293abf5 commit 037349f

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

python/packages/core/agent_framework/observability.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1120,7 +1120,7 @@ async def trace_run(
11201120
span=span,
11211121
provider_name=provider_name,
11221122
messages=messages,
1123-
system_instructions=getattr(self, "instructions", None),
1123+
system_instructions=getattr(getattr(self, "chat_options", None), "instructions", None),
11241124
)
11251125
try:
11261126
response = await run_func(self, messages=messages, thread=thread, **kwargs)
@@ -1189,7 +1189,7 @@ async def trace_run_streaming(
11891189
span=span,
11901190
provider_name=provider_name,
11911191
messages=messages,
1192-
system_instructions=getattr(self, "instructions", None),
1192+
system_instructions=getattr(getattr(self, "chat_options", None), "instructions", None),
11931193
)
11941194
try:
11951195
async for update in run_streaming_func(self, messages=messages, thread=thread, **kwargs):

0 commit comments

Comments
 (0)