Skip to content
Python

First contact asks via ask_user; titles read the first reply

Rohit C Prasadeaba00184ed6
diff --git a/coworker/agent.py b/coworker/agent.py
index 5aa53ac3..c958a854 100644
--- a/coworker/agent.py
+++ b/coworker/agent.py
@@ -125,9 +125,11 @@ the previous line, and never let narration replace your final answer."""
_FIRST_CONTACT_GUIDANCE = """\
First contact: if the user's first message is a simple hello or open-ended ("hey", "what \
can you do?") rather than a task, don't just say hello back — say in one or two \
-sentences what you do in this role, then offer two or three concrete things you could \
-start on right now, phrased for this session's context (workspace, connected tools). \
-Keep it short and skip the pitch when the user already gave you a task."""
+sentences what you do in this role, then offer two or three concrete starting points as \
+an ask_user question (short option labels, phrased for this session's context — \
+workspace, connected tools — and leave the free-text answer available so the user can \
+type their own direction). A picked option is a clear brief: start on it. Keep it short \
+and skip all of this when the user already gave you a task."""
def _enabled_connector_tools(secrets: SecretStore) -> tuple[set[str], set[str]]:
diff --git a/coworker/server/manager.py b/coworker/server/manager.py
index 6fb22b3b..1486d906 100644
--- a/coworker/server/manager.py
+++ b/coworker/server/manager.py
@@ -5061,10 +5061,12 @@ class SessionManager:
# -- LLM auto-titles (FB-010) -------------------------------------------------
_AUTOTITLE_PROMPT = (
- "You title chat sessions. Given the user's opening message(s), reply with ONLY "
- "a 4-5 word title for the session — no quotes or punctuation wrapping it. If "
- 'the opening is merely a greeting or small-talk with no topic ("hey", '
- '"how are you", "hi there"), reply with exactly: small-talk'
+ "You title chat sessions. Given the user's opening message(s) — and, when "
+ "present, the assistant's first reply for context — reply with ONLY a 4-5 word "
+ "title for the session, named after what the session is actually about — no "
+ "quotes or punctuation wrapping it. If there is no topic at all ("
+ '"hey", "how are you", "hi there" and a generic reply), reply with exactly: '
+ "small-talk"
)
def _maybe_autotitle(self, session_id: str) -> None:
@@ -5082,7 +5084,11 @@ class SessionManager:
return
if self.task_store.task_for_run_session(session_id) is not None:
return # automation runs are titled by their task
- if self._autotitle_attempts.get(session_id, 0) >= 2:
+ # Three windows, not two (owner ruling 2026-08-24): opener-only at turn 1 start,
+ # opener+assistant-reply at turn 1 end (titles a "hey"-then-real-work session),
+ # and both-openers at turn 2 start. The signature guard makes each fire at most
+ # once; sessions with a meaty first message still title on attempt 1.
+ if self._autotitle_attempts.get(session_id, 0) >= 3:
return
users = [m for m in engine.messages if m.get("role") == "user"]
if not users:
@@ -5099,11 +5105,28 @@ class SessionManager:
][:2]
if not openers:
return
- # Same openers as the last attempt → nothing new to say; skip WITHOUT burning an
+ # The agent's first reply is fair evidence for a TITLE (unlike the reviewer,
+ # naming a session is not a security boundary — owner ruling 2026-08-24): it is
+ # what turns "hey" + a generic ask into "Semgrep security review".
+ assistant = next(
+ (
+ text
+ for m in engine.messages
+ if m.get("role") == "assistant"
+ and (
+ text := content_to_text(
+ m.get("content"), image_placeholder=""
+ ).strip()
+ )
+ ),
+ "",
+ )[:400]
+ # Same evidence as the last attempt → nothing new to say; skip WITHOUT burning an
# attempt (this is how the turn-start and turn-end triggers coexist).
- if self._autotitle_sig.get(session_id) == len(openers):
+ sig = (len(openers), bool(assistant))
+ if self._autotitle_sig.get(session_id) == sig:
return
- self._autotitle_sig[session_id] = len(openers)
+ self._autotitle_sig[session_id] = sig
self._autotitle_attempts[session_id] = (
self._autotitle_attempts.get(session_id, 0) + 1
)
@@ -5114,12 +5137,18 @@ class SessionManager:
self._autotitle_inflight.add(session_id)
# Retain the task: the loop holds only a weak ref, and a GC'd task would both
# kill the title mid-flight and strand the inflight guard.
- task = loop.create_task(self._generate_autotitle(session_id, engine, openers))
+ task = loop.create_task(
+ self._generate_autotitle(session_id, engine, openers, assistant)
+ )
self._autotitle_tasks.add(task)
task.add_done_callback(self._autotitle_tasks.discard)
async def _generate_autotitle(
- self, session_id: str, engine: TurnEngine, openers: list[str]
+ self,
+ session_id: str,
+ engine: TurnEngine,
+ openers: list[str],
+ assistant: str = "",
) -> None:
"""One cheap non-streaming completion on the session's own provider/model. Every
failure (provider error, empty, absurdly long) is swallowed — the title_from
@@ -5131,7 +5160,15 @@ class SessionManager:
model=engine.model,
messages=[
{"role": "system", "content": self._AUTOTITLE_PROMPT},
- {"role": "user", "content": "\n\n".join(openers)},
+ {
+ "role": "user",
+ "content": "\n\n".join(openers)
+ + (
+ f"\n\n[the assistant's first reply]\n{assistant}"
+ if assistant
+ else ""
+ ),
+ },
],
temperature=0.2,
# Reasoning-routed models spend hidden tokens BEFORE emitting text; a
diff --git a/tests/test_autotitle.py b/tests/test_autotitle.py
index 62ea02d0..a6929ae6 100644
--- a/tests/test_autotitle.py
+++ b/tests/test_autotitle.py
@@ -65,7 +65,10 @@ async def test_title_set_after_first_turn(tmp_path):
await _turn(mgr, "s1", "help me plan a trip to japan")
assert len(provider.title_calls) == 1
- assert provider.title_calls[0][-1]["content"] == "help me plan a trip to japan"
+ # The agent's first reply rides along as titling evidence (owner ruling 2026-08-24).
+ assert provider.title_calls[0][-1]["content"] == (
+ "help me plan a trip to japan\n\n[the assistant's first reply]\nsure"
+ )
assert mgr.session_store.title_state("s1")["auto_title"] == (
"Japan Trip Planning Help"
)