toolbridge

package
v0.73.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2026 License: Apache-2.0 Imports: 13 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package toolbridge implements a generic HTTP client for the SpeechKit voice-agent tool bridge wire contract "speechkit.toolbridge.v1" (docs/server/toolbridge.v1.md).

The bridge is deployment-neutral: it knows nothing about who operates the remote endpoint. All tenant semantics (tool curation, authorization, entitlements, approval) live behind the two configured URLs; SpeechKit only forwards the opaque per-session credential the fronting proxy supplied at session creation as an Authorization bearer.

Fail-closed behavior:

  • no credential -> no manifest, session runs tool-less
  • manifest fetch failure -> session runs tool-less
  • invoke failure / denial -> structured error payload ({error, user_guidance}) the model can verbalize; the session never dies
  • hard per-session call cap (default 20)

The package is intentionally platform-neutral (no build tag) so its unit tests run on every OS; the linux-only server wiring adapts it to the voiceagent.SessionToolRouter interface.

Index

Constants

View Source
const (
	// DefaultTimeout bounds one invoke round-trip.
	DefaultTimeout = 10 * time.Second
	// DefaultMaxCallsPerSession is the hard per-session invoke cap.
	DefaultMaxCallsPerSession = 20
)
View Source
const WireVersion = "speechkit.toolbridge.v1"

WireVersion is the toolbridge wire-contract version this client speaks.

Variables

This section is empty.

Functions

This section is empty.

Types

type Bridge

type Bridge struct {
	// contains filtered or unexported fields
}

Bridge is a concurrency-safe toolbridge HTTP client shared across sessions.

func New

func New(opts Options) (*Bridge, error)

New constructs a Bridge. Returns an error when either URL is missing so a misconfigured deployment fails at wiring time, not mid-session.

func (*Bridge) Definitions

func (b *Bridge) Definitions(ctx context.Context, session Session) ([]ToolDefinition, error)

Definitions returns the tool manifest for the session, cached per credential for manifestCacheTTL. A session without a credential gets no tools (fail-closed). Errors mean "run tool-less", never "kill the session".

func (*Bridge) Execute

func (b *Bridge) Execute(ctx context.Context, session Session, tool string, args map[string]any) (map[string]any, bool)

Execute invokes one tool call. The returned map is always a model-facing tool response payload; ok=false is returned only when no usable payload could be produced (the caller substitutes a generic structured error). Denial envelopes from the remote endpoint are mapped to {error:{code,message}, user_guidance:...} so the model verbalizes the denial instead of hallucinating a result.

type Options

type Options struct {
	// ManifestURL is the GET endpoint returning the tool manifest. Required.
	ManifestURL string
	// InvokeURL is the POST endpoint executing one tool call. Required.
	InvokeURL string
	// Timeout bounds one HTTP round-trip. Zero uses DefaultTimeout.
	Timeout time.Duration
	// MaxCallsPerSession hard-caps invokes per session ID. Zero uses
	// DefaultMaxCallsPerSession.
	MaxCallsPerSession int
	// HTTPClient overrides the transport (tests). Nil builds one from Timeout.
	HTTPClient *http.Client
	// Clock overrides the time source (tests). Nil uses time.Now.
	Clock func() time.Time
}

Options configures a Bridge.

type Session

type Session struct {
	ID         string
	Locale     string
	PersonaID  string
	Credential string
}

Session identifies one voice session towards the bridge. Credential is the opaque per-session secret forwarded as Authorization bearer; it must never be logged.

type ToolDefinition

type ToolDefinition struct {
	Name        string         `json:"name"`
	Description string         `json:"description,omitempty"`
	Parameters  map[string]any `json:"parameters,omitempty"`
	TimeoutMs   int            `json:"timeout_ms,omitempty"`
}

ToolDefinition is one manifest entry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL