-
Notifications
You must be signed in to change notification settings - Fork 11
feat: implement tool calling support for workflow API #21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 11 commits
3663aa4
4d8bfcf
b58867c
1f11793
21d07fe
c006c09
b3ae33b
929e4e9
61aac6e
cbb7441
597a48d
9d4aa6e
b565278
fddb6dd
6426159
d61145b
78c610c
84be527
0276b21
00842b0
7952b5a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
module github.com/traceloop/go-openllmetry | ||
|
||
go 1.21 | ||
|
||
require ( | ||
github.com/traceloop/go-openllmetry/traceloop-sdk v0.0.0-00010101000000-000000000000 | ||
github.com/traceloop/go-openllmetry/semconv-ai v0.0.0-00010101000000-000000000000 | ||
) | ||
|
||
replace github.com/traceloop/go-openllmetry/traceloop-sdk => ./traceloop-sdk | ||
|
||
replace github.com/traceloop/go-openllmetry/semconv-ai => ./semconv-ai |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
go 1.21 | ||
go 1.23.0 | ||
|
||
use ( | ||
sample-app | ||
semconv-ai | ||
traceloop-sdk | ||
sample-app | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
# VCR cassettes may contain sensitive data during development | ||
# Only include pre-sanitized mock cassettes | ||
testdata/* | ||
!testdata/tool_calling_cassette.yaml |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Sample Apps | ||
|
||
This directory contains sample applications demonstrating the Traceloop Go OpenLLMetry SDK. | ||
|
||
## Regular Sample | ||
|
||
Run the regular sample that demonstrates basic prompt logging: | ||
|
||
```bash | ||
go run . | ||
``` | ||
|
||
## Tool Calling Sample | ||
|
||
Run the tool calling sample that demonstrates tool calling with the OpenAI Go SDK: | ||
|
||
```bash | ||
go run . tool-calling | ||
``` | ||
|
||
### Environment Variables | ||
|
||
Set the following environment variables: | ||
|
||
```bash | ||
export OPENAI_API_KEY="your-openai-api-key" | ||
export TRACELOOP_API_KEY="your-traceloop-api-key" | ||
export TRACELOOP_BASE_URL="https://api.traceloop.com" # Optional | ||
``` | ||
|
||
### Tool Calling Features | ||
|
||
The tool calling sample demonstrates: | ||
- Request tools logging with function definitions | ||
- Response tool calls logging with execution results | ||
- Multi-turn conversations with tool execution | ||
- Complete traceability of tool calling interactions |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Testing Tool Calling Without API Keys | ||
|
||
This directory contains testing for tool calling functionality that works in CI environments without requiring actual API keys. | ||
|
||
## Testing Approach | ||
|
||
### VCR Recording (`tool_calling_test.go`) | ||
|
||
Uses `go-vcr` to record real API interactions and replay them in tests. **API keys are automatically sanitized** from recordings. | ||
|
||
```bash | ||
# First run with real API key to record (local only) | ||
OPENAI_API_KEY=your_key go test -v -run TestToolCallingWithMock | ||
|
||
# Subsequent runs use recorded cassettes (works in CI) | ||
go test -v -run TestToolCallingWithMock | ||
``` | ||
|
||
**Security Features:** | ||
- 🔒 Authorization headers are automatically removed from cassettes | ||
- 🔒 Request bodies are sanitized to prevent accidental key leakage | ||
- 🔒 Cassettes are gitignored by default for extra safety | ||
|
||
**Pros:** | ||
- ✅ Uses real API responses | ||
- ✅ Accurate representation of actual data | ||
- ✅ Works in CI without API keys (after recording) | ||
- ✅ Automatic sanitization of sensitive data | ||
|
||
**Cons:** | ||
- ❌ Requires initial recording with real API key | ||
- ❌ Additional dependency | ||
|
||
### Integration Tests (Optional) | ||
|
||
Real API calls for full integration testing. | ||
|
||
```bash | ||
# Run integration tests (requires API keys) | ||
OPENAI_API_KEY=your_key INTEGRATION_TEST=1 go test -v -run TestToolCallingIntegration | ||
``` | ||
|
||
## CI Configuration | ||
|
||
For GitHub Actions or other CI systems: | ||
|
||
```yaml | ||
- name: Run Tests | ||
run: | | ||
# Run VCR tests with pre-sanitized cassettes (no API keys needed) | ||
go test -v -run TestToolCallingWithMock | ||
|
||
# Skip integration tests in CI (or use secrets for API keys) | ||
``` | ||
|
||
## Mock Data Structure | ||
|
||
The VCR cassette contains realistic OpenAI API responses: | ||
|
||
```json | ||
{ | ||
"choices": [{ | ||
"message": { | ||
"role": "assistant", | ||
"tool_calls": [{ | ||
"id": "call_YkIfypBQrmpUpxsKuS9aNdKg", | ||
"type": "function", | ||
"function": { | ||
"name": "get_weather", | ||
"arguments": "{\"location\":\"San Francisco, CA\"}" | ||
} | ||
}] | ||
} | ||
}], | ||
"usage": { | ||
"prompt_tokens": 82, | ||
"completion_tokens": 17, | ||
"total_tokens": 99 | ||
} | ||
} | ||
``` | ||
|
||
This ensures our tracing code gets realistic data to work with and validates that all span attributes are set correctly. |
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
@@ -1,5 +1,60 @@ | ||||||||
module github.com/traceloop/go-openllmetry/sample-app | ||||||||
|
||||||||
go 1.21 | ||||||||
go 1.23.0 | ||||||||
|
||||||||
require github.com/sashabaranov/go-openai v1.18.1 | ||||||||
require ( | ||||||||
github.com/openai/openai-go v0.1.0-alpha.35 | ||||||||
github.com/sashabaranov/go-openai v1.18.1 | ||||||||
github.com/traceloop/go-openllmetry/traceloop-sdk v0.0.0-00010101000000-000000000000 | ||||||||
gopkg.in/dnaeon/go-vcr.v2 v2.3.0 | ||||||||
) | ||||||||
|
||||||||
require ( | ||||||||
github.com/cenkalti/backoff v2.2.1+incompatible // indirect | ||||||||
github.com/cenkalti/backoff/v4 v4.2.1 // indirect | ||||||||
github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect | ||||||||
github.com/go-git/go-billy/v5 v5.5.0 // indirect | ||||||||
github.com/go-git/go-git/v5 v5.11.0 // indirect | ||||||||
github.com/go-logr/logr v1.4.3 // indirect | ||||||||
github.com/go-logr/stdr v1.2.2 // indirect | ||||||||
github.com/gobwas/glob v0.2.3 // indirect | ||||||||
github.com/golang/protobuf v1.5.3 // indirect | ||||||||
github.com/google/uuid v1.6.0 // indirect | ||||||||
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 // indirect | ||||||||
github.com/hashicorp/errwrap v1.1.0 // indirect | ||||||||
github.com/hashicorp/go-multierror v1.1.1 // indirect | ||||||||
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect | ||||||||
github.com/jinzhu/copier v0.4.0 // indirect | ||||||||
github.com/joho/godotenv v1.5.1 // indirect | ||||||||
github.com/kluctl/go-embed-python v0.0.0-3.11.6-20231002-1 // indirect | ||||||||
github.com/kluctl/go-jinja2 v0.0.0-20240108142937-8839259d2537 // indirect | ||||||||
github.com/rogpeppe/go-internal v1.13.1 // indirect | ||||||||
github.com/sirupsen/logrus v1.9.3 // indirect | ||||||||
github.com/tidwall/gjson v1.14.4 // indirect | ||||||||
github.com/tidwall/match v1.1.1 // indirect | ||||||||
github.com/tidwall/pretty v1.2.1 // indirect | ||||||||
github.com/tidwall/sjson v1.2.5 // indirect | ||||||||
github.com/traceloop/go-openllmetry/semconv-ai v0.0.0-20250405130248-6b2b4b41102b // indirect | ||||||||
go.opentelemetry.io/auto/sdk v1.1.0 // indirect | ||||||||
go.opentelemetry.io/otel v1.37.0 // indirect | ||||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.22.0 // indirect | ||||||||
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.22.0 // indirect | ||||||||
go.opentelemetry.io/otel/metric v1.37.0 // indirect | ||||||||
go.opentelemetry.io/otel/sdk v1.37.0 // indirect | ||||||||
go.opentelemetry.io/otel/trace v1.37.0 // indirect | ||||||||
go.opentelemetry.io/proto/otlp v1.0.0 // indirect | ||||||||
nirga marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||
golang.org/x/net v0.27.0 // indirect | ||||||||
golang.org/x/sync v0.7.0 // indirect | ||||||||
golang.org/x/sys v0.33.0 // indirect | ||||||||
golang.org/x/text v0.16.0 // indirect | ||||||||
google.golang.org/genproto/googleapis/api v0.0.0-20231002182017-d307bd883b97 // indirect | ||||||||
google.golang.org/genproto/googleapis/rpc v0.0.0-20231002182017-d307bd883b97 // indirect | ||||||||
google.golang.org/grpc v1.60.1 // indirect | ||||||||
google.golang.org/protobuf v1.32.0 // indirect | ||||||||
gopkg.in/warnings.v0 v0.1.2 // indirect | ||||||||
gopkg.in/yaml.v3 v3.0.1 // indirect | ||||||||
) | ||||||||
|
||||||||
replace github.com/traceloop/go-openllmetry/traceloop-sdk => ../traceloop-sdk | ||||||||
|
||||||||
replace github.com/traceloop/go-openllmetry/semconv-ai => ../semconv-ai | ||||||||
Comment on lines
+57
to
+59
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 💡 Verification agent 🧩 Analysis chainPrefer a Local replaces are fine for development, but a Check if a workspace file exists: If adopting
🏁 Script executed: #!/bin/bash
fd -a go.work Length of output: 73 To confirm that the workspace already includes the local modules (so we can safely drop those 🏁 Script executed: #!/bin/bash
echo "=== go.work ==="
cat go.work Length of output: 112 Remove redundant replace directives in sample-app/go.mod Since your go.work already includes • File: sample-app/go.mod - replace github.com/traceloop/go-openllmetry/traceloop-sdk => ../traceloop-sdk
- replace github.com/traceloop/go-openllmetry/semconv-ai => ../semconv-ai 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents
|
Uh oh!
There was an error while loading. Please reload this page.