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 ¶
- Variables
- type Agent
- func (a *Agent) Run(ctx context.Context, input cascaded.AgentInput) (cascaded.AgentOutput, error)
- func (a *Agent) SetVoiceMode(ctx context.Context, mode, requestID string) 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 ConversationCapability
- type ConversationSession
- type FinalTurnBinding
- type HeaderProvider
- type OpenAIHandler
- type RequestContext
- type SessionProjection
- type TurnError
- type TurnStreamer
- type VoiceModeCommand
- type VoiceModeReceipt
Constants ¶
This section is empty.
Variables ¶
var ErrConversationBusy = errors.New("speechkit a2a: voice turn already running")
var ErrConversationUnsupported = errors.New("speechkit a2a: conversation command unsupported")
ErrConversationBusy proves that no mode command was dispatched. It is not an uncertain failure and must never force an existing voice mode to stop. ErrConversationUnsupported proves no command could be dispatched.
var ErrTurnRejected = errors.New("speechkit a2a: native turn rejected")
ErrTurnRejected is returned by OpenAIHandler.Answer when the turn is not admitted: expired or revoked authority, a turn already in flight, failed revalidation, or an utterance that does not bind to a host-observed final.
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) SetVoiceMode ¶ added in v0.77.7
SetVoiceMode invokes the ordinary agent-owned control without synthetic speech.
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
// Conversation is an optional host-bound capability; the remote agent's
// ordinary tool loop owns mode changes and canonical history selection.
Conversation *ConversationSession
}
Config describes the registered A2A agent an Agent talks to. Endpoint, TargetAgentID and SessionID are required.
type ConversationCapability ¶ added in v0.77.7
type ConversationCapability struct {
Version int `json:"version"`
Mode string `json:"mode"`
VoiceSessionID string `json:"voice_session_id"`
ConversationSessionID string `json:"conversation_session_id"`
OneShotSessionID string `json:"oneshot_session_id"`
}
ConversationCapability is a host-bound control surface for this voice lifetime. It is carried in the signed A2A turn, never in provider prompts.
type ConversationSession ¶ added in v0.77.7
type ConversationSession struct {
// contains filtered or unexported fields
}
ConversationSession retains the agent-issued session switch for subsequent turns. Delivery must complete before the assistant can speak its tool result.
func NewConversationSession ¶ added in v0.77.7
func NewConversationSession(capability ConversationCapability, deliver func(context.Context, VoiceModeReceipt) error) (*ConversationSession, error)
NewConversationSession creates an opt-in, voice-lifetime-scoped control.
func (*ConversationSession) Snapshot ¶ added in v0.77.7
func (s *ConversationSession) Snapshot() ConversationCapability
Snapshot returns the current signed turn metadata and history binding.
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 TurnStreamer
Model string
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 TurnStreamer, 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) Answer ¶ added in v0.76.7
Answer runs one turn in-process for native providers whose tool call or delegation event (instead of an HTTP chat-completions callback) asks the bound agent. It applies the same admission, revalidation, final-turn binding, replay protection and disclosure as ServeHTTP and returns the agent's complete answer. A failed agent turn is returned as an error and never as speakable text.
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 SessionProjection ¶ added in v0.77.7
SessionProjection reports whether the canonical session owner has linked this conversation to its actual project/environment; canonical history is separate.
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.
type TurnStreamer ¶ added in v0.75.8
type TurnStreamer interface {
StreamTurn(context.Context, cascaded.AgentInput, string, func(string) error) (cascaded.AgentOutput, error)
}
TurnStreamer is the existing host-observed native turn boundary. An endpoint adapter can reuse the callback lifecycle without inventing an agent identity.
type VoiceModeCommand ¶ added in v0.77.7
type VoiceModeCommand struct {
Command string `json:"command"`
Mode string `json:"mode"`
RequestID string `json:"request_id"`
}
VoiceModeCommand is a panel's typed invocation of the same agent-owned command.
type VoiceModeReceipt ¶ added in v0.77.7
type VoiceModeReceipt struct {
Version int `json:"version"`
Mode string `json:"mode"`
VoiceSessionID string `json:"voice_session_id"`
ConversationSessionID string `json:"conversation_session_id"`
RequestID string `json:"request_id"`
Status string `json:"status"`
Code string `json:"code,omitempty"`
SessionProjection *SessionProjection `json:"session_projection,omitempty"`
}
VoiceModeReceipt is emitted only by the selected agent's ordinary tool loop. ConversationSessionID identifies the owner-authorized canonical history.