diff --git a/frontend-integration/README.md b/frontend-integration/README.md index daa847f3..e3f9f98c 100644 --- a/frontend-integration/README.md +++ b/frontend-integration/README.md @@ -140,6 +140,7 @@ User Query → Search Agent → Product List → Info Agent → Full Details - Comprehensive error messages with request details - Graceful handling of API failures - Frontend displays user-friendly error messages +- Frontend requests to local agents use a 5-second timeout so stalled agents return controlled JSON errors instead of hanging the UI ## 🛠️ Technical Details @@ -155,4 +156,4 @@ User Query → Search Agent → Product List → Info Agent → Full Details --- -**Ready to explore? Start the agents in separate terminals and open the web interface! 🚀** \ No newline at end of file +**Ready to explore? Start the agents in separate terminals and open the web interface! 🚀** diff --git a/frontend-integration/frontend_app.py b/frontend-integration/frontend_app.py index a909eefa..31a20bfb 100644 --- a/frontend-integration/frontend_app.py +++ b/frontend-integration/frontend_app.py @@ -9,6 +9,7 @@ "search": "http://127.0.0.1:8001", "info": "http://127.0.0.1:8002" } +AGENT_REQUEST_TIMEOUT = 5 @app.route('/') def index(): @@ -24,7 +25,11 @@ def search_products(): # Call search agent with POST request payload = {"query": query} - response = requests.post(f"{AGENTS['search']}/search", json=payload) + response = requests.post( + f"{AGENTS['search']}/search", + json=payload, + timeout=AGENT_REQUEST_TIMEOUT + ) response.raise_for_status() # Agent returns JSON directly @@ -65,7 +70,11 @@ def get_product_info(): # Call info agent with POST request payload = {"barcode": barcode} - response = requests.post(f"{AGENTS['info']}/product", json=payload) + response = requests.post( + f"{AGENTS['info']}/product", + json=payload, + timeout=AGENT_REQUEST_TIMEOUT + ) response.raise_for_status() # Agent returns JSON directly @@ -111,7 +120,7 @@ def health_check(): for agent_name, agent_url in AGENTS.items(): try: - response = requests.get(f"{agent_url}/health", timeout=5) + response = requests.get(f"{agent_url}/health", timeout=AGENT_REQUEST_TIMEOUT) if response.status_code == 200: # Health endpoint returns JSON directly health_data = response.json() @@ -128,4 +137,4 @@ def health_check(): print("Available endpoints:") print("- Main interface: http://127.0.0.1:5000") print("- Health check: http://127.0.0.1:5000/health") - app.run(host='127.0.0.1', port=5000, debug=True) \ No newline at end of file + app.run(host='127.0.0.1', port=5000, debug=True)