Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -39,27 +39,56 @@ def ticket_creation_agent(state: State) -> Command[Literal["priority_classificat
|
|
| 39 |
# Priority classification agent
|
| 40 |
def priority_classification_agent(state: State) -> Command[Literal["escalation_classification_agent"]]:
|
| 41 |
"""Classify priority based on the issue description."""
|
| 42 |
-
prompt =
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
def escalation_classification_agent(state: State) -> Command[Literal["generate_response_agent"]]:
|
| 50 |
-
"""Classify whether escalation is needed based on priority."""
|
| 51 |
-
escalation_needed = state["priority"].lower() in ["urgent", "critical"]
|
| 52 |
-
return Command(update={"escalation_needed": escalation_needed}, goto="generate_response_agent")
|
| 53 |
|
| 54 |
# Generate response agent
|
| 55 |
def generate_response_agent(state: State) -> Dict[str, str]:
|
| 56 |
"""Generate response based on ticket priority and escalation need."""
|
| 57 |
-
escalation =
|
| 58 |
-
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
return {"response": response, "escalation": escalation}
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# Add nodes to the graph
|
| 64 |
builder.add_edge(START, "ticket_creation_agent")
|
| 65 |
builder.add_node("ticket_creation_agent", ticket_creation_agent)
|
|
|
|
| 39 |
# Priority classification agent
|
| 40 |
def priority_classification_agent(state: State) -> Command[Literal["escalation_classification_agent"]]:
|
| 41 |
"""Classify priority based on the issue description."""
|
| 42 |
+
prompt = (
|
| 43 |
+
f"You are a support assistant. Classify the following issue as "
|
| 44 |
+
f"'urgent', 'critical', or 'normal' based on its severity:\n\n"
|
| 45 |
+
f"Issue: {state['issue_description']}"
|
| 46 |
+
)
|
| 47 |
+
priority = llm.invoke(prompt).strip().lower()
|
| 48 |
+
|
| 49 |
+
# Ensure valid priority classification
|
| 50 |
+
if priority not in ["urgent", "critical", "normal"]:
|
| 51 |
+
priority = "normal" # Default to 'normal' if the classification fails
|
| 52 |
|
| 53 |
+
return Command(update={"priority": priority}, goto="escalation_classification_agent")
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
# Generate response agent
|
| 56 |
def generate_response_agent(state: State) -> Dict[str, str]:
|
| 57 |
"""Generate response based on ticket priority and escalation need."""
|
| 58 |
+
escalation = (
|
| 59 |
+
"Escalate the issue to a senior team member immediately."
|
| 60 |
+
if state["escalation_needed"]
|
| 61 |
+
else "No escalation needed."
|
| 62 |
+
)
|
| 63 |
+
|
| 64 |
+
# Updated prompt to guide the model explicitly
|
| 65 |
+
prompt = (
|
| 66 |
+
f"You are a customer service assistant. Generate a concise and actionable response "
|
| 67 |
+
f"for the following issue:\n\n"
|
| 68 |
+
f"Issue: {state['issue_description']}\n"
|
| 69 |
+
f"Priority: {state['priority']}.\n\n"
|
| 70 |
+
f"Your response should directly address the issue and provide next steps."
|
| 71 |
+
)
|
| 72 |
+
response = llm.invoke(prompt).strip()
|
| 73 |
|
| 74 |
return {"response": response, "escalation": escalation}
|
| 75 |
|
| 76 |
+
# Gradio Interface function to process the ticket
|
| 77 |
+
def process_ticket(issue_description: str):
|
| 78 |
+
"""Process the issue ticket through the multi-agent flow."""
|
| 79 |
+
state = {"issue_description": issue_description}
|
| 80 |
+
try:
|
| 81 |
+
print(f"Initial Issue Description: {issue_description}") # Debug log
|
| 82 |
+
result = graph.invoke(state)
|
| 83 |
+
print(f"Graph Result: {result}") # Debug log
|
| 84 |
+
response = result.get("response", "No response generated")
|
| 85 |
+
escalation = result.get("escalation", "No escalation specified")
|
| 86 |
+
return response, escalation
|
| 87 |
+
except Exception as e:
|
| 88 |
+
print(f"Error occurred: {e}") # Debug log
|
| 89 |
+
return f"Error occurred: {e}", "Unable to determine escalation"
|
| 90 |
+
|
| 91 |
+
|
| 92 |
# Add nodes to the graph
|
| 93 |
builder.add_edge(START, "ticket_creation_agent")
|
| 94 |
builder.add_node("ticket_creation_agent", ticket_creation_agent)
|