Skip to content

Generate suggestions from your own backend

Limited access

This feature is only available to a limited set of partners.

Rather than rely on the LLM to generate the suggestions while the user types, you can instead have your own backend generate the suggestions directly. This gives your agent more control and can improve latency.

Enabling this feature requires a few distinct steps:

  1. Build out an endpoint that complies with our suggestions spec.
  2. Create or update a connector to add a suggestion provider that points to that endpoint.
  3. Update your agent to enable suggestions for that connector.

The sections below go into this process in more detail.

Build the endpoint

Your server must expose an HTTPS endpoint purpose-built for generating suggestions. As the user types, Go sends a POST request to this endpoint with a JSON payload and expects a JSON response.

Your endpoint must respond within 10 seconds for the suggestions to be shown to the user.

Request to check text

Incoming requests to your endpoint will include the text to check.

{
  "text": "The concert was very enjoyable, and everyone was enthusiastic."
}

As the user edits their writing, the text will need to be checked again. When rechecking a range of text, additional information is included.

{
  "text": "The concert was very enjoyable, and everyone was enthusiastic.",
  "dirtyRanges": [
    { "startOffset": 16, "endOffset": 30 }
  ],
  "currentSuggestions": [
    {
      "original": "enthusiastic",
      "replacement": "hyped",
      "title": "Try hyped instead",
      "explanation": "'Hyped' is a casual way to say people are excited."
    }
  ],
  "dismissedSuggestions": [
    {
      "original": "the concert",
      "replacement": "the gig",
      "title": "Gig would be better",
      "explanation": "'Gig' is an informal word for a concert."
    }
  ]
}

The part of the text that changed since the last check is listed in dirtyRanges. Offsets count UTF-16 code units from zero, with the start inclusive and the end exclusive. A zero-width range indicates a deletion.

Information about previous suggestions your endpoint returned is in currentSuggestions, acceptedSuggestions, and dismissedSuggestions. The offset information isn't included for these suggestions.

View request schema

Response to make suggestions

In response to these requests, your endpoint returns a JSON object with an array of suggestions (up to 500). Each suggestion identifies the text to annotate and the details to show in the card.

{
  "suggestions": [
    {
      "startOffset": 16,
      "endOffset": 30,
      "original": "very enjoyable",
      "replacement": "a whole vibe",
      "title": "Prefer vibe",
      "explanation": "A whole vibe means you really enjoyed something."
    }
  ]
}

Anchor the suggestion using a startOffset and endOffset. Offsets count UTF-16 code units in the input text, starting at zero, with the start inclusive and the end exclusive. The text in original must match the exact text slice between those offsets.

Include a replacement field for a rewrite suggestion, or omit it for a comment suggestion. For a rewrite, use an empty string for the replacement value to suggest deleting the selected text.

Set the title and explanation of the suggestion to provide context to the user. For comment suggestions, the explanation is used as the body of the card.

If your endpoint cannot assess the text, return no suggestions and a short reason in the unavailable field.

{
  "suggestions": [],
  "unavailable": "Unsupported language"
}

Go does not show the reason to the user. Keep the reason under 200 characters and do not include the user's writing.

View response schema

Register the endpoint on a connector

Agents can't call the suggestion endpoint directly, but instead use a connector to enable this. You can update an existing connector or create a new one just for providing suggestions.

Add a suggestion provider to the connector with addSuggestionProvider(), which specifies the endpoint where requests should be sent.

connector.addSuggestionProvider({
  type: sdk.SuggestionProviderType.Endpoint,
  name: "GenAlphaSlang",
  endpointUrl: "https://api.example.com/suggestions",
});

Ensure that the connector includes an allowed network domain that matches the endpoint URL, and an appropriate authentication type that matches what your server expects.

A connector can register up to ten providers. When checking text, requests are sent to all of them in parallel. Endpoints that fail to respond within 10 seconds will be dropped.

Enable suggestions for an agent

The final step is to update your agent to make clear which connector to use when providing suggestions. Set useSuggestions on the connector in the agent's tools:

agent.setTools({
  connectors: [
    { connectorId: 1234, useSuggestions: true },
  ],
});

When enabled, the agent will no longer use the LLM for generating suggestions and instead send requests to the suggestion provider endpoints on the connector. Your agent must still include a while-writing routine, but any instructions will be ignored.