Autogen_v0.4/multi_agent/multi_agent_implementation.ipynb (439 lines of code) (raw):
{
"cells": [
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"c:\\source\\repos\\multiagent-frameworks\\Autogen_v0.4\\multi_agent\n"
]
}
],
"source": [
"import sys\n",
"import os\n",
"\n",
"# Get the current working directory (where the notebook is running)\n",
"notebook_dir = os.getcwd()\n",
"\n",
"# Add the parent directory to the system path\n",
"parent_dir = os.path.abspath(os.path.join(notebook_dir, '.'))\n",
"sys.path.append(parent_dir)\n",
"print(parent_dir)"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"c:\\source\\repos\\multiagent-frameworks\\Autogen_v0.4\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"body=UserMessage(content='I want to know my credit card balance.', source='user', type='UserMessage') conversation_id='749ed688-f7aa-4c7f-aa78-cb1c52272218'\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\source\\repos\\multiagent-frameworks\\Autogen_v0.4\\multi_agent\\multi_agent_implementation.py:197: UserWarning: Resolved model mismatch: gpt-4o-2024-08-06 != gpt-4o-2024-11-20. Model mapping in autogen_ext.models.openai may be incorrect.\n",
" completion = await self._model_client.create(self._chat_history)\n"
]
},
{
"name": "stdout",
"output_type": "stream",
"text": [
"from A group_chat agent completion: {\"agentType\": \"NeedMoreInfo\", \"body\": \"I want to know my credit card balance.\"}\n",
"\u001b[32m--------------------\u001b[0m\n",
"Received by A Final Responder Agent:[UserMessage(content='I want to know my credit card balance.', source='user', type='UserMessage'), UserMessage(content='{\"agentType\": \"NeedMoreInfo\", \"body\": \"I want to know my credit card balance.\"}', source='GroupChatManager', type='UserMessage')]\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"c:\\source\\repos\\multiagent-frameworks\\Autogen_v0.4\\multi_agent\\multi_agent_implementation.py:108: UserWarning: Resolved model mismatch: gpt-4o-2024-08-06 != gpt-4o-2024-11-20. Model mapping in autogen_ext.models.openai may be incorrect.\n",
" completion = await self._model_client.create(self._chat_history)\n"
]
}
],
"source": [
"from multi_agent_implementation import *\n",
"runtime = SingleThreadedAgentRuntime()\n",
"await register_agents(runtime)\n",
"runtime.start()"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"async def get_answer(conversation_id, user_query):\n",
"\n",
" await runtime.publish_message(GroupChatMessage(body=UserMessage(content=user_query, source=\"user\"), \n",
" conversation_id=conversation_id), DefaultTopicId(type=\"group_chat_any_topic\", source=conversation_id)) \n",
"\n",
" group_chat_result = \"\"\n",
" try:\n",
" # Wait for a message in the queue, or you can use a timeout if needed\n",
" #group_chat_result = (await queue.get()).body.content\n",
" # clear queue \n",
" async with condition:\n",
" while conversation_id not in llm_results_dict:\n",
" await condition.wait()\n",
"\n",
" \n",
" group_chat_result = llm_results_dict[conversation_id].body.content\n",
" del llm_results_dict[conversation_id]\n",
" print(f\"conversation_id: {conversation_id}\")\n",
" print(\"\\033[35m\" + \"-\" * 20 + \"\\033[0m\")\n",
" except Exception as e:\n",
" # Handle any exception that may occur during the wait for the response\n",
" print(f\"Error retrieving message from queue: {e}\")\n",
" group_chat_result = \"An error occurred while waiting for the response.\"\n",
"\n",
" print(group_chat_result)"
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"conversation_id: 749ed688-f7aa-4c7f-aa78-cb1c52272218\n",
"\u001b[35m--------------------\u001b[0m\n",
"To check your credit card balance through Transify, could you please provide us with the last four digits of your credit card? This will help us locate the relevant information for you.\n"
]
}
],
"source": [
"conversation_id1 = str(uuid.uuid4())\n",
"user_query = \"I want to know my credit card balance.\"\n",
"await get_answer(conversation_id1, user_query)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"conversation_id: 012aee6d-02d6-42fa-82ca-c6a90f76eb13\n",
"\u001b[35m--------------------\u001b[0m\n",
"It seems the account number '1255' is not found in the Transify system. Could you please double-check the account number and provide the correct one? Alternatively, if you suspect this error and need further clarification, let me know, and we can explore other ways to assist you!\n"
]
}
],
"source": [
"user_query = \"My account number is 1255.\"\n",
"await get_answer(conversation_id1, user_query)"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"conversation_id: fb2c6c13-0027-4f00-8974-a1351e99aff7\n",
"\u001b[35m--------------------\u001b[0m\n",
"You can find your account number on your credit card statement or through the Transify app. If you need further assistance, please let me know.\n"
]
}
],
"source": [
"user_query = \"where do I find my account number?\"\n",
"await get_answer(conversation_id1, user_query)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"conversation_id: 012aee6d-02d6-42fa-82ca-c6a90f76eb13\n",
"\u001b[35m--------------------\u001b[0m\n",
"Your Transify account with the account number 'A1234567890' is verified and active. The balance in your account is $150.00 USD. If you need additional details or to manage your account, you can use the following links:\n",
"\n",
"- Account overview: [https://api.transify.com/v1/accounts/A1234567890](https://api.transify.com/v1/accounts/A1234567890)\n",
"- Balance details: [https://api.transify.com/v1/accounts/A1234567890/balance](https://api.transify.com/v1/accounts/A1234567890/balance)\n",
"\n",
"Let me know if you need further assistance!\n"
]
}
],
"source": [
"user_query = \"My account number is A1234567890.\"\n",
"await get_answer(conversation_id1, user_query)"
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"conversation_id: 012aee6d-02d6-42fa-82ca-c6a90f76eb13\n",
"\u001b[35m--------------------\u001b[0m\n",
"Thank you for your inquiry regarding the overdraft limit. Currently, based on the account details retrieved earlier, there is no specific mention of an overdraft facility tied to your Transify account. If you believe you have an overdraft arrangement or need more details, please confirm whether this is specifically linked to your Transify account, or provide more information.\n"
]
}
],
"source": [
"user_query = \"what is my over draft limit?\"\n",
"await get_answer(conversation_id1, user_query)"
]
},
{
"cell_type": "code",
"execution_count": 11,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"conversation_id: 012aee6d-02d6-42fa-82ca-c6a90f76eb13\n",
"\u001b[35m--------------------\u001b[0m\n",
"The balance in your Transify account is $150.00 USD, but no information about overdraft limits or maximum transaction amounts is available in the account details retrieved. Could you clarify if you're looking for specific transaction limits tied to transfers, withdrawals, or purchases within Transify? This would help provide you with accurate assistance.\n"
]
}
],
"source": [
"user_query = \"what is the maximum amount I can transact on my account number?\"\n",
"await get_answer(conversation_id1, user_query)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"conversation_id: 163fae64-89c4-4ec9-b524-3e3687f202ad\n",
"\u001b[35m--------------------\u001b[0m\n",
"Based on the information retrieved:\n",
"\n",
"Your credit card account is active and belongs to Alice Smith. Your current balances are 300.00 EUR and 100.00 USD.\n",
"\n",
"If you have any additional inquiries, feel free to ask!\n"
]
}
],
"source": [
"conversation_id2 = str(uuid.uuid4())\n",
"user_query = \"I want to know my credit card balance. My account number is XYZ7890123456.\"\n",
"await get_answer(conversation_id2, user_query)"
]
},
{
"cell_type": "code",
"execution_count": 13,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"conversation_id: 879b91e2-284e-4edf-9eef-e0bce103fb1a\n",
"\u001b[35m--------------------\u001b[0m\n",
"This query about planning a road trip to Zion National Park is not related to Transify. If you have any questions or concerns regarding Transify's services or features, feel free to share them, and I'll be happy to assist you!\n"
]
}
],
"source": [
"conversation_id3 = str(uuid.uuid4())\n",
"user_query = \"Plan a 3 day road trip to zion national park\"\n",
"await get_answer(conversation_id3, user_query)"
]
},
{
"cell_type": "code",
"execution_count": 14,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"conversation_id: 95889ea0-207d-4b6c-9049-e8ce81daeb34\n",
"\u001b[35m--------------------\u001b[0m\n",
"Based on the conversation history, the user's question has been identified (\"What are payment reversals and how to avoid them\") but no direct answer was provided. Here is the complete response:\n",
"\n",
"---\n",
"\n",
"**Payment Reversals:** A payment reversal, also known as a chargeback or refund, occurs when funds from a payment transaction are returned to the payer. Common reasons for payment reversals include disputes raised by customers, fraudulent transactions, duplicate charges, or errors in transaction processing.\n",
"\n",
"**How to Avoid Payment Reversals:**\n",
"1. **Ensure Transparent Communication:** Clearly communicate your terms and policies, including refund, cancellation, and return policies.\n",
"2. **Provide Accurate Details:** Maintain accurate product or service descriptions to avoid customer confusion.\n",
"3. **Use Fraud Protection Tools:** Identify and block potential fraudulent transactions with security tools and verification measures.\n",
"4. **Ensure Order Accuracy:** Verify customer details and order accuracy before processing payments.\n",
"5. **Deliver Promptly:** Ensure timely delivery of products or services to meet customer expectations.\n",
"6. **Offer Excellent Customer Service:** Handle inquiries or disputes quickly to avoid escalation into chargebacks.\n",
"7. **Maintain Documentation:** Keep records of all transactions and communications for future reference.\n",
"\n",
"Should you require more specific details regarding preventing payment reversals on Transify, feel free to let me know!\n"
]
}
],
"source": [
"conversation_id4 = str(uuid.uuid4())\n",
"user_query = \"What are payment reversals and how to avoid them\"\n",
"await get_answer(conversation_id4, user_query)"
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"conversation_id: 012aee6d-02d6-42fa-82ca-c6a90f76eb13\n",
"\u001b[35m--------------------\u001b[0m\n",
"Your recent transaction was successfully completed. Here are the details:\n",
"\n",
"- **Transaction ID**: 9HX25435AB0123456\n",
"- **Status**: Completed \n",
"- **Total Amount**: $75.00 USD \n",
" - **Transaction Fee**: $2.50 USD \n",
" - **Purchased Items**: \n",
" 1. Watercolor Paint Set - $50.00 USD \n",
" 2. Brush Set - $25.00 USD \n",
" - **Shipping Cost**: $5.00 USD \n",
"\n",
"The items were shipped to the following address: \n",
"123 Main St, Anytown, CA, 90210, US. \n",
"\n",
"Payment was made via Transify. If you'd like more information, you can view the transaction details using the following link: [Transaction Details](https://api.transify.com/v1/payments/transaction/9HX25435AB0123456). \n",
"\n",
"Let me know if you need assistance with anything else!\n"
]
}
],
"source": [
"user_query = \"get my transaction details\"\n",
"await get_answer(conversation_id1, user_query)"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"conversation_id: fe011b59-23c4-4c26-a752-c49fe171bf3e\n",
"\u001b[35m--------------------\u001b[0m\n",
"Here are the details of your transaction associated with account number **A1234567890**:\n",
"\n",
"- **Transaction ID**: 9HX25435AB0123456 \n",
"- **Status**: Completed \n",
"- **Total Amount**: $75.00 USD \n",
"- **Transaction Fee**: $2.50 USD \n",
"- **Create Time**: 2024-09-29T12:45:30Z \n",
"- **Update Time**: 2024-09-29T12:46:45Z \n",
"\n",
"### Payer Details:\n",
"- **Name**: John Doe \n",
"- **Email**: buyer@example.com \n",
"- **Country**: US \n",
"\n",
"### Payee Details:\n",
"- **Merchant ID**: MERCHANT987654321 \n",
"- **Name**: Alice's Art Supplies \n",
"- **Email**: seller@example.com \n",
"\n",
"### Payment Method:\n",
"- Transify \n",
"\n",
"### Transaction Items:\n",
"1. **Watercolor Paint Set** \n",
" - Quantity: 1 \n",
" - Price: $50.00 USD \n",
"\n",
"2. **Brush Set** \n",
" - Quantity: 1 \n",
" - Price: $25.00 USD \n",
"\n",
"### Shipping Information:\n",
"- **Recipient Name**: John Doe \n",
"- **Address**: 123 Main St, Anytown, CA, 90210, US \n",
"- **Shipping Cost**: $5.00 USD \n",
"\n",
"You can also view the transaction details at the following link: [View Transaction](https://api.transify.com/v1/payments/transaction/9HX25435AB0123456).\n",
"\n",
"Let me know if you need further assistance!\n"
]
}
],
"source": [
"conversation_id5 = str(uuid.uuid4())\n",
"user_query = \"get my transaction details my account number is A1234567890\"\n",
"await get_answer(conversation_id5, user_query)"
]
}
],
"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
}