1818 ObservationTypeGenerationLike ,
1919 ObservationTypeSpanLike ,
2020)
21+ from langfuse ._client .skills import serialize_available_skills
2122from langfuse ._utils .serializer import EventSerializer
2223from langfuse .api import MapValue
2324from langfuse .logger import langfuse_logger
2425from langfuse .model import PromptClient
25- from langfuse .types import SpanLevel
26+ from langfuse .types import SkillReference , SpanLevel
2627
2728
2829class LangfuseOtelSpanAttributes :
@@ -41,6 +42,7 @@ class LangfuseOtelSpanAttributes:
4142 OBSERVATION_STATUS_MESSAGE = "langfuse.observation.status_message"
4243 OBSERVATION_INPUT = "langfuse.observation.input"
4344 OBSERVATION_OUTPUT = "langfuse.observation.output"
45+ OBSERVATION_SKILLS_AVAILABLE = "langfuse.observation.skills_available"
4446
4547 # Langfuse-observation of type Generation attributes
4648 OBSERVATION_COMPLETION_START_TIME = "langfuse.observation.completion_start_time"
@@ -87,6 +89,7 @@ def create_trace_attributes(
8789def create_span_attributes (
8890 * ,
8991 metadata : Optional [Any ] = None ,
92+ available_skills : Optional [list [SkillReference ]] = None ,
9093 input : Optional [Any ] = None ,
9194 output : Optional [Any ] = None ,
9295 level : Optional [SpanLevel ] = None ,
@@ -103,6 +106,7 @@ def create_span_attributes(
103106 LangfuseOtelSpanAttributes .VERSION : version ,
104107 LangfuseOtelSpanAttributes .OBSERVATION_INPUT : _serialize (input ),
105108 LangfuseOtelSpanAttributes .OBSERVATION_OUTPUT : _serialize (output ),
109+ ** create_available_skills_attributes (available_skills ),
106110 ** _flatten_and_serialize_metadata (metadata , "observation" ),
107111 }
108112
@@ -114,6 +118,7 @@ def create_generation_attributes(
114118 name : Optional [str ] = None ,
115119 completion_start_time : Optional [datetime ] = None ,
116120 metadata : Optional [Any ] = None ,
121+ available_skills : Optional [list [SkillReference ]] = None ,
117122 level : Optional [SpanLevel ] = None ,
118123 status_message : Optional [str ] = None ,
119124 version : Optional [str ] = None ,
@@ -148,12 +153,22 @@ def create_generation_attributes(
148153 LangfuseOtelSpanAttributes .OBSERVATION_MODEL_PARAMETERS : _serialize (
149154 model_parameters
150155 ),
156+ ** create_available_skills_attributes (available_skills ),
151157 ** _flatten_and_serialize_metadata (metadata , "observation" ),
152158 }
153159
154160 return {k : v for k , v in attributes .items () if v is not None }
155161
156162
163+ def create_available_skills_attributes (
164+ available_skills : Optional [list [SkillReference ]],
165+ ) -> dict [str , str ]:
166+ serialized = serialize_available_skills (available_skills )
167+ if serialized is None :
168+ return {}
169+ return {LangfuseOtelSpanAttributes .OBSERVATION_SKILLS_AVAILABLE : serialized }
170+
171+
157172def _serialize (obj : Any ) -> Optional [str ]:
158173 if obj is None or isinstance (obj , str ):
159174 return obj
0 commit comments