This project provides an AI-powered shopping agent built with FastAPI and LangGraph that helps users shop through the Beckn Protocol. The agent can search for items, help with order selection, initialization, confirmation, and even track, cancel, or support orders. Users can interact with the agent conversationally, simulating a shopping experience, or make direct API calls for more control.
- Shopping Assistant: A conversational AI agent that helps you shop by interacting with the decentralized Beckn Protocol. The agent can:
- Search for items
- Select items from available providers
- Initialize and confirm orders
- Track the status of orders
- Cancel orders or request support
- Beckn API Integration: For advanced users, the project also provides direct API endpoints for various shopping actions such as
search
,select
,init
,confirm
,status
,track
,cancel
, andsupport
. - User-Friendly Interface: A simple API-driven interaction model that makes shopping through the Beckn network seamless and efficient.
-
Clone the repository:
git clone https://github.com/bajpainaman/beckn-agent.git cd beckn-agent
-
Install the required dependencies:
pip install -r requirements.txt
Alternatively, you can install dependencies manually:
pip install fastapi uvicorn pydantic langchain_openai langgraph requests
-
Set up your OpenAI API key by creating a
.env
file or exporting the key directly:export OPENAI_API_KEY="your-api-key"
To start the FastAPI server using Uvicorn, run:
uvicorn main:app --reload
The server will start at http://127.0.0.1:8000
.
Interact with the AI shopping assistant via the /chat
endpoint. The agent will guide you through the shopping process on the Beckn Protocol, from searching for items to confirming your orders.
POST http://localhost:8000/chat
Content-Type: application/json
{
"input": "I want to order a pizza.",
"chat_history": []
}
The agent will respond and continue to guide you through selecting a provider, initializing the order, and completing the purchase.
For more control, you can interact with the Beckn Protocol directly via these API endpoints. Each endpoint handles a specific shopping action such as searching for items, confirming orders, or tracking status.
- Search for Items:
/search
- Select an Item:
/select
- Initialize an Order:
/init
- Confirm an Order:
/confirm
- Check Order Status:
/status
- Track an Order:
/track
- Cancel an Order:
/cancel
- Request Support:
/support
POST http://localhost:8000/search
Content-Type: application/json
{
"item": "pizza",
"delivery_location": "12.9715987,77.5945627"
}
Below are examples of how you can use the various API endpoints to interact directly with the Beckn Protocol:
-
Search for Items:
POST /search { "item": "pizza", "delivery_location": "12.9715987,77.5945627" }
-
Select an Item:
POST /select { "bpp_id": "sandbox-bpp-network.becknprotocol.io", "bpp_uri": "https://sandbox-bpp-network.becknprotocol.io", "provider_id": "example_provider_id", "item_id": "example_item_id" }
-
Initialize an Order:
POST /init { "bpp_id": "sandbox-bpp-network.becknprotocol.io", "bpp_uri": "https://sandbox-bpp-network.becknprotocol.io", "provider_id": "example_provider_id", "item_id": "example_item_id", "billing_info": { "phone": "9999999999", "email": "email@example.com", "address": "123 Street, City" }, "delivery_info": { "location": "12.9715987,77.5945627", "address": "456 Street, City", "phone": "8888888888" } }
-
Confirm an Order:
POST /confirm { "bpp_id": "sandbox-bpp-network.becknprotocol.io", "bpp_uri": "https://sandbox-bpp-network.becknprotocol.io", "provider_id": "example_provider_id", "item_id": "example_item_id", "billing_info": { "phone": "9999999999", "email": "email@example.com", "address": "123 Street, City" }, "delivery_info": { "location": "12.9715987,77.5945627", "address": "456 Street, City", "phone": "8888888888" }, "payment_info": { "method": "credit_card", "transaction_id": "txn_12345" } }
-
Track an Order:
POST /track { "bpp_id": "sandbox-bpp-network.becknprotocol.io", "bpp_uri": "https://sandbox-bpp-network.becknprotocol.io", "order_id": "example_order_id" }
-
Cancel an Order:
POST /cancel { "bpp_id": "sandbox-bpp-network.becknprotocol.io", "bpp_uri": "https://sandbox-bpp-network.becknprotocol.io", "order_id": "example_order_id" }
-
Request Support:
POST /support { "bpp_id": "sandbox-bpp-network.becknprotocol.io", "bpp_uri": "https://sandbox-bpp-network.becknprotocol.io", "order_id": "example_order_id" }
.
├── beckn_requests.py # Contains all the Beckn API request functions
├── main.py # FastAPI app and agent definition
├── requirements.txt # Python dependencies
└── README.md # This file
Once the server is running, you can visit the interactive API documentation generated by FastAPI at:
http://127.0.0.1:8000/docs