Skip to content

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

feat(agent): add support for stored and pending attachments in queued turns

Steven Enamakel18506e22b951
diff --git a/crates/openhuman-core/src/agent/queued_turn.rs b/crates/openhuman-core/src/agent/queued_turn.rs
index 71835028ef..72cec4f3cb 100644
--- a/crates/openhuman-core/src/agent/queued_turn.rs
+++ b/crates/openhuman-core/src/agent/queued_turn.rs
@@ -7,6 +7,23 @@
use std::sync::Arc;
use tinyagents_harness::turn_runner::{QueueDisposition, RequeuePayload, ScopeKey, TurnRequest};
+/// Opaque attachment refs supplied for a user row that is already persisted.
+/// Paths and URLs are intentionally absent; the trusted turn resolves the
+/// parts again against the row and current dispatch scope before use.
+#[derive(Clone, Debug, Default)]
+pub(crate) struct StoredAttachmentInput {
+ pub(crate) persisted_message_id: String,
+ pub(crate) parts: Vec<tinychannels_bus::ContentPart>,
+}
+
+/// Opaque refs staged for a queued follow-up. The user row is persisted only
+/// when the turn is admitted, preserving transcript order behind the active
+/// assistant reply.
+#[derive(Clone, Debug, Default)]
+pub(crate) struct PendingAttachmentInput {
+ pub(crate) parts: Vec<tinychannels_bus::ContentPart>,
+}
+
/// The host metadata one OpenHuman turn carries through TinyAgents' turn
/// runner and its run queue: which client asked, the per-message model and
/// locale choices, and the context the turn runs under.
@@ -30,6 +47,8 @@ pub struct QueuedPayload {
/// Requeued placeholders inherit it from their running turn; public chat
/// metadata never supplies or overrides this value.
pub(crate) trusted_turn: Option<Arc<super::turn_host::TrustedAgentTurn>>,
+ pub(crate) stored_attachments: Option<StoredAttachmentInput>,
+ pub(crate) pending_attachments: Option<PendingAttachmentInput>,
}
impl std::fmt::Debug for QueuedPayload {
@@ -41,6 +60,8 @@ impl std::fmt::Debug for QueuedPayload {
.field("locale", &self.locale)
.field("queued_at_ms", &self.queued_at_ms)
.field("has_trusted_turn", &self.trusted_turn.is_some())
+ .field("has_stored_attachments", &self.stored_attachments.is_some())
+ .field("has_pending_attachments", &self.pending_attachments.is_some())
.finish_non_exhaustive()
}
}
@@ -60,6 +81,14 @@ impl RequeuePayload for QueuedPayload {
if self.trusted_turn.is_none() {
self.trusted_turn.clone_from(&running.trusted_turn);
}
+ if self.pending_attachments.is_none() {
+ self.pending_attachments
+ .clone_from(&running.pending_attachments);
+ }
+ if self.stored_attachments.is_none() {
+ self.stored_attachments
+ .clone_from(&running.stored_attachments);
+ }
if self.client_id.is_empty() {
self.client_id.clone_from(&running.client_id);
self.model_override.clone_from(&running.model_override);
diff --git a/crates/openhuman-core/src/web_chat/ops/start_chat.rs b/crates/openhuman-core/src/web_chat/ops/start_chat.rs
index 30782fc0e0..8bc96164a3 100644
--- a/crates/openhuman-core/src/web_chat/ops/start_chat.rs
+++ b/crates/openhuman-core/src/web_chat/ops/start_chat.rs
@@ -231,6 +231,34 @@ pub(super) fn start_chat_with_voice_note<'a>(
queue_mode: Option<String>,
metadata: ChatRequestMetadata,
voice_note_id: Option<String>,
+) -> futures::future::BoxFuture<'a, Result<String, StartChatError>> {
+ start_chat_with_stored_attachments(
+ ctx,
+ client_id,
+ thread_id,
+ message,
+ model_override,
+ temperature,
+ locale,
+ queue_mode,
+ metadata,
+ voice_note_id,
+ None,
+ )
+}
+
+pub(super) fn start_chat_with_stored_attachments<'a>(
+ ctx: &'a crate::core::runtime::DispatchCtx,
+ client_id: &'a str,
+ thread_id: &'a str,
+ message: &'a str,
+ model_override: Option<String>,
+ temperature: Option<f64>,
+ locale: Option<String>,
+ queue_mode: Option<String>,
+ metadata: ChatRequestMetadata,
+ voice_note_id: Option<String>,
+ stored_attachments: Option<crate::agent::queued_turn::StoredAttachmentInput>,
) -> futures::future::BoxFuture<'a, Result<String, StartChatError>> {
Box::pin(start_chat_inner(
ctx,
@@ -243,6 +271,7 @@ pub(super) fn start_chat_with_voice_note<'a>(
queue_mode,
metadata,
voice_note_id,
+ stored_attachments,
))
}
@@ -258,6 +287,7 @@ async fn start_chat_inner(
queue_mode: Option<String>,
metadata: ChatRequestMetadata,
voice_note_id: Option<String>,
+ stored_attachments: Option<crate::agent::queued_turn::StoredAttachmentInput>,
) -> Result<String, StartChatError> {
let client_id = client_id.trim().to_string();
let thread_id = thread_id.trim().to_string();
@@ -301,6 +331,7 @@ async fn start_chat_inner(
locale,
metadata,
queued_at_ms,
+ stored_attachments,
},
host_authored: false,
disposition: disposition(mode),