Skip to content

Commit 45d8e98

Browse files
authored
update default investigation name with auto LLM generated name (#256)
Signed-off-by: Hailong Cui <[email protected]>
1 parent fae8d7d commit 45d8e98

File tree

6 files changed

+51
-6
lines changed

6 files changed

+51
-6
lines changed

common/constants/notebooks.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,5 @@ export const NOTEBOOK_APP_NAME = 'investigate-notebook';
3030
export const OBSERVABILITY_VISUALIZATION_TYPE = 'observability-visualization';
3131

3232
export const DASHBOARDS_VISUALIZATION_TYPE = 'visualization';
33+
34+
export const DEFAULT_INVESTIGATION_NAME = 'Discover investigation';

common/types/notebooks.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,7 @@ export interface PERAgentHypothesisItem {
159159
export interface PERAgentInvestigationResponse {
160160
findings: PERAgentHypothesisFinding[];
161161
hypotheses: PERAgentHypothesisItem[];
162+
investigationName?: string;
162163
}
163164

164165
export interface NotebookComponentProps {

public/components/notebooks/components/discover_explorer/__tests__/start_investigation_modal.test.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,10 @@ import {
1313
httpServiceMock,
1414
notificationServiceMock,
1515
} from '../../../../../../../../src/core/public/mocks';
16-
import { NOTEBOOKS_API_PREFIX } from '../../../../../../common/constants/notebooks';
16+
import {
17+
DEFAULT_INVESTIGATION_NAME,
18+
NOTEBOOKS_API_PREFIX,
19+
} from '../../../../../../common/constants/notebooks';
1720

1821
describe('<StartInvestigationModal /> spec', () => {
1922
const httpMock = httpServiceMock.createStartContract();
@@ -134,7 +137,7 @@ describe('<StartInvestigationModal /> spec', () => {
134137
expect(httpMock.post).toHaveBeenCalledWith(
135138
`${NOTEBOOKS_API_PREFIX}/note/savedNotebook`,
136139
expect.objectContaining({
137-
body: expect.stringContaining('Discover investigation'),
140+
body: expect.stringContaining(DEFAULT_INVESTIGATION_NAME),
138141
})
139142
);
140143
});

public/components/notebooks/components/discover_explorer/start_investigation_modal.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ import {
2323
import React, { useState, useMemo } from 'react';
2424
import { useOpenSearchDashboards } from '../../../../../../../src/plugins/opensearch_dashboards_react/public';
2525
import type { NoteBookServices } from '../../../../types';
26-
import { NOTEBOOKS_API_PREFIX } from '../../../../../common/constants/notebooks';
26+
import {
27+
DEFAULT_INVESTIGATION_NAME,
28+
NOTEBOOKS_API_PREFIX,
29+
} from '../../../../../common/constants/notebooks';
2730

2831
const suggestedActions = [
2932
{
@@ -116,7 +119,7 @@ export const StartInvestigationModal = ({ log, closeModal }: StartInvestigationM
116119
}
117120
setDisabled(true);
118121
try {
119-
const id = await createNotebook('Discover investigation');
122+
const id = await createNotebook(DEFAULT_INVESTIGATION_NAME);
120123
const path = `#/agentic/${id}`;
121124
application.navigateToApp('investigation-notebooks', {
122125
path,

public/hooks/use_investigation.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { AgenticMemeory, PERAgentInvestigationResponse } from '../../common/type
2525
import { isValidPERAgentInvestigationResponse } from '../../common/utils/per_agent';
2626
import { useNotebook } from './use_notebook';
2727
import { generateContextPromptFromParagraphs } from '../services/helpers/per_agent';
28+
import { DEFAULT_INVESTIGATION_NAME, NOTEBOOKS_API_PREFIX } from '../../common/constants/notebooks';
2829

2930
const getFindingFromParagraph = (paragraph: ParagraphStateValue<unknown>) => {
3031
return `
@@ -144,6 +145,34 @@ ${finding.evidence}
144145
[updateHypotheses, batchCreateParagraphs, batchRunParagraphs]
145146
);
146147

148+
/**
149+
* Update investigation title based on the suggested title from the agent only if investigation use the default value
150+
*/
151+
const updateInvestigationName = useCallback(
152+
async (suggestedName: string) => {
153+
const isDefaultName = contextStateValue?.title === DEFAULT_INVESTIGATION_NAME;
154+
if (isDefaultName && suggestedName) {
155+
try {
156+
const autoGeneratedName = suggestedName.substring(0, 50);
157+
const { id: openedNoteId } = context.state.value;
158+
await http.put(`${NOTEBOOKS_API_PREFIX}/note/savedNotebook/rename`, {
159+
body: JSON.stringify({
160+
name: autoGeneratedName,
161+
noteId: openedNoteId,
162+
}),
163+
});
164+
165+
// Update local state to reflect invesitgation header
166+
context.state.updateValue({ title: autoGeneratedName, path: autoGeneratedName });
167+
} catch (error) {
168+
// Don't fail the entire investigation if title update fails
169+
console.error('Failed to update investigation title:', error);
170+
}
171+
}
172+
},
173+
[contextStateValue?.title, context.state, http]
174+
);
175+
147176
/**
148177
* Poll for investigation completion and process the response
149178
* @returns Promise that resolves when investigation is complete or rejects on error
@@ -219,6 +248,11 @@ ${finding.evidence}
219248
throw error;
220249
}
221250

251+
// Update notebook title if suggested_title is provided and name is default investigation name
252+
if (responseJson.investigationName) {
253+
await updateInvestigationName(responseJson.investigationName);
254+
}
255+
222256
context.state.updateValue({
223257
historyMemory: runningMemory,
224258
investigationError: undefined,
@@ -253,6 +287,7 @@ ${finding.evidence}
253287
notifications,
254288
context.state,
255289
storeInvestigationResponse,
290+
updateInvestigationName,
256291
updateHypotheses,
257292
batchDeleteParagraphs,
258293
]

server/routes/notebooks/agent_router.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ Final result must be a stringified JSON object:
5151
\`\`\`json
5252
{
5353
"findings": array[object],
54-
"hypotheses": array[object]
54+
"hypotheses": array[object],
55+
"investigationName": "string object which will be the auto generated name for the whole investigation, max 50 characters"
5556
}
5657
\`\`\`
5758
@@ -107,7 +108,7 @@ Your final result JSON must include:
107108
\`\`\`json
108109
{
109110
"steps": [],
110-
"result": "{\"findings\":[{\"id\":\"F1\",\"description\":\"High error rate detected\",\"importance\":90,\"evidence\":\"500+ errors in last hour\"}],\"hypotheses\":[{\"id\":\"H1\",\"title\":\"Database Connection Issue\",\"description\":\"Application errors caused by database connectivity problems\",\"likelihood\":85,\"supporting_findings\":[\"F1\"]}]}"
111+
"result": "{\"investigationName\": \"Invalid payment token Investigation\",\"findings\":[{\"id\":\"F1\",\"description\":\"High error rate detected\",\"importance\":90,\"evidence\":\"500+ errors in last hour\"}],\"hypotheses\":[{\"id\":\"H1\",\"title\":\"Database Connection Issue\",\"description\":\"Application errors caused by database connectivity problems\",\"likelihood\":85,\"supporting_findings\":[\"F1\"]}]}"
111112
}
112113
\`\`\`
113114

0 commit comments

Comments
 (0)