Files
Agent-System-Backend/internal/runtime/provider_run_identity.go
T

31 lines
931 B
Go

package runtime
import (
"context"
agentllm "agent-native/runtime/llm"
)
type providerRunIDKey struct{}
// WithProviderRunID binds a provider request to the host-owned run rather than
// a mutable prompt transcript. It does not change the request body.
func WithProviderRunID(ctx context.Context, id string) context.Context {
if id == "" {
return ctx
}
return context.WithValue(ctx, providerRunIDKey{}, id)
}
// ProviderRunID returns the host-owned run identity for evaluation controls.
func ProviderRunID(ctx context.Context) string {
id, _ := ctx.Value(providerRunIDKey{}).(string)
return id
}
func bindProviderRunID(stream agentllm.StreamFunc, id string) agentllm.StreamFunc {
return func(ctx context.Context, model string, messages []agentllm.Message, tools []agentllm.ToolDecl, opts agentllm.StreamOptions) <-chan agentllm.Event {
return stream(WithProviderRunID(ctx, id), model, messages, tools, opts)
}
}