Skip to content

Commit 5d4d4f6

Browse files
committed
feat(agent): add server→client AgentResponse enum
Adds the full server-emitted JSON event surface for the Voice Agent WebSocket (16 typed variants plus an Unknown(serde_json::Value) catch-all for forward compatibility). Variants mirror AgentV1*Event in api/specs/asyncapi/schemas/agent/schemas.agent.v1.yml: - Welcome (request_id) - SettingsApplied - ConversationText (role, content, +languages/languages_hinted on user-role messages with flux-general-multi) - UserStartedSpeaking - AgentThinking (content) - FunctionCallRequest (functions[]: id, name, arguments, client_side, thought_signature?) - AgentStartedSpeaking (total/tts/ttt latency floats; experimental) - AgentAudioDone - Error / Warning (description, code) - History (reuses HistoryMessage — same wire shape as agent.context.messages[]) - PromptUpdated, SpeakUpdated, ThinkUpdated - InjectionRefused (message) - FunctionCallResponse (reuses the bidirectional FunctionCallResponseMessage from messages.rs) Wire dispatch follows the same #[serde(untagged)] + per-variant marker enum pattern as ClientMessage. Unknown is the tail variant so any unrecognized server message round-trips its raw JSON instead of failing deserialization — matches the FluxResponse forward-compat strategy. Audio frames sent by the server are binary WebSocket frames and are not part of this enum; they'll be delivered out-of-band by the connection layer when that surface lands. 21 new round-trip serde tests, 125 passing across the agent module.
1 parent 5ac6a2d commit 5d4d4f6

2 files changed

Lines changed: 769 additions & 2 deletions

File tree

src/agent/mod.rs

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,25 @@
2020
//! (`UpdateSpeak`, `UpdateThink`, `UpdatePrompt`, `InjectUserMessage`,
2121
//! `InjectAgentMessage`, `FunctionCallResponse`, `KeepAlive`) plus the
2222
//! `ClientMessage` discriminated union over all eight.
23+
//! - [`response`] — every server-emitted JSON event (`Welcome`,
24+
//! `SettingsApplied`, `ConversationText`, `UserStartedSpeaking`,
25+
//! `AgentThinking`, `FunctionCallRequest`, `AgentStartedSpeaking`,
26+
//! `AgentAudioDone`, `Error`, `Warning`, `History`, `PromptUpdated`,
27+
//! `SpeakUpdated`, `ThinkUpdated`, `InjectionRefused`,
28+
//! `FunctionCallResponse`) plus an `Unknown` catch-all for forward
29+
//! compatibility, all unified under the [`response::AgentResponse`] enum.
2330
//!
2431
//! Wire format matches the AsyncAPI schemas in `deepgram-docs` under
25-
//! `api/specs/asyncapi/schemas/agent/`. The server-to-client event
26-
//! enum and the WebSocket connection helpers land in subsequent commits.
32+
//! `api/specs/asyncapi/schemas/agent/`. The WebSocket connection helpers
33+
//! (builder, handle, stream) land in subsequent commits.
2734
2835
pub mod audio;
2936
pub mod aws_credentials;
3037
pub mod endpoint;
3138
pub mod history;
3239
pub mod listen;
3340
pub mod messages;
41+
pub mod response;
3442
pub mod settings;
3543
pub mod speak;
3644
pub mod think;
@@ -54,6 +62,15 @@ pub use messages::{
5462
InjectUserMessageType, KeepAliveMessage, KeepAliveType, UpdatePromptMessage, UpdatePromptType,
5563
UpdateSpeakMessage, UpdateSpeakType, UpdateThinkMessage, UpdateThinkType,
5664
};
65+
pub use response::{
66+
AgentAudioDoneEvent, AgentAudioDoneType, AgentFunctionCall, AgentResponse,
67+
AgentStartedSpeakingEvent, AgentStartedSpeakingType, AgentThinkingEvent, AgentThinkingType,
68+
ConversationTextEvent, ConversationTextType, ErrorEvent, ErrorType, FunctionCallRequestEvent,
69+
FunctionCallRequestType, InjectionRefusedEvent, InjectionRefusedType, PromptUpdatedEvent,
70+
PromptUpdatedType, SettingsAppliedEvent, SettingsAppliedType, SpeakUpdatedEvent,
71+
SpeakUpdatedType, ThinkUpdatedEvent, ThinkUpdatedType, UserStartedSpeakingEvent,
72+
UserStartedSpeakingType, WarningEvent, WarningType, WelcomeEvent, WelcomeType,
73+
};
5774
pub use settings::{
5875
AgentConfig, AgentContext, InlineAgentConfig, SettingsFlags, SettingsMessage,
5976
SettingsMessageType,

0 commit comments

Comments
 (0)