Skip to content

Commit d35addc

Browse files
authored
Clean up agent summary formatting (#803)
Signed-off-by: Tyler Ohlsen <[email protected]>
1 parent 4a9988c commit d35addc

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.1.0/)
88
### Enhancements
99
- Clean up / hide complex fields on agent configuration ([#796](https://github.com/opensearch-project/dashboards-flow-framework/pull/796))
1010
- Add agent summary ([#801](https://github.com/opensearch-project/dashboards-flow-framework/pull/801))
11+
- Clean up agent summary formatting ([#803](https://github.com/opensearch-project/dashboards-flow-framework/pull/803))
1112
### Bug Fixes
1213
### Infrastructure
1314
### Documentation

public/pages/workflow_detail/agentic_search/test_flow/agent_summary_modal.tsx

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
EuiSmallButton,
1414
EuiText,
1515
} from '@elastic/eui';
16+
import { TOOL_TYPE } from '../../../../../common';
1617

1718
interface AgentSummaryModalProps {
1819
onClose: () => void;
@@ -26,11 +27,8 @@ export function AgentSummaryModal(props: AgentSummaryModalProps) {
2627
<EuiModalHeaderTitle>Agent Summary</EuiModalHeaderTitle>
2728
</EuiModalHeader>
2829
<EuiModalBody>
29-
{/**
30-
* Handle newline formatting, as the agent response will likely have plaintext "\n" characters.
31-
*/}
32-
<EuiText style={{ whiteSpace: 'pre-wrap' }}>
33-
<i>{props.agentSummary}</i>
30+
<EuiText style={{ whiteSpace: 'pre-wrap', lineHeight: 1.5 }}>
31+
{prettifyAgentSummary(props.agentSummary)}
3432
</EuiText>
3533
</EuiModalBody>
3634
<EuiModalFooter>
@@ -41,3 +39,34 @@ export function AgentSummaryModal(props: AgentSummaryModalProps) {
4139
</EuiModal>
4240
);
4341
}
42+
43+
// Post-processing of the agent summary string returned from the LLM.
44+
// Clean up any escape characters, highlight the tools mentioned, and other
45+
// minor formatting / styling improvements
46+
function prettifyAgentSummary(text: string): any {
47+
// rm backslashes before quotes
48+
let updatedText = text.replace(/\\"/g, '"');
49+
50+
const tools = [
51+
...(Object.values(TOOL_TYPE) as string[]),
52+
'query_planner_tool',
53+
];
54+
updatedText = updatedText.replace(
55+
new RegExp(`\\b(${tools.join('|')})\\b`, 'g'),
56+
'**_$1_**'
57+
);
58+
59+
return updatedText.split('\n').map((line, idx) => (
60+
<div key={idx} style={{ marginBottom: '1rem' }}>
61+
{line.split(/(\*\*.*?\*\*)/).map((segment, j) =>
62+
segment.startsWith('**_') && segment.endsWith('_**') ? (
63+
<strong key={j}>
64+
<em>{segment.slice(3, -3)}</em>
65+
</strong>
66+
) : (
67+
segment
68+
)
69+
)}
70+
</div>
71+
));
72+
}

0 commit comments

Comments
 (0)