@@ -143,7 +143,7 @@ func (instance *Traceloop) getTracer() apitrace.Tracer {
143143}
144144
145145// NewAgent creates a standalone agent (without a workflow)
146- func (instance * Traceloop ) NewAgent (ctx context.Context , name string , associationProperties map [ string ] string ) * Agent {
146+ func (instance * Traceloop ) NewAgent (ctx context.Context , name string , agentAttrs AgentAttributes , abTest * model. ABTest ) * Agent {
147147 aCtx , span := instance .getTracer ().Start (ctx , fmt .Sprintf ("%s.agent" , name ), apitrace .WithNewRoot ())
148148
149149 attrs := []attribute.KeyValue {
@@ -152,8 +152,17 @@ func (instance *Traceloop) NewAgent(ctx context.Context, name string, associatio
152152 semconvai .LLMAgentName .String (name ),
153153 }
154154
155+ if abTest != nil {
156+ for key , activeVarient := range abTest .VarientsKeys {
157+ if activeVarient {
158+ agentAttrs .AssociationProperties ["ab_testing_variant" ] = key
159+ break
160+ }
161+ }
162+ }
163+
155164 // Add association properties if provided
156- for key , value := range associationProperties {
165+ for key , value := range agentAttrs . AssociationProperties {
157166 attrs = append (attrs , attribute .String ("traceloop.association.properties." + key , value ))
158167 }
159168
@@ -163,10 +172,8 @@ func (instance *Traceloop) NewAgent(ctx context.Context, name string, associatio
163172 sdk : instance ,
164173 workflow : nil ,
165174 ctx : aCtx ,
166- Attributes : AgentAttributes {
167- Name : name ,
168- AssociationProperties : associationProperties ,
169- },
175+ Attributes : agentAttrs ,
176+ ABTest : abTest ,
170177 }
171178}
172179
0 commit comments