Function introduction
Agents created in the AgentRun runtime can be called by other systems, allowing you to quickly integrate them into frontend web pages, backend services, and other business systems.
Prerequisites
-
You have created and published an active agent (Quickly create an agent or Create an agent using code).
-
You have granted the agent the `AliyunDevsFullAccess` permission to manage the Serverless Devs platform.
Procedure
Go to the integration and publishing page
-
Go to the AgentRun Runtime page.
-
On the card for the agent that you want to integrate, click Details.
-
On the agent details page, select Integration and Publishing from the left navigation pane.
The page displays the following three integration methods:
UI integration:
-
Generates a full-stack agent application interface with a single click.
-
You can embed the interface into existing web pages or other applications as an iframe or using an independent domain.
-
This method is suitable for scenarios that require a visual chat interface, such as internal workbenches or portals.
Code integration:
-
Provides a standard HTTP API compatible with protocols such as the OpenAI Chat Completions protocol.
-
External systems can call the agent directly by using a standard protocol API or an SDK. Suitable for multi-language and multi-platform integration.
Ecosystem integration:
Supports agent integration on platforms such as Dify and n8n.
Configure UI integration
-
Select an Integration Template. You can use the template to specify the UI Integration Method and Style Template. Click Preview to see the results of your configuration.
-
Integration Method: Full screen embedding, Floating chat, Sidebar.
-
Style Template: Simple, Business, Tech, Cozy.
-
-
Start Integration: Click Start Integration. Specify the endpoint for the corresponding agent version and complete the API Binding Configuration. Then, click Next.
-
Wait for the deployment to complete: View the deployment logs and wait for the process to finish.
-
Test the deployment result: A successful deployment displays the Deployed Integration Resources and generates a temporary Endpoint. You can click the endpoint to access and use the agent.
ImportantThis endpoint is provided by the Serverless Devs community, a Cloud Native Computing Foundation (CNCF) Sandbox project. It is for learning and testing purposes only and must not be used in production. The community performs periodic network probes on this domain name and revokes it 1 day after it is issued. For a better experience, attach a custom domain name.
-
Attach a Custom Domain Name: Click Add next to the endpoint to select an existing domain name or add a new one. For more information, see Configure a custom domain name.
Code integration
Call the agent directly by using a standard protocol API or an SDK for multi-language and multi-platform integration. The following example uses cURL:
curl https://12**********.agentrun-data.ap-southeast-1.aliyuncs.com/agent-runtimes/agent-code-XVe7d/endpoints/Default/invocations/openai/v1/chat/completions -XPOST \
-H "content-type: application/json" \
-H "X-AgentRun-Session-ID: your-session-id" \
-d '{
"messages": [{"role": "user", "content": "Write a piece of code to query the current time."}],
"stream":true
}'
The X-AgentRun-Session-ID header enables session affinity. Requests with the same session ID are routed to the same agent instance, which helps maintain conversation context. Use any unique string as a session ID, such as a UUID.