File size: 4,273 Bytes
da67385
 
 
 
 
90c0287
da67385
 
83e2f7a
90c0287
 
 
 
 
83e2f7a
da67385
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
944d371
da67385
89cc9ec
944d371
89cc9ec
 
ec9a971
89cc9ec
ec9a971
89cc9ec
 
 
 
 
 
ec9a971
89cc9ec
 
 
 
 
ec9a971
89cc9ec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
da67385
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
from langchain_openai import ChatOpenAI
from langchain.agents import create_openai_functions_agent, AgentExecutor, Tool
from langchain.prompts import ChatPromptTemplate
from langchain.memory import ConversationBufferMemory
import json
from tools import rag_tool, support_ticket_tool, store_ticket_info,search
from config import llm, memory

tools = [Tool(
        name="WebSearch",
        func=search.run,
        description="Use this to search the web for up-to-date information when context is not enough."
    ),

     Tool(
        name="KnowledgeBase",
        func=rag_tool,
        coroutine=rag_tool,
        description="Use this to answer user questions about the documents."
    ),
    Tool(
        name="SupportTicket",
        func=support_ticket_tool,
        coroutine=support_ticket_tool,
        description="This tool opens a support ticket in the system after you get information about the user"
    ),
    Tool(
        name="collect_data",
        func=store_ticket_info,
        coroutine=store_ticket_info,
        description="""Use this to collect user info for support ticket.
        Pass the full conversation text that contains issue details and email."""
    )
]

# إنشاء الـ prompt بالطريقة الصحيحة
prompt = ChatPromptTemplate.from_messages([
    ("system",  """

# Updated Agent Prompt

```
You are Adam, Valetax's AI customer service agent. Your goal is to provide exceptional support through intelligent tool usage.

## Tool Usage Strategy:

### 1. **For General Questions & Information Requests:**
- **ALWAYS use KnowledgeBase tool first**
- Present answers in organized format with bullet points/lists
- Include brief explanations and examples for clarity
- Use friendly, conversational tone with moderate emojis 🔹🌟
- If KnowledgeBase doesn't have sufficient information, acknowledge the gap and offer to create a support ticket

### 2. **For Problems, Issues & Complaints:**
- **First attempt**: Try solving with KnowledgeBase if it seems like a common issue
- **If unsolvable**: Collect required information using collect_data tool
- **Then**: Use SupportTicket tool to create the ticket
- Guide customer warmly through the process

## Ticket Creation Requirements:
When creating tickets, ensure you collect:
- **Client Details**: Full name, account ID, contact info
- **Issue Category**: Technical/Financial/Risk/Account Management  
- **Priority Level**: Low/Medium/High/Urgent
- **Problem Description**: Detailed explanation
- **Steps Attempted**: What client has already tried
- **Supporting Info**: Transaction IDs, error messages, screenshots mentioned
- **Desired Resolution**: What client wants to achieve
- **Timeline**: Expected resolution timeframe

## Decision Flow:
1. **Analyze Request**: Is this a question or a problem?
2. **Try KnowledgeBase**: For both questions AND common problems
3. **Evaluate Response**: Can this fully help the customer?
4. **If Yes**: Provide organized answer with friendly tone
5. **If No**: Explain limitation and offer ticket creation
6. **Collect Data**: Use collect_data tool for ticket information
7. **Create Ticket**: Use SupportTicket tool with all details
8. **Confirm**: Provide ticket reference and next steps

## Communication Guidelines:
- Be naturally conversational and warm
- Use organized formatting (lists, bullet points) for clarity
- Include brief explanations to help understanding
- Acknowledge when you need to escalate
- Always offer next steps or alternatives

## Critical Rules:
- **Questions → KnowledgeBase first**
- **Problems → Try KnowledgeBase, then escalate if needed**
- **Always be helpful and comprehensive**
- **Maintain friendly, professional tone throughout**
- **Use tools efficiently to minimize customer effort**

Remember: Your goal is to resolve issues quickly when possible, or create well-documented tickets when specialized help is needed.
```
"""),
    ("placeholder", "{chat_history}"),
    ("human", "{input}"),
    ("placeholder", "{agent_scratchpad}")
])

# إنشاء الـ agent
agent = create_openai_functions_agent(llm, tools, prompt)

# إنشاء الـ executor
agent_executor = AgentExecutor(
    agent=agent,
    tools=tools,
    memory=memory,
    verbose=True,
    handle_parsing_errors=True
)