Skip to content

Commit 01c1198

Browse files
committed
add prop
1 parent 3f52b3f commit 01c1198

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

sample-app/generate_joke_workflow_example.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ func historyJokesTool(ctx context.Context, agent *sdk.Agent, client *openai.Clie
149149
Name: "history_jokes",
150150
Description: "Get some history jokes",
151151
Parameters: map[string]interface{}{},
152+
}, map[string]string{
153+
"user_id": "user_12345",
152154
})
153155
defer tool.End()
154156

sample-app/recipe_agent_example.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ import (
99
sdk "github.com/traceloop/go-openllmetry/traceloop-sdk"
1010
)
1111

12+
var associationProperties = map[string]string{
13+
"user_id": "user_67890",
14+
"ab_testing_variant": "variant_a",
15+
}
16+
1217
// ingredientValidatorTool validates that requested ingredients are available/safe
1318
func ingredientValidatorTool(ctx context.Context, agent *sdk.Agent, client *openai.Client, ingredients string) (string, error) {
1419
tool := agent.NewTool("ingredient_validator", "function", sdk.ToolFunction{
@@ -23,7 +28,7 @@ func ingredientValidatorTool(ctx context.Context, agent *sdk.Agent, client *open
2328
},
2429
},
2530
},
26-
})
31+
}, associationProperties)
2732
defer tool.End()
2833

2934
prompt := sdk.Prompt{
@@ -91,7 +96,7 @@ func nutritionCalculatorTool(ctx context.Context, agent *sdk.Agent, client *open
9196
},
9297
},
9398
},
94-
})
99+
}, associationProperties)
95100
defer tool.End()
96101

97102
prompt := sdk.Prompt{
@@ -159,6 +164,8 @@ func cookingTimeEstimatorTool(ctx context.Context, agent *sdk.Agent, client *ope
159164
},
160165
},
161166
},
167+
}, map[string]string{
168+
"user_id": "user_67890",
162169
})
163170
defer tool.End()
164171

@@ -229,10 +236,7 @@ func runRecipeAgent() {
229236
client := openai.NewClient(os.Getenv("OPENAI_API_KEY"))
230237

231238
// Create standalone agent with association properties
232-
agent := traceloop.NewAgent(ctx, "recipe_generator", map[string]string{
233-
"ab_testing_variant": "variant_a",
234-
"user_id": "user_67890",
235-
})
239+
agent := traceloop.NewAgent(ctx, "recipe_generator", associationProperties)
236240
defer agent.End()
237241

238242
// User request

traceloop-sdk/agent.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
semconvai "github.com/traceloop/go-openllmetry/semconv-ai"
8+
"go.opentelemetry.io/otel/attribute"
89
"go.opentelemetry.io/otel/trace"
910
"github.com/traceloop/go-openllmetry/traceloop-sdk/model"
1011
)
@@ -42,13 +43,24 @@ func (agent *Agent) LogPrompt(prompt Prompt) LLMSpan {
4243
return agent.sdk.LogPrompt(agent.ctx, prompt, contextAttrs)
4344
}
4445

45-
func (agent *Agent) NewTool(name string, toolType string, toolFunction ToolFunction) *Tool {
46+
func (agent *Agent) NewTool(name string, toolType string, toolFunction ToolFunction, associationProperties map[string]string) *Tool {
4647
toolCtx, span := agent.sdk.getTracer().Start(agent.ctx, fmt.Sprintf("%s.tool", name))
47-
span.SetAttributes(
48+
attrs := []attribute.KeyValue{
4849
semconvai.LLMAgentName.String(agent.Attributes.Name),
4950
semconvai.TraceloopSpanKind.String(string(model.SpanKindTool)),
5051
semconvai.TraceloopEntityName.String(name),
51-
)
52+
}
53+
54+
for key, value := range agent.Attributes.AssociationProperties {
55+
attrs = append(attrs, attribute.String("traceloop.association.properties."+key, value))
56+
}
57+
58+
// Add tool-specific association properties
59+
for key, value := range associationProperties {
60+
attrs = append(attrs, attribute.String("traceloop.association.properties."+key, value))
61+
}
62+
63+
span.SetAttributes(attrs...)
5264

5365
return &Tool{
5466
agent: *agent,

0 commit comments

Comments
 (0)