Example of an AI agent using Agent Protocol to book and pay for a flight.
As AI agents become a significant part of online transactions, vendors like airlines will aim to better serve these agents, competing with other vendors catering to them. This will involve transitioning from only fiat payments to including crypto payment options. The example below assumes the airline accepts credit cards:
from agent_protocol import AgentProtocoltravel_ai =TravelAI()# Retrieve the API key from the Agent Protocol websiteap =AgentProtocol(api_key="YOUR_API_KEY")# The agent developer generates each user a unique Agent Protocol IDuser_ap_id = ...new_agent = ap.init_agent( name="TravelAssistant", user_agent_protocol_id=user_ap_id, description="An AI agent for booking flights and managing travel")agent_id = new_agent.idprint(f"New AI Travel Assistant created with ID: {agent_id}")# The agent developer needs to retrieve relevant info# from the user in order to initialize the agent. The agent developer# also implements relevant callbacks to handle transaction failures# and other errors.awaitcall_agent_developer_init_fns(agent_id)# User makes a requestuser_request ="I need a round trip flight to Japan for 10 days sometime in September"print(f"User request: {user_request}")# Travel AI processes the request and selects flightparsed_request = travel_ai.parse_travel_request(user_request)available_flights = travel_ai.search_flights(parsed_request)selected_flight = travel_ai.optimize_itinerary(available_flights, parsed_request)print(f"Travel AI selected flight: {selected_flight['airline']} for ${selected_flight['price']/100:.2f}")# The use case filters for the relevant cardscards = ap.retrieve_authorized_cards(use_case=...)# Agent developer defined function to purchase the flightc = cards[0]txn_id = ap.describe_expense(c, estimated_txn_size, txn_description)purchase_result =purchase_flight( c.card_number, c.exp_date, c.cvc)print(f"Purchase status: {purchase_result['status']}")if purchase_result['status']=='approved':# The purchase had an issue issue_report = ap.report_purchase_issue( card_id=c.id, transaction_id=purchase_result['transaction_id'], issue_description="Flight ticket not received after payment" )print(f"Issue investigation status: {issue_report['status']}")if issue_report['status']!='resolved': dispute_result = ap.initiate_buyer_dispute( card_id=c.id, transaction_id=purchase_result['transaction_id'], dispute_reason="Paid for flight ticket but did not receive it" )print(f"Dispute initiated. Status: {dispute_result['status']}")