Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions assistant/src/daemon/session-agent-loop.ts
Original file line number Diff line number Diff line change
Expand Up @@ -625,13 +625,10 @@ export async function runAgentLoopImpl(
}

if (isFirstMessage) {
void (async () => {
try {
await generateTitle(ctx, content, state.firstAssistantText, onEvent);
} catch (err) {
generateTitle(ctx, content, state.firstAssistantText, onEvent, abortController.signal)
.catch((err) => {
log.warn({ err, conversationId: ctx.conversationId }, 'Failed to generate conversation title (non-fatal, using default title)');
}
})();
});
}
} catch (err) {
const errorCtx = { phase: 'agent_loop' as const, aborted: abortController.signal.aborted };
Expand Down Expand Up @@ -712,13 +709,17 @@ async function generateTitle(
userMessage: string,
assistantResponse: string,
onEvent: (msg: ServerMessage) => void,
sessionSignal?: AbortSignal,
): Promise<void> {
const prompt = `Generate a very short title for this conversation. Rules: at most 5 words, at most 40 characters, no quotes.\n\nUser: ${truncate(userMessage, 200, '')}\nAssistant: ${truncate(assistantResponse, 200, '')}`;
const signal = sessionSignal
? AbortSignal.any([sessionSignal, AbortSignal.timeout(10_000)])
: AbortSignal.timeout(10_000);
const response = await ctx.provider.sendMessage(
[{ role: 'user', content: [{ type: 'text', text: prompt }] }],
[],
undefined,
{ config: { max_tokens: 30 } },
{ config: { max_tokens: 30 }, signal },
);

const textBlock = response.content.find((b) => b.type === 'text');
Expand Down