Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions NEXT_CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

### New Features and Improvements

* Added a `meta-harness` user-agent dimension that reports the omnigent meta-harness (detected via the `OMNIGENT` environment variable) independently of agent detection.

### Bug Fixes

### Documentation
Expand Down
11 changes: 11 additions & 0 deletions config/api_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@ func HTTPClientConfigFromConfig(cfg *Config) (httpclient.ClientConfig, error) {
*r = *r.WithContext(ctx) // replace request
return nil
},
func(r *http.Request) error {
// Detect if we are running inside a known agent meta-harness.
provider := useragent.MetaHarnessProvider()
if provider == "" {
return nil
}
// Add the detected meta-harness to the user agent.
ctx := useragent.InContext(r.Context(), useragent.MetaHarnessKey, provider)
*r = *r.WithContext(ctx) // replace request
return nil
},
}

return httpclient.ClientConfig{
Expand Down
53 changes: 53 additions & 0 deletions useragent/meta_harness.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package useragent

import (
"os"
"sync"
)

// knownMetaHarness describes a meta-harness that orchestrates AI agents (not
// itself an agent). Detected if envVar is set (any value, including empty, counts).
type knownMetaHarness struct {
envVar string
product string
}

// listKnownMetaHarnesses returns the canonical list of agent meta-harnesses.
// Keep in sync with databricks-sdk-py and databricks-sdk-java.
func listKnownMetaHarnesses() []knownMetaHarness {
return []knownMetaHarness{
{envVar: "OMNIGENT", product: "omnigent"}, // https://github.com/omnigent-ai/omnigent
}
}

// lookupMetaHarnessProvider returns the matched meta-harness product, "multiple"
// if more than one matched, or "" if none matched.
func lookupMetaHarnessProvider() string {
var matches []string
for _, h := range listKnownMetaHarnesses() {
if _, ok := os.LookupEnv(h.envVar); ok {
matches = append(matches, h.product)
}
}
switch len(matches) {
case 1:
return matches[0]
case 0:
return ""
default:
return "multiple"
}
}

var (
metaHarnessOnce sync.Once
metaHarnessName string
)

// MetaHarnessProvider returns the detected meta-harness name, cached for the process lifetime.
func MetaHarnessProvider() string {
metaHarnessOnce.Do(func() {
metaHarnessName = lookupMetaHarnessProvider()
})
return metaHarnessName
}
66 changes: 66 additions & 0 deletions useragent/meta_harness_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package useragent

import (
"testing"

"github.com/databricks/databricks-sdk-go/internal/env"
)

func TestLookupMetaHarnessProvider(t *testing.T) {
tests := []struct {
name string
envs map[string]string
expect string
}{
{
name: "no harness",
envs: nil,
expect: "",
},
{
name: "omnigent",
envs: map[string]string{"OMNIGENT": "1"},
expect: "omnigent",
},
{
name: "omnigent empty value still counts as set",
envs: map[string]string{"OMNIGENT": ""},
expect: "omnigent",
},
{
name: "agent env var does not affect harness",
envs: map[string]string{"CLAUDECODE": "1"},
expect: "",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
env.CleanupEnvironment(t)
ClearCache()
for k, v := range tt.envs {
t.Setenv(k, v)
}
got := lookupMetaHarnessProvider()
if got != tt.expect {
t.Errorf("lookupMetaHarnessProvider() = %q, want %q", got, tt.expect)
}
})
}
}

func TestMetaHarnessProviderCached(t *testing.T) {
env.CleanupEnvironment(t)
ClearCache()
t.Setenv("OMNIGENT", "1")
got := MetaHarnessProvider()
if got != "omnigent" {
t.Errorf("MetaHarnessProvider() = %q, want %q", got, "omnigent")
}
// Change env after caching. Cached result should persist.
t.Setenv("OMNIGENT", "")
got = MetaHarnessProvider()
if got != "omnigent" {
t.Errorf("MetaHarnessProvider() after cache = %q, want %q", got, "omnigent")
}
}
1 change: 1 addition & 0 deletions useragent/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ func ClearCache() {
runtimeOnce = sync.Once{}
providerOnce = sync.Once{}
agentOnce = sync.Once{}
metaHarnessOnce = sync.Once{}
}

var runtimeOnce sync.Once
Expand Down
9 changes: 5 additions & 4 deletions useragent/user_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (
)

const (
RuntimeKey = "runtime"
CicdKey = "cicd"
AuthKey = "auth"
AgentKey = "agent"
RuntimeKey = "runtime"
CicdKey = "cicd"
AuthKey = "auth"
AgentKey = "agent"
MetaHarnessKey = "meta-harness"
)

// WithProduct sets the product name and product version globally.
Expand Down
Loading