Documentation
¶
Overview ¶
Package a2a adapts a registered A2A agent to SpeechKit's cascaded voice pipeline. SpeechKit retains STT/TTS custody; the remote endpoint owns agent semantics, memory, tools and authorization.
Stability: Experimental — may change in any release.
Index ¶
- type Agent
- func (a *Agent) Run(ctx context.Context, input cascaded.AgentInput) (cascaded.AgentOutput, error)
- func (a *Agent) Stream(ctx context.Context, input cascaded.AgentInput, emit func(string) error) (cascaded.AgentOutput, error)
- func (a *Agent) StreamTurn(ctx context.Context, input cascaded.AgentInput, turnID string, ...) (cascaded.AgentOutput, error)
- type Config
- type FinalTurnBinding
- type HeaderProvider
- type OpenAIHandler
- type RequestContext
- type TurnError
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Agent ¶
type Agent struct {
// contains filtered or unexported fields
}
Agent implements cascaded.Agent by forwarding each utterance to a registered A2A agent and returning the text parts of its answer. Build it with New; it holds no per-turn state and is safe for concurrent use.
func New ¶
New validates config and returns an Agent. It fails when Endpoint is missing or not HTTPS (HTTP is allowed only on loopback), or when TargetAgentID or SessionID is blank.
func (*Agent) Run ¶
func (a *Agent) Run(ctx context.Context, input cascaded.AgentInput) (cascaded.AgentOutput, error)
Run sends one user turn as a JSON-RPC "message/stream" request and returns the agent's text answer with Action "display". It fails closed: a blank utterance, a HeaderProvider error (reported before any network call), a non-2xx status, a JSON-RPC error object (also inside an SSE stream; a *TurnError carrying the agent's typed reason), or an answer without text parts is an error. Streamed answers concatenate the text of every result event.
func (*Agent) Stream ¶ added in v0.75.5
func (a *Agent) Stream(ctx context.Context, input cascaded.AgentInput, emit func(string) error) (cascaded.AgentOutput, error)
Stream sends the same authorized turn as Run and emits each answer delta as it arrives. Returning an error from emit aborts the request without replay.
func (*Agent) StreamTurn ¶ added in v0.75.5
func (a *Agent) StreamTurn(ctx context.Context, input cascaded.AgentInput, turnID string, emit func(string) error) (cascaded.AgentOutput, error)
StreamTurn supplies the host's canonical native final-transcript identity. Empty keeps the historical generated request identity. The host must bind turnID to one observed final utterance and never replay uncertain execution.
type Config ¶
type Config struct {
// Endpoint is the agent's A2A JSON-RPC URL. It must use HTTPS; plain
// HTTP is accepted only for loopback hosts.
Endpoint string
// TargetAgentID names the registered agent; it is sent in the request
// metadata and in every [RequestContext].
TargetAgentID string
// SessionID is the A2A contextId every turn is sent under, so the
// remote agent can keep per-session memory.
SessionID string
// HTTPClient sends the turns; nil uses a client with a 60 s timeout.
HTTPClient *http.Client
// TurnTimeout bounds the complete request and streamed answer, including
// custom HTTP clients. Zero uses 60 seconds. Turns are never replayed.
TurnTimeout time.Duration
// Headers optionally mints per-turn headers; nil adds none.
Headers HeaderProvider
}
Config describes the registered A2A agent an Agent talks to. Endpoint, TargetAgentID and SessionID are required.
type FinalTurnBinding ¶ added in v0.75.5
type FinalTurnBinding struct {
// contains filtered or unexported fields
}
FinalTurnBinding assigns identities to host-observed native final transcripts. Vendor history is not an authority. A new identical utterance has a new sequence; a callback retry against the same final keeps its identity. Without a native event id, callbacks before a new identical final are ambiguous and must not be promoted to another privileged turn.
func NewFinalTurnBinding ¶ added in v0.75.5
func NewFinalTurnBinding(sessionID string) *FinalTurnBinding
NewFinalTurnBinding scopes native final transcript identities to one voice session.
func (*FinalTurnBinding) Observe ¶ added in v0.75.5
func (b *FinalTurnBinding) Observe(text, eventID string)
Observe records one native final. eventID, when supplied by the provider, deduplicates retransmitted finals. Empty uses the native ordered event stream.
type HeaderProvider ¶
HeaderProvider supplies per-turn headers. It is deliberately generic: a self-hosted deployment may use a bearer key while a hosted connector can mint a capability lease and signed delegation without exposing either to SpeechKit clients.
type OpenAIHandler ¶ added in v0.75.5
type OpenAIHandler struct {
Agent *Agent
Token string `json:"-"`
ExpiresAt time.Time
Locale string
// Context is the owning voice session. Its cancellation stops callbacks.
Context context.Context
// BindTurn resolves a callback against a host-observed native final
// transcript. When set, vendor history cannot create a new turn identity.
BindTurn func(context.Context, string) (string, error)
// Revalidate checks current host authority on every authenticated callback,
// before parsing, correlation or replay admission. Denial must revoke media.
Revalidate func(context.Context) error
// FirstResponsePrefix is trusted host disclosure, spoken once before the
// first successful answer starts. It is never supplied by the vendor.
FirstResponsePrefix string
// contains filtered or unexported fields
}
OpenAIHandler adapts a native voice provider's streamed chat-completions callback to one fixed registered Agent. Token is a session-scoped callback credential, never an owner login or provider key. The host owns its expiry and removes this handler on voice teardown. Vendor prompts, model selection, history and tools cannot change the bound agent or its durable session.
func NewOpenAIHandler ¶ added in v0.75.5
func NewOpenAIHandler(ctx context.Context, agent *Agent, token string, expiresAt time.Time, locale string) (*OpenAIHandler, error)
NewOpenAIHandler requires a bound agent, an opaque credential and a future expiry. The caller must generate at least 32 random bytes for token.
func (*OpenAIHandler) CancelTurn ¶ added in v0.75.5
func (h *OpenAIHandler) CancelTurn()
CancelTurn stops the current registered-agent request without revoking the voice session. Its admitted identity remains consumed, including uncertainty.
func (*OpenAIHandler) ResponsePending ¶ added in v0.75.5
func (h *OpenAIHandler) ResponsePending() bool
ResponsePending includes admission/correlation before the first answer delta.
func (*OpenAIHandler) ServeHTTP ¶ added in v0.75.5
func (h *OpenAIHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
type RequestContext ¶
RequestContext identifies the exact registered-agent turn for a header provider that mints short-lived authorization or a signed delegation.
type TurnError ¶ added in v0.74.2
type TurnError struct {
// contains filtered or unexported fields
}
TurnError is a streamed turn the agent answered with a JSON-RPC error. It implements cascaded.CodedError with an allowlisted public outcome.