AI_Agent_Service/multi_ai_agent_with_tools.ipynb (193 lines of code) (raw):
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from dotenv import load_dotenv\n",
"load_dotenv()\n",
"\n",
"from azure.ai.projects.models import FunctionTool, ToolSet\n",
"from get_account_info_tools import *\n",
"from get_transaction_info_tools import *\n",
"\n",
"from CustomAIAgent import CustomAIServiceAgent\n",
"from AgentHandler import AgentHandler\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"get_account_info_set: Set = {get_account_info}\n",
"get_transaction_info_set: Set = {get_transaction_details}"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [],
"source": [
"functions = FunctionTool(functions=get_account_info_set)\n",
"toolset1 = ToolSet()\n",
"toolset1.add(functions)\n",
"agent_handler = AgentHandler()\n",
"\n",
"get_account_info_agent = CustomAIServiceAgent(agent_name=\"GetAccountInfoAgent\",\n",
" agent_instructions=\"\"\"You are Transify Support Agent. Transify is an online payment platform.\n",
" You can provide information about the account details. \n",
" You need to know the 'account number' to provide the account details.\n",
" If the 'account number' is provided use the get_account_info tool to get the account details.\n",
" Format the response with 'Account Details:'.\n",
" If the 'account number' is not provided, ask the user to provide the 'account number'. \n",
" If the account number is already provided, don't ask for it again.\n",
" Summarize and format your response in a clear and concise manner. \n",
" Do not provide unnecessary information.\n",
"\n",
" Response Format as table:\n",
" Account Balance: date | Balance Amount | account id\n",
" \"\"\",\n",
" tool_set=toolset1,\n",
" model=\"gpt-4o\"\n",
" )\n",
"\n",
"functions = FunctionTool(functions=get_transaction_info_set)\n",
"toolset1 = ToolSet()\n",
"toolset1.add(functions)\n",
"\n",
"\n",
"get_transaction_info_agent = CustomAIServiceAgent(agent_name=\"GetTransactionDetailsAgent\",\n",
" agent_instructions=\"\"\"You are Transify Support Agent. Transify is an online payment platform.\n",
" You can provide information about the transaction details for the account.\n",
" You need to know the 'account number' to provide the transaction details.\n",
" If the 'account number' is provided use the get_transaction_details tool to get the transaction details.\n",
" Format the response with 'Transaction Details:'.\n",
" If the 'account number' is not provided, ask the user to provide the 'account number'. \n",
" If the account number is already provided, don't ask for it again. \n",
" Summarize and format your response in a clear and concise manner.\n",
" Do not provide eunecessary information. \n",
"\n",
" Response Format as table:\n",
" Transaction: date | amount | description | transaction id\n",
" \"\"\",\n",
" tool_set=toolset1,\n",
" model=\"gpt-4o\"\n",
" )\n",
"\n",
"\n",
"\n",
"agent_handler.add_agent(get_account_info_agent)\n",
"agent_handler.add_agent(get_transaction_info_agent)\n",
"\n"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Please provide your account number so I can retrieve your latest transaction details.\n"
]
}
],
"source": [
"r = agent_handler.answer_user_question(\"I want to know my latest transaction details\")\n",
"print(r)\n"
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"**Transaction Details:**\n",
"\n",
"| **Transaction** | **Date** | **Amount** | **Description** | **Transaction ID** |\n",
"|-----------------------|------------------|------------|------------------------------------------|--------------------------|\n",
"| Completed | 2024-09-29 | $75.00 | Purchase of Watercolor Paint Set & Brush Set | 9HX25435AB0123456 |\n"
]
}
],
"source": [
"r = agent_handler.answer_user_question(\"account number is A1234567890.\")\n",
"print(r)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"**Account Details:**\n",
"\n",
"| **Account Balance** | **Date** | **Balance Amount** | **Account ID** |\n",
"|-----------------------|----------------|---------------------|----------------------|\n",
"| Verified | 2024-10-09 | $150.00 | A1234567890 |\n"
]
}
],
"source": [
"\n",
"r = agent_handler.answer_user_question(\"I want to know my account balance\")\n",
"print(r)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"I can only answer questions about Transify account and transaction details.\n"
]
}
],
"source": [
"response = agent_handler.answer_user_question(\"plan a 3 day road trip to zion national park\")\n",
"print(response)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "venv",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
}