slug エージェントが暴走するのを対処

This commit is contained in:
nrslib 2026-02-10 21:18:48 +09:00
parent d185039c73
commit eb32cf0138
5 changed files with 47 additions and 16 deletions

View File

@ -130,6 +130,7 @@ describe('template file existence', () => {
'score_interactive_policy', 'score_interactive_policy',
'score_summary_system_prompt', 'score_summary_system_prompt',
'score_slug_system_prompt', 'score_slug_system_prompt',
'score_slug_user_prompt',
'perform_phase1_message', 'perform_phase1_message',
'perform_phase2_message', 'perform_phase2_message',
'perform_phase3_message', 'perform_phase3_message',

View File

@ -57,20 +57,25 @@ describe('summarizeTaskName', () => {
timestamp: new Date(), timestamp: new Date(),
}); });
// When // When
const result = await summarizeTaskName('long task name for testing', { cwd: '/project' }); const result = await summarizeTaskName('long task name for testing', { cwd: '/project' });
// Then // Then
expect(result).toBe('add-auth'); expect(result).toBe('add-auth');
expect(mockGetProvider).toHaveBeenCalledWith('claude'); expect(mockGetProvider).toHaveBeenCalledWith('claude');
expect(mockProviderCall).toHaveBeenCalledWith( const callPrompt = mockProviderCall.mock.calls[0]?.[0];
'long task name for testing', expect(callPrompt).toContain('Generate a slug from the task description below.');
expect.objectContaining({ expect(callPrompt).toContain('<task_description>');
cwd: '/project', expect(callPrompt).toContain('long task name for testing');
allowedTools: [], expect(callPrompt).toContain('</task_description>');
}) expect(mockProviderCall).toHaveBeenCalledWith(
); expect.any(String),
}); expect.objectContaining({
cwd: '/project',
permissionMode: 'readonly',
})
);
});
it('should return AI-generated slug for English task name', async () => { it('should return AI-generated slug for English task name', async () => {
// Given // Given

View File

@ -70,10 +70,11 @@ export class TaskSummarizer {
name: 'summarizer', name: 'summarizer',
systemPrompt: loadTemplate('score_slug_system_prompt', 'en'), systemPrompt: loadTemplate('score_slug_system_prompt', 'en'),
}); });
const response = await agent.call(taskName, { const prompt = loadTemplate('score_slug_user_prompt', 'en', { taskDescription: taskName });
const response = await agent.call(prompt, {
cwd: options.cwd, cwd: options.cwd,
model, model,
allowedTools: [], permissionMode: 'readonly',
}); });
const slug = sanitizeSlug(response.content); const slug = sanitizeSlug(response.content);

View File

@ -0,0 +1,12 @@
<!--
template: score_slug_user_prompt
role: user prompt for task-name-to-slug generation
vars: taskDescription
caller: infra/task/summarize
-->
Generate a slug from the task description below.
Output ONLY the slug text.
<task_description>
{{taskDescription}}
</task_description>

View File

@ -0,0 +1,12 @@
<!--
template: score_slug_user_prompt
role: user prompt for task-name-to-slug generation
vars: taskDescription
caller: infra/task/summarize
-->
Generate a slug from the task description below.
Output ONLY the slug text.
<task_description>
{{taskDescription}}
</task_description>