Commit 32e4928
committed
feat(agent): add WebSocket connection layer
Adds the Agent sub-client, AgentHandle, AgentEventStream, and
AgentEvent types that connect to wss://agent.deepgram.com/v1/agent/converse
and tie together the message and response types from prior commits.
Surface:
- Deepgram::agent() returns Agent<'_>; Agent::start() opens a session
and returns (AgentHandle, AgentEventStream).
- AgentHandle exposes send_settings/send_update_speak/send_update_think/
send_update_prompt/send_inject_user_message/send_inject_agent_message/
send_function_call_response for JSON messages, send_data for binary
audio frames, and keep_alive/close for control. Method naming
follows the existing FluxHandle convention (send_data for audio,
plain verbs for control), with send_<message_type> for the typed
JSON sends.
- AgentEvent::Json(AgentResponse) | Audio(Bytes) is the unified
stream item type — JSON events and audio frames are interleaved
in their natural ordering. Matches the Python and JS SDKs.
Connection details:
- URL is a hardcoded constant (wss://agent.deepgram.com/v1/agent/converse).
Self-hosted agent support is on the 0.10.0 roadmap; for now this
is fixed.
- Auth uses the Deepgram client's auth method (Token X / Bearer X).
- dg-request-id from the upgrade response is parsed when present;
falls back to the server's Welcome event when absent.
Plumbing:
- The agent feature now pulls in tungstenite + tokio-tungstenite
(shared with listen).
- WsError, TungsteniteError, and the From<TungsteniteError> impl are
extended from cfg(feature = "listen") to
cfg(any(feature = "listen", feature = "agent")) so agent works
standalone.
- auth field's allow-unused extended to cover agent; base_url and
client stay listen-gated since agent doesn't use them today.
128 tests pass (3 new), doctest in the module example compiles.
Examples and an integration test against a mock server follow in
subsequent commits.1 parent d76efd7 commit 32e4928
4 files changed
Lines changed: 549 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
59 | 59 | | |
60 | 60 | | |
61 | 61 | | |
62 | | - | |
| 62 | + | |
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
30 | 33 | | |
31 | 34 | | |
32 | | - | |
33 | | - | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
34 | 38 | | |
35 | 39 | | |
36 | 40 | | |
| |||
42 | 46 | | |
43 | 47 | | |
44 | 48 | | |
| 49 | + | |
45 | 50 | | |
46 | 51 | | |
47 | 52 | | |
| |||
77 | 82 | | |
78 | 83 | | |
79 | 84 | | |
| 85 | + | |
0 commit comments