Build Custom AI Agents with Agent API — 构建自定义 AI 代理(练习操作步骤)

《Build Custom AI Agents with Agent API — 构建自定义 AI 代理》的分步练习操作指南。...

📅 2026/10/2 ✍️ ponybai 🏷️ agentforce, agent api, rest api, salesforce

本文是《Build Custom AI Agents with Agent API — 构建自定义 AI 代理》的练习操作步骤。阅读原文请见:Build Custom AI Agents with Agent API — 构建自定义 AI 代理。

1. Enable Agentforce and Activate an Agent

  1. Enable Agentforce in your Salesforce org.
  2. Activate at least one agent.
    • Note: Agent API doesn't support agents of the type "Agentforce (Default)".

2. Create an External Client App and Enable OAuth Settings

  1. Create an external client app in Salesforce. This app handles the client credential flow, which is essential for secure API calls.
  2. Enable OAuth settings for API.

3. Obtain the Consumer Key and Consumer Secret

  1. Find the consumer key and consumer secret in your external client app. These credentials authenticate your API calls.

4. Create a Token

  1. Create a token using the consumer key, consumer secret, and your domain name. This token authenticates your API calls.

5. Make Your First API Call

  1. Gather the required information from your org. See "Call the API" in the Agent API Developer Guide.
  2. Using a command-line interface, run the following curl command to create a new agent session with the Agent API:

```

curl --location -X POST https://api.salesforce.com/einstein/ai-agent/v1/agents/{AGENT_ID}/sessions \

--header 'Content-Type: application/json' \

--header 'Authorization: Bearer {ACCESS_TOKEN}' \

--data '{

"externalSessionKey": "{RANDOM_UUID}",

"instanceConfig": {

"endpoint": "https://{MY_DOMAIN_URL}"

},

"streamingCapabilities": {

"chunkTypes": ["Text"]

},

"bypassUser": true

}'

```

  1. When the call succeeds, you receive a response with a session ID and additional info.
  2. Start sending messages to the AI agent:
    • Synchronous messages: ideal for getting the complete response in a single call.
    • Streaming messages: better for real-time interactions like chat conversations.
  3. When done, close the session.