AgentBuilder 伺服器
預設情況下,您在 http://localhost:7860 的 AgentBuilder 伺服器不會暴露到公共網際網路。
但是,您可以使用像 ngrok 或 zrok 這樣的轉發平台轉發 AgentBuilder 伺服器流量,使您的伺服器公開。
當您的 AgentBuilder 伺服器公開時,您可以做一些事情,比如外部部署您的 AgentBuilder MCP 伺服器、提供 API 請求和公開共享FLOW的 Playground。
先決條件
在您計劃託管 AgentBuilder 安裝的機器上,安裝 AgentBuilder 和反向代理或轉發服務。
本指南使用 ngrok,但您可以使用任何類似的反向代理或轉發平台。
如果您想按照本指南操作,請安裝 ngrok 和建立 ngrok authtoken。
使用 ngrok 暴露您的 AgentBuilder 伺服器
-
啟動 AgentBuilder:
_10uv run langflow run -
在另一個終端機視窗中,使用您的 ngrok authtoken 認證您的本地 ngrok 伺服器:
_10ngrok config add-authtoken NGROK_AUTHTOKEN -
使用 ngrok 將您的 AgentBuilder 伺服器暴露到公共網際網路:
_10ngrok http http://localhost:7860此範例假設您使用預設的 AgentBuilder 監聽地址
http://localhost:7860。如果您有不同的監聽地址,您必須相應地修改此命令。ngrok 會話在您的終端機中啟動,並部署一個臨時域,沒有認證。 要新增認證或部署靜態域,請參閱 ngrok 文件。
Forwarding行會列印您的 AgentBuilder 伺服器的轉發地址:_10Forwarding https://94b1-76-64-171-14.ngrok-free.app -> http://localhost:7860轉發地址充當您的 AgentBuilder 伺服器的反向代理,ngrok 會將您的本地流量轉發到此域。
-
要驗證您的 AgentBuilder 伺服器是否公開可用,請導航到轉發地址 URL,例如
https://94b1-76-64-171-14.ngrok-free.app。
使用公共 AgentBuilder 伺服器
當您的 AgentBuilder 伺服器公開時,您可以做一些事情,比如外部部署您的 AgentBuilder MCP 伺服器、提供 API 請求和公開共享FLOW的 Playground。
外部部署您的 MCP 伺服器
在您部署公共 AgentBuilder 伺服器後,您也可以公開存取您的 AgentBuilder 專案的 MCP 伺服器。
為此,在您連接客戶端以使用伺服器動作時使用您的伺服器轉發地址。
提供 API 請求
要向公共 AgentBuilder 伺服器的 AgentBuilder API 端點發送請求,請使用伺服器的域作為您的 API 請求的基礎 URL。 例如:
_10curl -X POST \_10 "PUBLIC_SERVER_DOMAIN/api/v1/webhook/FLOW_ID" \_10 -H "Content-Type: application/json" \_10 -H "x-api-key: LANGFLOW_API_KEY" \_10 -d '{"data": "example-data"}'
當您在公共 AgentBuilder 伺服器上建立FLOW時,在 API access 窗格 中產生的程式碼片段會自 動使用您的公共伺服器域。
在腳本中進行 AgentBuilder API 呼叫時,您也使用您的公共域,包括 AgentBuilder 自動產生的程式碼片段。
例如,以下程式碼片段呼叫 ngrok 域來觸發指定的FLOW(d764c4b8...):
_29import requests_29_29url = "https://3f7c-73-64-93-151.ngrok-free.app/api/v1/run/d764c4b8-5cec-4c0f-9de0-4b419b11901a" # The complete API endpoint URL for this flow_29_29# Request payload configuration_29payload = {_29 "output_type": "chat",_29 "input_type": "chat",_29 "input_value": "Hello"_29}_29_29# Request headers_29headers = {_29 "Content-Type": "application/json",_29 "x-api-key": "LANGFLOW_API_KEY"_29}_29_29try:_29 # Send API request_29 response = requests.request("POST", url, json=payload, headers=headers)_29 response.raise_for_status() # Raise exception for bad status codes_29_29 # Print response_29 print(response.text)_29_29except requests.exceptions.RequestException as e:_29 print(f"Error making API request: {e}")_29except ValueError as e:_29 print(f"Error parsing response: {e}")
有關腳本中 AgentBuilder API 的演示,請參閱快速入門。
共享FLOW的 Playground
在您部署公共 AgentBuilder 伺服器後,您可以使用 可共享 Playground 選項使FLOW的 Playground 在公共 URL 上可用。 如果使用者存取此 URL,他們可以與FLOW的聊天輸入和輸出互動並查看結果,而無需安裝 AgentBuilder 或產生 AgentBuilder API 金鑰。
更多資訊請參閱共享FLOW的 Playground。