If you run an agent with the same input more than once, you can reuse the result from a previous run instead of executing the agent again. Add the useCache query parameter set to true to enable this.A previous execution is reused only when the agent version, the tenant ID, and the input all match. When a match is found, the API returns its result immediately, which reduces latency and cost. If no match is found, the agent runs normally and its result becomes available for future cached requests.When a cached result is returned, the response has "cached": true and a cachedDocumentExecutionId pointing to the original execution that produced it.
Caching is disabled by default. You can also enable it per agent version in
the execution config; the useCache query parameter overrides that persisted
setting for a single call. Use it when the same input reliably produces the
same output and you want to avoid re-running the agent.
// Java requires the OkHttp library. You can add it to your project using Maven or Gradle. Learn more in the Java Quick Start section of the API reference.import okhttp3.*;import java.io.IOException;public class Main { public static void main(String[] args) throws IOException { OkHttpClient client = new OkHttpClient(); String json = "{ /* your input JSON here */ }"; RequestBody body = RequestBody.create(json, MediaType.get("application/json")); HttpUrl url = HttpUrl.parse("https://api.logic.inc/v1/agents/{agent_id}/executions") .newBuilder() .addQueryParameter("useCache", "true") .build(); Request request = new Request.Builder() .url(url) .addHeader("Authorization", "Bearer ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx") .addHeader("Content-Type", "application/json") .post(body) .build(); try (Response response = client.newCall(request).execute()) { System.out.println(response.body().string()); } }}