Skip to content

Commit 95f583d

Browse files
committed
move to att
1 parent 9cf4d61 commit 95f583d

File tree

8 files changed

+17
-23
lines changed

8 files changed

+17
-23
lines changed

sample-app/generate_joke_workflow_example.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func runJokeWorkflow() {
264264
"user_id": "user_12345",
265265
"chat_id": "chat_1234",
266266
},
267-
}, nil)
267+
})
268268
defer wf.End()
269269

270270
// Execute workflow steps

sample-app/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,4 @@ func workflowExample() {
124124
})
125125

126126
fmt.Println(resp.Choices[0].Message.Content)
127-
}
127+
}

sample-app/recipe_agent_example.go

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ func ingredientValidatorTool(ctx context.Context, agent *sdk.Agent, client *open
5353

5454
llmSpan := tool.LogPrompt(prompt)
5555

56-
// Make API call
5756
resp, err := client.CreateChatCompletion(ctx, openai.ChatCompletionRequest{
5857
Model: "gpt-3.5-turbo",
5958
Messages: []openai.ChatCompletionMessage{
@@ -67,7 +66,6 @@ func ingredientValidatorTool(ctx context.Context, agent *sdk.Agent, client *open
6766
return "", fmt.Errorf("CreateChatCompletion error: %w", err)
6867
}
6968

70-
// Log completion
7169
var completionMsgs []sdk.Message
7270
for _, choice := range resp.Choices {
7371
completionMsgs = append(completionMsgs, sdk.Message{
@@ -121,7 +119,6 @@ func nutritionCalculatorTool(ctx context.Context, agent *sdk.Agent, client *open
121119

122120
llmSpan := tool.LogPrompt(prompt)
123121

124-
// Make API call
125122
resp, err := client.CreateChatCompletion(ctx, openai.ChatCompletionRequest{
126123
Model: "gpt-3.5-turbo",
127124
Messages: []openai.ChatCompletionMessage{
@@ -135,7 +132,6 @@ func nutritionCalculatorTool(ctx context.Context, agent *sdk.Agent, client *open
135132
return "", fmt.Errorf("CreateChatCompletion error: %w", err)
136133
}
137134

138-
// Log completion
139135
var completionMsgs []sdk.Message
140136
for _, choice := range resp.Choices {
141137
completionMsgs = append(completionMsgs, sdk.Message{
@@ -191,7 +187,6 @@ func cookingTimeEstimatorTool(ctx context.Context, agent *sdk.Agent, client *ope
191187

192188
llmSpan := tool.LogPrompt(prompt)
193189

194-
// Make API call
195190
resp, err := client.CreateChatCompletion(ctx, openai.ChatCompletionRequest{
196191
Model: "gpt-3.5-turbo",
197192
Messages: []openai.ChatCompletionMessage{
@@ -205,7 +200,6 @@ func cookingTimeEstimatorTool(ctx context.Context, agent *sdk.Agent, client *ope
205200
return "", fmt.Errorf("CreateChatCompletion error: %w", err)
206201
}
207202

208-
// Log completion
209203
var completionMsgs []sdk.Message
210204
for _, choice := range resp.Choices {
211205
completionMsgs = append(completionMsgs, sdk.Message{
@@ -246,10 +240,10 @@ func runRecipeAgent() {
246240
agent := traceloop.NewAgent(ctx, "recipe_generator", sdk.AgentAttributes{
247241
Name: "recipe_generator",
248242
AssociationProperties: associationProperties,
249-
}, abTest)
243+
ABTest: abTest,
244+
})
250245
defer agent.End()
251246

252-
// User request
253247
userRequest := "Create a healthy pasta dish with vegetables"
254248
fmt.Printf("User request: %s\n\n", userRequest)
255249

@@ -284,7 +278,6 @@ func runRecipeAgent() {
284278
return
285279
}
286280

287-
// Log completion
288281
var completionMsgs []sdk.Message
289282
for _, choice := range resp.Choices {
290283
completionMsgs = append(completionMsgs, sdk.Message{

sample-app/workflow_example.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func workflowMain() {
2626

2727
wf := traceloop.NewWorkflow(ctx, tlp.WorkflowAttributes{
2828
Name: "history_generation",
29-
}, nil)
29+
})
3030
defer wf.End()
3131

3232
factGenTask := wf.NewTask("current_date_fact_generation")

traceloop-sdk/agent.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ type Agent struct {
1515
workflow *Workflow
1616
ctx context.Context
1717
Attributes AgentAttributes `json:"agent_attributes"`
18-
ABTest *model.ABTest `json:"ab_test"`
1918
}
2019

2120
func (agent *Agent) End() {

traceloop-sdk/sdk.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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, agentAttrs AgentAttributes, abTest *model.ABTest) *Agent {
146+
func (instance *Traceloop) NewAgent(ctx context.Context, name string, agentAttrs AgentAttributes) *Agent {
147147
aCtx, span := instance.getTracer().Start(ctx, fmt.Sprintf("%s.agent", name), apitrace.WithNewRoot())
148148

149149
attrs := []attribute.KeyValue{
@@ -152,8 +152,8 @@ func (instance *Traceloop) NewAgent(ctx context.Context, name string, agentAttrs
152152
semconvai.LLMAgentName.String(name),
153153
}
154154

155-
if abTest != nil {
156-
for key, activeVarient := range abTest.VarientsKeys {
155+
if agentAttrs.ABTest != nil {
156+
for key, activeVarient := range agentAttrs.ABTest.VarientsKeys {
157157
if activeVarient {
158158
agentAttrs.AssociationProperties["ab_testing_variant"] = key
159159
break
@@ -173,7 +173,6 @@ func (instance *Traceloop) NewAgent(ctx context.Context, name string, agentAttrs
173173
workflow: nil,
174174
ctx: aCtx,
175175
Attributes: agentAttrs,
176-
ABTest: abTest,
177176
}
178177
}
179178

traceloop-sdk/tracing_types.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package traceloop
22

3+
import "github.com/traceloop/go-openllmetry/traceloop-sdk/model"
4+
35
type Message struct {
46
Index int `json:"index"`
57
Role string `json:"role"`
@@ -28,6 +30,7 @@ type Completion struct {
2830
type WorkflowAttributes struct {
2931
Name string `json:"workflow_name"`
3032
AssociationProperties map[string]string `json:"association_properties"`
33+
ABTest *model.ABTest `json:"ab_test"`
3134
}
3235

3336
type ContextAttributes struct {
@@ -66,4 +69,5 @@ type ToolCallAttributes struct {
6669
type AgentAttributes struct {
6770
Name string `json:"agent_name"`
6871
AssociationProperties map[string]string `json:"association_properties"`
72+
ABTest *model.ABTest `json:"ab_test"`
6973
}

traceloop-sdk/workflow.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ type Workflow struct {
1414
sdk *Traceloop
1515
ctx context.Context
1616
Attributes WorkflowAttributes `json:"workflow_attributes"`
17-
ABTest *model.ABTest `json:"ab_test"`
1817
}
1918

20-
func (instance *Traceloop) NewWorkflow(ctx context.Context, attrs WorkflowAttributes, abTest *model.ABTest) *Workflow {
19+
func (instance *Traceloop) NewWorkflow(ctx context.Context, attrs WorkflowAttributes) *Workflow {
2120
wCtx, span := instance.getTracer().Start(ctx, fmt.Sprintf("%s.workflow", attrs.Name), trace.WithNewRoot())
2221

2322
span.SetAttributes(
@@ -26,8 +25,8 @@ func (instance *Traceloop) NewWorkflow(ctx context.Context, attrs WorkflowAttrib
2625
semconvai.TraceloopEntityName.String(attrs.Name),
2726
)
2827

29-
if abTest != nil {
30-
for key, activeVarient := range abTest.VarientsKeys {
28+
if attrs.ABTest != nil {
29+
for key, activeVarient := range attrs.ABTest.VarientsKeys {
3130
if activeVarient {
3231
span.SetAttributes(attribute.String("traceloop.association.properties.ab_testing_variant", key))
3332
break
@@ -79,8 +78,8 @@ func (workflow *Workflow) NewAgent(name string, associationProperties map[string
7978
semconvai.TraceloopEntityName.String(name),
8079
}
8180

82-
if workflow.ABTest != nil {
83-
for key, activeVarient := range workflow.ABTest.VarientsKeys {
81+
if workflow.Attributes.ABTest != nil {
82+
for key, activeVarient := range workflow.Attributes.ABTest.VarientsKeys {
8483
if activeVarient {
8584
associationProperties["ab_testing_variant"] = key
8685
}

0 commit comments

Comments
 (0)