Updated on 2025-07-28 GMT+08:00

Using APIs to Call an Agent

The agent development platform allows you to call APIs for created agents. Before calling an agent, create an agent by referring to Improving Skills for Agents.

Obtaining the Call Path

To obtain the call path of an agent, perform the following steps:

  1. Log in to ModelArts Studio and click Agent Dev.
  2. On the Workbench page, click the Application tab. On the required agent card, click and choose Call Path.
    Figure 1 Obtaining the call path of an agent (1)

  3. In the Call Path dialog box, click Copy Path.

    The conversation_id parameter indicates the session ID, which uniquely identifies a session. You can set the session ID to any value in the standard UUID format. For example, conversation_id in the following figure can be replaced with 550e8400-e29b-41d4-a716-446655440000.

    Figure 2 Obtaining the call path of an agent (2)

Obtaining a Token

Obtain the token by following the instructions provided in section "Calling REST APIs" > "Authentication" in API Reference.

Using Postman to Call APIs

  1. Create a POST request in Postman and enter the API of the application.
  2. Set the request header parameters.
    • KEY: Content-Type; VALUE: application/json
    • The header parameter X-Auth-Token is mandatory, and the parameter value is the token obtained in Obtaining a Token.
    Figure 3 Configuring the request header

  3. In Postman, choose Body > raw. The following is an example of configuring the request body: The query parameter is a question raised by the user, and is used as an input of the application.
    { 
      "query": "Introduce the scenic spots in Beijing."
    }
  4. Click Send on Postman to send the request. If status code 200 is returned, the API is successfully called. The following is an example response:
    data:{"event":"start","createdTime":1744636611503}
    
    data:{"event":"message","content":"Beijing","createdTime":1744636611816}
    
    data:{"event":"message","content":"Yes","createdTime":1744636611854}
    
    data:{"event":"message","content":"China","createdTime":1744636611890}
    
    data:{"event":"message","content":"Capital","createdTime":1744636611925}
    
    ...
    
    data:{"event":"message","content":"Anytime","createdTime":1744636624119}
    
    data:{"event":"message","content":"Tell me","createdTime":1744636624154}
    
    data:{"event":"message","content":".","createdTime":1744636624190}
    
    data:{"event":"statistic_data","latency":{"overall":13.17},"createdTime":1744636624265}
    
    data:{"event":"summary_response","content":"Beijing is the capital of China. It has rich historical and cultural heritage and modern city landscapes. Here are some famous tourist attractions:\n\n###Historical and cultural attractions\n- **Imperial Palace**\n  - Features: The largest palace complex in the world, the palace of the Ming and Qing Dynasties, showcased the ancient Chinese architectural art and royal culture. \n - Suggestion: You are advised to reserve at least half a day for the visit. It is recommended that you purchase tickets online in advance to avoid queuing. \n\n- **Tian'anmen Square**\n  - Features: The world's largest city square, surrounded by important buildings such as the Monument of People's Heroes and Chairman Mao's Memorial Hall. \n-Suggestion: Visit in the morning or evening to avoid peak hours. \n\n- **Summer Palace**\n-Features: The most complete Royal Garden in China, based on Kunming Lake and Wanshou Mountain, integrates the design style of Jiangnan Garden. \n  - Suggestion: Suitable for family travel. You can take a cruise boat to visit Kunming Lake. \n\n###Modern Scenic Spots\n- **Bird's Nest and Water Cube**\n  - Features: The main venue of the 2008 Beijing Olympic Games has become a landmark building in Beijing. \n -Suggestion: You can see the light show at night. \n\n- **798 Art Zone**\n  - Features: A collection of art exhibitions and creative studios, a paradise for art enthusiasts. \n  - Suggestion: It is suitable for visiting in the afternoon or evening. You can enjoy the artistic atmosphere here. \n\n- **Sanlitun**\n - Feature: Beijing's most fashionable shopping and entertainment area with many international brand stores and restaurants. \n-Suggestion: It is recommended that you go to Beijing at night to experience nightlife in Beijing. \n\nWe hope that the information is helpful for your travel plan. If you need more detailed trip planning or other information, please feel free to let me know.","role":"assistant","createdTime":1744636624266}
    
    data:{"event":"done","createdTime":1744636624276}