Spaces:
Paused
Paused
dushyantsingh0 commited on
Commit ·
f681a63
1
Parent(s): db68795
fix: resolve typescript build errors in internal portal navigation
Browse files- agents/triage.py +34 -1
- agents/workflow.py +1 -1
- scratch/verify_fix.py +25 -0
agents/triage.py
CHANGED
|
@@ -111,13 +111,46 @@ async def triage_node(state: AgentState, config: RunnableConfig) -> Dict[str, An
|
|
| 111 |
# 3. Define Extraction Chain
|
| 112 |
try:
|
| 113 |
logger.debug(f"Triage node starting ainvoke for ticket {state['ticket_id']}")
|
| 114 |
-
|
|
|
|
|
|
|
| 115 |
"title": state["title"],
|
| 116 |
"description": state["description"] + user_constraints,
|
| 117 |
"image_captions": "\n".join(image_captions) if image_captions else "No visual evidence provided.",
|
| 118 |
"kb_context": "\n---\n".join(kb_context) if kb_context else "No relevant KB articles found.",
|
| 119 |
"format_instructions": parser.get_format_instructions()
|
| 120 |
})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 121 |
logger.debug(f"Triage node completed for ticket {state['ticket_id']}")
|
| 122 |
|
| 123 |
# Determine final fields: AI enrichment + User persistence
|
|
|
|
| 111 |
# 3. Define Extraction Chain
|
| 112 |
try:
|
| 113 |
logger.debug(f"Triage node starting ainvoke for ticket {state['ticket_id']}")
|
| 114 |
+
|
| 115 |
+
# We manually invoke the LLM first to perform resilient JSON cleanup
|
| 116 |
+
raw_output = await chain.ainvoke({
|
| 117 |
"title": state["title"],
|
| 118 |
"description": state["description"] + user_constraints,
|
| 119 |
"image_captions": "\n".join(image_captions) if image_captions else "No visual evidence provided.",
|
| 120 |
"kb_context": "\n---\n".join(kb_context) if kb_context else "No relevant KB articles found.",
|
| 121 |
"format_instructions": parser.get_format_instructions()
|
| 122 |
})
|
| 123 |
+
|
| 124 |
+
# --- RESILIENCE: Handle Markdown-wrapped JSON ---
|
| 125 |
+
# If the output is still a string (meaning parser failed or we bypassed it),
|
| 126 |
+
# we clean it. (Note: standard chain | parser usually handles this, but
|
| 127 |
+
# here we add an explicit guard).
|
| 128 |
+
content = raw_output
|
| 129 |
+
if hasattr(raw_output, 'content'): # for BaseMessage
|
| 130 |
+
content = raw_output.content
|
| 131 |
+
|
| 132 |
+
# If the result is a Pydantic object (parser worked), we use it.
|
| 133 |
+
# Otherwise, we might need a manual parse.
|
| 134 |
+
result = raw_output if isinstance(raw_output, TriageResult) else None
|
| 135 |
+
|
| 136 |
+
if not result:
|
| 137 |
+
import json
|
| 138 |
+
import re
|
| 139 |
+
|
| 140 |
+
# Extract JSON from potential Markdown blocks
|
| 141 |
+
json_match = re.search(r'```json\s*(.*?)\s*```', str(content), re.DOTALL)
|
| 142 |
+
if json_match:
|
| 143 |
+
content = json_match.group(1)
|
| 144 |
+
else:
|
| 145 |
+
# Try to find anything between curly braces
|
| 146 |
+
json_match = re.search(r'(\{.*\}|\[.*\])', str(content), re.DOTALL)
|
| 147 |
+
if json_match:
|
| 148 |
+
content = json_match.group(1)
|
| 149 |
+
|
| 150 |
+
# Manual Parse
|
| 151 |
+
clean_data = json.loads(content)
|
| 152 |
+
result = TriageResult(**clean_data)
|
| 153 |
+
|
| 154 |
logger.debug(f"Triage node completed for ticket {state['ticket_id']}")
|
| 155 |
|
| 156 |
# Determine final fields: AI enrichment + User persistence
|
agents/workflow.py
CHANGED
|
@@ -259,7 +259,7 @@ async def run_ai_workflow(ctx: Any, ticket_id: Any, ticket_data: Dict[str, Any],
|
|
| 259 |
"processed_steps": final_state.get("processed_steps", []),
|
| 260 |
"summaries": {
|
| 261 |
"internal_summary": internal_summary,
|
| 262 |
-
"customer_summary": (final_state.get("suggested_reply") or "")
|
| 263 |
}
|
| 264 |
})
|
| 265 |
|
|
|
|
| 259 |
"processed_steps": final_state.get("processed_steps", []),
|
| 260 |
"summaries": {
|
| 261 |
"internal_summary": internal_summary,
|
| 262 |
+
"customer_summary": (final_state.get("suggested_reply") or "") or "AI analysis in progress."
|
| 263 |
}
|
| 264 |
})
|
| 265 |
|
scratch/verify_fix.py
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import asyncio
|
| 2 |
+
import sys
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
if sys.platform == 'win32':
|
| 6 |
+
asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
|
| 7 |
+
|
| 8 |
+
from core.database import async_session_factory
|
| 9 |
+
from models.ticket import Ticket
|
| 10 |
+
from sqlalchemy import select
|
| 11 |
+
|
| 12 |
+
async def verify():
|
| 13 |
+
t_id = "ffe0afe9-1a66-46d4-9eb4-dcc491d5955c"
|
| 14 |
+
async with async_session_factory() as db:
|
| 15 |
+
res = await db.execute(select(Ticket).where(Ticket.id == t_id))
|
| 16 |
+
t = res.scalar_one_or_none()
|
| 17 |
+
if t:
|
| 18 |
+
print(f"ID: {t.id}")
|
| 19 |
+
print(f"Expected Resolution: {t.expected_resolution_at}")
|
| 20 |
+
print(f"Effort Hours: {t.estimated_effort_hours}")
|
| 21 |
+
else:
|
| 22 |
+
print("Ticket not found.")
|
| 23 |
+
|
| 24 |
+
if __name__ == "__main__":
|
| 25 |
+
asyncio.run(verify())
|