Skip to content

Commit 1c8175d

Browse files
committed
refactor: update AgentChat component for OpenAI integration and enhance markdown support
Signed-off-by: Andre Bossard <anbossar@microsoft.com>
1 parent b57955a commit 1c8175d

3 files changed

Lines changed: 87 additions & 24 deletions

File tree

backend/agents.py

Lines changed: 28 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -405,21 +405,34 @@ async def run_agent(self, request: AgentRequest) -> AgentResponse:
405405
agent = create_react_agent(self.llm, self.tools)
406406

407407
# System message to guide the agent's behavior
408-
system_msg = (
409-
"You are a support ticket management assistant. "
410-
"Use the CSV tools: csv_list_tickets, csv_search_tickets, csv_get_ticket, csv_ticket_fields. "
411-
"You MUST use the available tools to perform all actions - NEVER simulate or invent data. "
412-
"\n\n"
413-
"TICKET CAPABILITIES:\n"
414-
"- List tickets with filters (status, assigned_group, has_assignee)\n"
415-
"- Search tickets across summary/description/notes/resolution/requester/group/city\n"
416-
"- Get a ticket by id (UUID) including notes and resolution\n"
417-
"- Inspect available ticket fields (schema)\n"
418-
"\n"
419-
"When users ask about tickets, call the csv_* tools and summarize results. "
420-
"If a field is not present, state that explicitly. "
421-
"Always confirm actions based on actual tool results."
422-
)
408+
tool_lines = []
409+
for t in self.tools:
410+
name = t.name if hasattr(t, 'name') else str(t)
411+
desc = (t.description if hasattr(t, 'description') else "") or ""
412+
tool_lines.append(f"- `{name}`: {desc}".strip())
413+
tools_md = "\n".join(tool_lines) if tool_lines else "- (none)"
414+
415+
system_msg = f"""
416+
Du bist ein freundlicher CSV-Ticket-Assistent. Sprich **Deutsch**.
417+
418+
Antwortstil:
419+
- Starte immer mit einer kurzen Begrüßung.
420+
- Liste sofort die verfügbaren Tools (Markdown-Bullets).
421+
- Nutze **Markdown** mit klaren Überschriften (##), Bullet-Listen und Tabellen, wenn sinnvoll.
422+
- Für JSON-Daten nutze fenced Code-Blöcke:
423+
```json
424+
{{"example": "value"}}
425+
```
426+
- Halte Antworten knapp und gut strukturiert.
427+
428+
Verfügbare Tools:
429+
{tools_md}
430+
431+
Verhalten:
432+
- Verwende ausschließlich die csv_* Tools für Ticket-Informationen. Keine Daten erfinden.
433+
- Falls Daten fehlen, sage das explizit.
434+
- Fasse Ergebnisse klar zusammen; für Listen sind kompakte Tabellen ideal.
435+
"""
423436

424437
# Execute agent with user prompt
425438
print(f"\n{'='*60}")

frontend/package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@
2323
"@nivo/stream": "^0.99.0",
2424
"react": "^18.2.0",
2525
"react-dom": "^18.2.0",
26-
"react-router-dom": "^7.9.6"
26+
"react-markdown": "^10.1.0",
27+
"react-router-dom": "^7.9.6",
28+
"remark-gfm": "^4.0.1"
2729
},
2830
"devDependencies": {
2931
"@playwright/test": "^1.42.1",

frontend/src/features/agent/AgentChat.jsx

Lines changed: 56 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
/**
22
* AgentChat Component
33
*
4-
* Chat interface for Azure OpenAI LangGraph Agent
5-
* Agent has access to task tools and ticket MCP tools
4+
* Chat interface for OpenAI LangGraph Agent
5+
* Agent has access to CSV ticket tools
66
*
77
* Following principles:
88
* - Pure functions for message formatting (calculations)
@@ -31,6 +31,8 @@ import {
3131
Wrench20Regular,
3232
} from '@fluentui/react-icons'
3333
import { useEffect, useRef, useState } from 'react'
34+
import ReactMarkdown from 'react-markdown'
35+
import remarkGfm from 'remark-gfm'
3436
import { agentChat } from '../../services/api'
3537

3638
const useStyles = makeStyles({
@@ -105,6 +107,46 @@ const useStyles = makeStyles({
105107
wordBreak: 'break-word',
106108
whiteSpace: 'pre-wrap',
107109
},
110+
messageContentMarkdown: {
111+
whiteSpace: 'normal',
112+
lineHeight: 1.5,
113+
},
114+
markdown: {
115+
'& h1, & h2, & h3': {
116+
margin: `${tokens.spacingVerticalS} 0 ${tokens.spacingVerticalXS}`,
117+
fontWeight: tokens.fontWeightSemibold,
118+
},
119+
'& ul, & ol': {
120+
paddingLeft: tokens.spacingHorizontalL,
121+
margin: `${tokens.spacingVerticalXS} 0`,
122+
},
123+
'& table': {
124+
width: '100%',
125+
borderCollapse: 'collapse',
126+
marginTop: tokens.spacingVerticalXS,
127+
},
128+
'& th, & td': {
129+
border: `1px solid ${tokens.colorNeutralStroke1}`,
130+
padding: tokens.spacingHorizontalXS,
131+
textAlign: 'left',
132+
},
133+
'& pre': {
134+
backgroundColor: tokens.colorNeutralBackground3,
135+
padding: tokens.spacingHorizontalM,
136+
borderRadius: tokens.borderRadiusSmall,
137+
overflowX: 'auto',
138+
},
139+
'& code': {
140+
fontFamily: 'monospace',
141+
backgroundColor: tokens.colorNeutralBackground3,
142+
padding: '0 4px',
143+
borderRadius: tokens.borderRadiusSmall,
144+
},
145+
'& a': {
146+
color: tokens.colorBrandForegroundLink,
147+
textDecoration: 'underline',
148+
},
149+
},
108150
userContent: {
109151
backgroundColor: tokens.colorBrandBackground2,
110152
},
@@ -230,7 +272,7 @@ export default function AgentChat() {
230272
<Text weight="semibold" size={500}>
231273
AI Agent
232274
</Text>
233-
<Badge color="informative" appearance="filled">Azure OpenAI</Badge>
275+
<Badge color="informative" appearance="filled">OpenAI</Badge>
234276
</div>
235277
<div className={styles.headerControls}>
236278
<Text size={200}>Powered by LangGraph + GPT</Text>
@@ -252,12 +294,12 @@ export default function AgentChat() {
252294
{messages.length === 0 && !error && (
253295
<div className={styles.emptyState}>
254296
<Bot24Regular style={{ fontSize: '48px', marginBottom: tokens.spacingVerticalM }} />
255-
<Text size={400}>Start a conversation with the AI Agent</Text>
297+
<Text size={400}>Starte eine Unterhaltung mit dem AI Agenten</Text>
256298
<Text size={300} style={{ marginTop: tokens.spacingVerticalS, display: 'block' }}>
257-
The agent can manage tasks and tickets for you!
299+
Der Agent kann Tickets durchsuchen und Details anzeigen.
258300
</Text>
259301
<Text size={200} style={{ marginTop: tokens.spacingVerticalM, display: 'block' }}>
260-
Try: "Create a task to review the documentation" or "List all tasks"
302+
Versuche: "Suche Tickets mit 'VPN'" oder "Zeige Ticket [Ticket-ID]"
261303
</Text>
262304
</div>
263305
)}
@@ -285,9 +327,15 @@ export default function AgentChat() {
285327
<div
286328
className={`${styles.messageContent} ${
287329
message.role === 'user' ? styles.userContent : styles.assistantContent
288-
}`}
330+
} ${message.role !== 'user' ? styles.messageContentMarkdown : ''}`}
289331
>
290-
<Text>{message.content}</Text>
332+
{message.role === 'user' ? (
333+
<Text style={{ whiteSpace: 'pre-wrap' }}>{message.content}</Text>
334+
) : (
335+
<div className={styles.markdown}>
336+
<ReactMarkdown remarkPlugins={[remarkGfm]}>{message.content}</ReactMarkdown>
337+
</div>
338+
)}
291339
{message.error && (
292340
<div className={styles.errorDetails}>
293341
<Text weight="semibold" size={200} style={{ color: tokens.colorPaletteRedForeground1 }}>

0 commit comments

Comments
 (0)