Agent API versus Models API
Key Takeaway
Agent API lets code chat with an existing, activated Agentforce agent, and one session holds one conversation. Models API gets output straight from a large language model.
Agent API and Models API both let developers add generative AI to an application, but they talk to different things. Agent API lets an application hold a conversation with an Agentforce agent that has already been built and activated. Models API connects an application straight to large language models (LLMs) to generate text, chat replies, and embeddings.
What Agent API does
Agent API is a REST API for chatting with Agentforce agents from code. An application uses it to hold a conversation with an agent that has already been built and activated. Each conversation runs as a session in this order:
- Start a session with the agent.
- Send messages to the agent.
- Receive the agent's messages.
- End the session.
Because Agent API is a REST API, an application can call it from outside Salesforce. One example is deploying a customer-facing use case from your own application.
Agent API works with an agent that already exists. Agentforce must be enabled with at least one agent activated. Agent API isn't supported for agents of type "Agentforce (Default)", so an integration that targets that agent type won't work through the API.
Agent API also requires an external client app (ECA). Every call needs an access token. A basic setup uses the client credentials flow, but any flow that provides a JWT-based access token works.
A furniture retailer runs its online store on its own web platform, outside Salesforce. The retailer has already built and activated an Agentforce agent that answers delivery questions. A shopper types a question into the store's help box. The store's code calls Agent API to start a session with that agent and sends the shopper's question as a message. The code then shows the agent's reply on the page and ends the session when the shopper is done.