Skip to content

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

feat(threads): generate thread titles from first message

Steven Enamakela2c2cb087c95
diff --git a/crates/openhuman-core/src/threads/ops/title_generation.rs b/crates/openhuman-core/src/threads/ops/title_generation.rs
index bd307d2ae8..c9c1925325 100644
--- a/crates/openhuman-core/src/threads/ops/title_generation.rs
+++ b/crates/openhuman-core/src/threads/ops/title_generation.rs
@@ -13,9 +13,27 @@ use crate::threads::{
};
use tinyagents_harness::title::{
build_title_request, is_auto_generated_thread_title, sanitize_generated_title,
- title_log_fingerprint,
+ title_from_user_message, title_log_fingerprint,
};
+/// Whether the summarizer may replace `title`.
+///
+/// Two titles are ours to replace: the creation placeholder (`Chat Oct 6 …`)
+/// and the interim title derived from the first user message. The interim one
+/// is written the moment the user sends — before any reply exists to summarize
+/// — so without this the real summary that runs on the finished reply found a
+/// non-placeholder title and never ran. Anything else was typed by the user
+/// and is left alone. A user who renames a thread to exactly the interim title
+/// gets it summarized once more, which is harmless.
+pub(crate) fn is_replaceable_title(title: &str, first_user_message: Option<&str>) -> bool {
+ if is_auto_generated_thread_title(title) {
+ return true;
+ }
+ first_user_message
+ .and_then(title_from_user_message)
+ .is_some_and(|interim| interim == title.trim())
+}
+
/// Generates a durable thread title from the first user message and assistant reply.
pub async fn thread_generate_title(
request: GenerateConversationThreadTitleRequest,
@@ -32,12 +50,19 @@ pub async fn thread_generate_title(
return Err(ThreadsError::not_found(request.thread_id));
};
- if !is_auto_generated_thread_title(&thread.title) {
+ let messages =
+ conversations::blocking::get_messages(dir.clone(), request.thread_id.clone()).await?;
+ let first_user_message = messages
+ .iter()
+ .find(|message| message.sender == "user" && !message.content.trim().is_empty())
+ .map(|message| message.content.trim().to_string());
+
+ if !is_replaceable_title(&thread.title, first_user_message.as_deref()) {
tracing::debug!(
thread_id = %request.thread_id,
title_len = thread.title.chars().count(),
title_hash = %title_log_fingerprint(&thread.title),
- "{THREAD_TITLE_LOG_PREFIX} skipping non-placeholder title"
+ "{THREAD_TITLE_LOG_PREFIX} skipping user-chosen title"
);
return Ok(envelope(
thread_to_summary(thread),
@@ -46,13 +71,7 @@ pub async fn thread_generate_title(
));
}
- let messages =
- conversations::blocking::get_messages(dir.clone(), request.thread_id.clone()).await?;
- let Some(first_user_message) = messages
- .iter()
- .find(|message| message.sender == "user" && !message.content.trim().is_empty())
- .map(|message| message.content.trim().to_string())
- else {
+ let Some(first_user_message) = first_user_message else {
tracing::debug!(
thread_id = %request.thread_id,
"{THREAD_TITLE_LOG_PREFIX} no user message yet; skipping"