By default, an agent execution runs synchronously: the request blocks until the agent finishes and the response contains the output. For long-running agents, you can instead run the execution asynchronously by adding the execMode query parameter.The execMode parameter accepts two values:
sync (default) — the request waits for the agent to finish and returns the output.
async — the request returns immediately with an execution record you can poll.
Async execution is useful for long-running or agentic agents, and for starting
many executions in parallel without holding open a request for each one.
// 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("execMode", "async") .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()); } }}
If caching is enabled (useCache=true) and a matching prior execution exists,
an async request returns the cached result right away with status already
SUCCESS and "cached": true, rather than IN_PROGRESS.
Use the execution id from the response to poll the GET /agent_executions/{id} endpoint. Keep polling until status is SUCCESS or ERROR. When the execution succeeds, the output field contains the agent’s result.
A status of IN_PROGRESS means the agent is still running—wait and poll
again. SUCCESS means output is populated; ERROR means the error field
explains what went wrong.