Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(config): add voice channel configuration schema

Steven Enamakelc5d6d3c81422
diff --git a/crates/openhuman-core/src/config/schema/README.md b/crates/openhuman-core/src/config/schema/README.md
index 1812df7c32..9ca667e477 100644
--- a/crates/openhuman-core/src/config/schema/README.md
+++ b/crates/openhuman-core/src/config/schema/README.md
@@ -26,6 +26,7 @@ is mounted as a submodule of [`load/dirs.rs`](./load/dirs.rs) via `#[path]`.
| `[context]` | [`context.rs`](./context.rs) | `ContextConfig` |
| `[cost]` | [`identity_cost.rs`](./identity_cost.rs) | `CostConfig`, `ModelPricing` |
| `[dashboard]` | [`dashboard.rs`](./dashboard.rs) | `DashboardConfig`, `DiagramViewerConfig`, `EventStreamConfig`, `ModelHealthConfig` |
+| `[channel_voice]` | [`channel_voice.rs`](./channel_voice.rs) | `ChannelVoiceConfig`, `ChannelVoiceOverride`, `VoiceReplyMode` |
| `[dictation]` | [`dictation.rs`](./dictation.rs) | `DictationConfig`, `DictationActivationMode` |
| `[ephemeral_route]` | [`ephemeral_route.rs`](./ephemeral_route.rs) | `EphemeralRoute` |
| `[cron]` | [`cron.rs`](./cron.rs) | `CronConfig` |
diff --git a/crates/openhuman-core/src/config/schema/channel_voice.rs b/crates/openhuman-core/src/config/schema/channel_voice.rs
new file mode 100644
index 0000000000..57c18f0e84
--- /dev/null
+++ b/crates/openhuman-core/src/config/schema/channel_voice.rs
@@ -0,0 +1,90 @@
+//! Spoken-reply policy for channels (`[channel_voice]`).
+//!
+//! The host resolves one [`VoiceReplyMode`] per turn: a per-thread override
+//! wins over a per-channel override, which wins over the global default.
+
+use schemars::JsonSchema;
+use serde::{Deserialize, Serialize};
+use std::collections::BTreeMap;
+
+/// When a channel reply is also spoken.
+#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, JsonSchema, PartialEq, Eq)]
+#[serde(rename_all = "snake_case")]
+pub enum VoiceReplyMode {
+ /// Speak only when the inbound message was a voice note.
+ #[default]
+ Mirror,
+ /// Always speak the reply.
+ Always,
+ /// Never speak the reply.
+ Never,
+ /// Speak only when the request explicitly asked for a spoken reply.
+ SpeakReply,
+}
+
+/// Per-channel overrides; unset fields inherit the global value.
+#[derive(Debug, Clone, Default, Serialize, Deserialize, JsonSchema, PartialEq)]
+#[serde(default)]
+pub struct ChannelVoiceOverride {
+ pub reply_mode: Option<VoiceReplyMode>,
+ pub voice: Option<String>,
+ pub max_outbound_secs: Option<u32>,
+}
+
+#[derive(Debug, Clone, Serialize, Deserialize, JsonSchema, PartialEq)]
+#[serde(default)]
+pub struct ChannelVoiceConfig {
+ /// Global reply mode.
+ pub reply_mode: VoiceReplyMode,
+ /// Default synthesis voice; `None` uses the backend default.
+ pub voice: Option<String>,
+ /// Longest spoken reply the host will synthesize, in seconds.
+ pub max_outbound_secs: u32,
+ /// Overrides keyed by channel name (for example `telegram`).
+ pub channels: BTreeMap<String, ChannelVoiceOverride>,
+ /// Reply-mode overrides keyed by conversation (thread) id.
+ pub threads: BTreeMap<String, VoiceReplyMode>,
+}
+
+impl Default for ChannelVoiceConfig {
+ fn default() -> Self {
+ Self {
+ reply_mode: VoiceReplyMode::Mirror,
+ voice: None,
+ max_outbound_secs: 120,
+ channels: BTreeMap::new(),
+ threads: BTreeMap::new(),
+ }
+ }
+}
+
+impl ChannelVoiceConfig {
+ /// Thread override, then channel override, then the global mode.
+ pub fn resolve_mode(&self, channel: &str, thread: &str) -> VoiceReplyMode {
+ self.threads
+ .get(thread)
+ .copied()
+ .or_else(|| self.channels.get(channel).and_then(|c| c.reply_mode))
+ .unwrap_or(self.reply_mode)
+ }
+
+ /// Channel voice, falling back to the global voice.
+ pub fn resolve_voice(&self, channel: &str) -> Option<&str> {
+ self.channels
+ .get(channel)
+ .and_then(|c| c.voice.as_deref())
+ .or(self.voice.as_deref())
+ }
+
+ /// Channel outbound cap, falling back to the global cap.
+ pub fn resolve_max_outbound_secs(&self, channel: &str) -> u32 {
+ self.channels
+ .get(channel)
+ .and_then(|c| c.max_outbound_secs)
+ .unwrap_or(self.max_outbound_secs)
+ }
+}
+
+#[cfg(test)]
+#[path = "channel_voice_tests.rs"]
+mod tests;
diff --git a/crates/openhuman-core/src/config/schema/channel_voice_tests.rs b/crates/openhuman-core/src/config/schema/channel_voice_tests.rs
new file mode 100644
index 0000000000..5f2dc33329
--- /dev/null
+++ b/crates/openhuman-core/src/config/schema/channel_voice_tests.rs
@@ -0,0 +1,53 @@
+use super::*;
+
+fn config() -> ChannelVoiceConfig {
+ let mut cfg = ChannelVoiceConfig::default();
+ cfg.channels.insert(
+ "telegram".into(),
+ ChannelVoiceOverride {
+ reply_mode: Some(VoiceReplyMode::Always),
+ voice: Some("nova".into()),
+ max_outbound_secs: Some(30),
+ },
+ );
+ cfg.threads.insert("t-1".into(), VoiceReplyMode::Never);
+ cfg
+}
+
+#[test]
+fn default_mode_is_mirror() {
+ let cfg = ChannelVoiceConfig::default();
+ assert_eq!(cfg.resolve_mode("slack", "x"), VoiceReplyMode::Mirror);
+ assert_eq!(cfg.max_outbound_secs, 120);
+}
+
+#[test]
+fn channel_override_beats_global() {
+ assert_eq!(config().resolve_mode("telegram", "other"), VoiceReplyMode::Always);
+}
+
+#[test]
+fn thread_override_beats_channel() {
+ assert_eq!(config().resolve_mode("telegram", "t-1"), VoiceReplyMode::Never);
+}
+
+#[test]
+fn voice_and_cap_fall_back_to_global() {
+ let mut cfg = config();
+ cfg.voice = Some("alloy".into());
+ assert_eq!(cfg.resolve_voice("telegram"), Some("nova"));
+ assert_eq!(cfg.resolve_voice("slack"), Some("alloy"));
+ assert_eq!(cfg.resolve_max_outbound_secs("telegram"), 30);
+ assert_eq!(cfg.resolve_max_outbound_secs("slack"), 120);
+}
+
+#[test]
+fn parses_from_toml() {
+ let cfg: ChannelVoiceConfig = toml::from_str(
+ "reply_mode = \"never\"\n[channels.telegram]\nreply_mode = \"speak_reply\"\n[threads]\nabc = \"always\"\n",
+ )
+ .unwrap();
+ assert_eq!(cfg.resolve_mode("slack", "z"), VoiceReplyMode::Never);
+ assert_eq!(cfg.resolve_mode("telegram", "z"), VoiceReplyMode::SpeakReply);
+ assert_eq!(cfg.resolve_mode("telegram", "abc"), VoiceReplyMode::Always);
+}
diff --git a/crates/openhuman-core/src/config/schema/mod.rs b/crates/openhuman-core/src/config/schema/mod.rs
index e315760604..6637244fd4 100644
--- a/crates/openhuman-core/src/config/schema/mod.rs
+++ b/crates/openhuman-core/src/config/schema/mod.rs
@@ -21,6 +21,7 @@ mod dashboard;
mod desktop;
pub use desktop::DesktopConfig;
mod defaults;
+mod channel_voice;
mod dictation;
mod hooks;
pub use hooks::HooksConfig;
@@ -90,6 +91,7 @@ pub(crate) use cli_overrides::set_cli_inference_overrides;
pub use context::{CompactionSettings, CompactionStrategy, ContextConfig};
pub use cron::CronConfig;
pub use dashboard::{DashboardConfig, DiagramViewerConfig, EventStreamConfig, ModelHealthConfig};
+pub use channel_voice::{ChannelVoiceConfig, ChannelVoiceOverride, VoiceReplyMode};
pub use dictation::{DictationActivationMode, DictationConfig};
pub use identity_cost::{
BudgetAction, BudgetPeriod, BudgetPolicy, BudgetScope, CostConfig, ModelPricing,
diff --git a/crates/openhuman-core/src/config/schema/types/config.rs b/crates/openhuman-core/src/config/schema/types/config.rs
index f90c4929cc..56cdd026ee 100644
--- a/crates/openhuman-core/src/config/schema/types/config.rs
+++ b/crates/openhuman-core/src/config/schema/types/config.rs
@@ -484,6 +484,10 @@ pub struct Config {
#[serde(default)]
pub dictation: DictationConfig,
+ /// Spoken-reply policy for channels (`[channel_voice]`).
+ #[serde(default)]
+ pub channel_voice: ChannelVoiceConfig,
+
/// Whether the user has completed the **React UI** onboarding flow.
///
/// Set by `OnboardingOverlay.tsx::handleDone` and the multi-step
diff --git a/crates/openhuman-core/src/config/schema/types/config_clone.rs b/crates/openhuman-core/src/config/schema/types/config_clone.rs
index bb25e363c6..30cc86a1f0 100644
--- a/crates/openhuman-core/src/config/schema/types/config_clone.rs
+++ b/crates/openhuman-core/src/config/schema/types/config_clone.rs
@@ -102,6 +102,7 @@ impl Clone for Config {
integrations: self.integrations.clone(),
update: self.update.clone(),
dictation: self.dictation.clone(),
+ channel_voice: self.channel_voice.clone(),
onboarding_completed: self.onboarding_completed,
chat_onboarding_completed: self.chat_onboarding_completed,
model_registry: self.model_registry.clone(),
diff --git a/crates/openhuman-core/src/config/schema/types/defaults.rs b/crates/openhuman-core/src/config/schema/types/defaults.rs
index 61279ec7cf..fe1b8c536b 100644
--- a/crates/openhuman-core/src/config/schema/types/defaults.rs
+++ b/crates/openhuman-core/src/config/schema/types/defaults.rs
@@ -115,6 +115,7 @@ impl Default for Config {
integrations: IntegrationsConfig::default(),
update: UpdateConfig::default(),
dictation: DictationConfig::default(),
+ channel_voice: ChannelVoiceConfig::default(),
onboarding_completed: false,
chat_onboarding_completed: false,
model_registry: Vec::new(),