deepgram-go-voice-agent
bởi deepgram
Sử dụng khi viết hoặc xem xét mã Go trong repo này chạy một phiên Deepgram Voice Agent qua WebSockets, bao gồm cài đặt thời gian chạy, cập nhật lời nhắc, nói…
npx skills add https://github.com/deepgram/deepgram-go-sdk --skill deepgram-go-voice-agentUsing Deepgram Voice Agent from the Go SDK
When to use this product
Use this skill for live Voice Agent runtime flows in pkg/client/agent.
- open an agent WebSocket session
- send initial settings
- stream audio
- react to agent events and function-call messages
- update prompt/speak settings during the session
Use a different skill when:
- you only need STT (
deepgram-go-speech-to-text) - you only need TTS (
deepgram-go-text-to-speech) - you need management/admin endpoints (
deepgram-go-management-api)
Authentication
Set DEEPGRAM_API_KEY before opening the agent connection.
export DEEPGRAM_API_KEY="your_api_key"
Quick start
package main
import (
"context"
"fmt"
"log"
agentws "github.com/deepgram/deepgram-go-sdk/v3/pkg/api/agent/v1/websocket"
agent "github.com/deepgram/deepgram-go-sdk/v3/pkg/client/agent"
)
func main() {
if err := run(); err != nil {
log.Fatal(err)
}
}
func run() error {
ctx := context.Background()
settings := agent.NewSettingsConfigurationOptions()
handler := agentws.NewDefaultChanHandler()
conn, err := agent.NewWSUsingChanWithDefaults(ctx, settings, handler)
if err != nil {
return err
}
defer conn.Stop()
if ok := conn.Connect(); !ok {
return fmt.Errorf("connect failed")
}
conn.Start()
// The handler receives Welcome, ConversationText, FunctionCallRequest, and audio events.
// Stream audio frames, watch agent events, and respond to function calls as needed.
return nil
}
Key parameters
- constructors
agent.NewSettingsConfigurationOptions()agent.NewWSUsingChanWithDefaults(...)agent.NewWSUsingChan(...)
- runtime methods
Connect,Start,ProcessMessage,Stream,Write,KeepAlive- reconnect helpers like
AttemptReconnectand error handling helpers in the WS client
- message and event payloads in
pkg/api/agent/v1/websocket/interfaces/types.goUpdatePromptUpdateSpeakInjectAgentMessageInjectUserMessageFunctionCallResponse- server events such as
WelcomeResponse,ConversationTextResponse,FunctionCallRequestResponse,AgentStartedSpeakingResponse,AgentAudioDoneResponse
API reference (layered)
- In-repo reference
README.mdpkg/client/agent/client.gopkg/client/agent/v1/websocket/client_channel.gopkg/client/agent/v1/websocket/new_using_chan.gopkg/client/interfaces/v1/types-agent.gopkg/api/agent/v1/websocket/interfaces/types.go
- OpenAPI
https://developers.deepgram.com/openapi.yaml
- AsyncAPI
https://developers.deepgram.com/asyncapi.yaml
- Context7
/llmstxt/developers_deepgram_llms_txt
- Product docs
https://developers.deepgram.com/reference/voice-agent/voice-agenthttps://developers.deepgram.com/docs/voice-agenthttps://developers.deepgram.com/docs/configure-voice-agenthttps://developers.deepgram.com/docs/voice-agent-message-flow
Gotchas
- This repo exposes live Voice Agent runtime over WebSockets, not a persisted configuration-management surface.
- Keep audio streaming, event handling, and any function-call response loop running concurrently.
- Follow the example session setup instead of inventing your own event names; the repo already defines concrete message structs.
- Channel-based constructors require an
AgentMessageChanhandler; events are routed there rather than pulled from the client. - Use
defer conn.Stop(), and remember thatConnect()returnsboolrather thanerror.
Example files in this repo
examples/agent/websocket/simple/main.goexamples/agent/websocket/no_mic/main.goexamples/agent/websocket/arbitrary_keys/main.gotests/unit_test/agent/agent_speak_test.go
Central product skills
For cross-language Deepgram product knowledge — the consolidated API reference, documentation finder, focused runnable recipes, third-party integration examples, and MCP setup — install the central skills:
npx skills add deepgram/skills
This SDK ships language-idiomatic code skills; deepgram/skills ships cross-language product knowledge (see api, docs, recipes, examples, starters, setup-mcp).