> ## Documentation Index
> Fetch the complete documentation index at: https://docs.logic.inc/llms.txt
> Use this file to discover all available pages before exploring further.

# Max Agent Steps

> How to cap the number of steps an agent takes during an execution

## Max Agent Steps

When an agent uses tools, it works in steps: each response from the model counts as one step, whether it returns a message, a single tool call, or several tool calls at once. The `maxAgentSteps` query parameter lets you override the maximum number of steps allowed for a single execution.

The value must be an integer from `1` to `500`. If you don't set it, the execution defaults to `100` steps. A value outside that range returns a `400` error rather than being clamped.

<Info>
  This is most relevant for agentic agents that call tools. Lowering the limit
  can cap latency and cost; raising it gives complex, multi-step tasks more room
  to complete.
</Info>

### Example with `maxAgentSteps`

Add the `maxAgentSteps` query parameter to your execution request.

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST 'https://api.logic.inc/v1/agents/{agent_id}/executions?maxAgentSteps=25'
    -H "Authorization: Bearer $LOGIC_API_TOKEN"
    -H "Content-Type: application/json"
    -d '{
          {YOUR INPUT JSON HERE}
        }'
  ```

  ```bash httpie theme={null}
  http POST 'https://api.logic.inc/v1/agents/{agent_id}/executions'
    maxAgentSteps==25
    "Authorization:Bearer $LOGIC_API_TOKEN"
    "Content-Type:application/json"
    --raw '{
      {YOUR INPUT JSON HERE}
    }'
  ```

  ```python python theme={null}
  import requests

  LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

  response = requests.post(
      "https://api.logic.inc/v1/agents/{agent_id}/executions",
      params={"maxAgentSteps": 25},
      headers={
          "Authorization": f"Bearer {LOGIC_API_TOKEN}",
          "Content-Type": "application/json",
      },
      json={
          # Add your agent input here
      },
  )

  print(response.status_code, response.text)
  ```

  ```ruby ruby theme={null}
  require 'net/http'
  require 'json'

  uri = URI('https://api.logic.inc/v1/agents/{agent_id}/executions')
  uri.query = URI.encode_www_form({ maxAgentSteps: 25 })

  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true

  LOGIC_API_TOKEN = 'ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
  headers = {
    "Authorization" => "Bearer #{LOGIC_API_TOKEN}",
    "Content-Type" => "application/json"
  }
  body = { }.to_json

  request = Net::HTTP::Post.new(uri, headers)
  request.body = body

  response = http.request(request)
  puts response.code
  puts response.body
  ```

  ```javascript javascript theme={null}
  const LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

  const url = new URL("https://api.logic.inc/v1/agents/{agent_id}/executions");
  url.searchParams.set("maxAgentSteps", "25");

  const response = await fetch(url, {
    method: "POST",
    headers: {
      Authorization: `Bearer ${LOGIC_API_TOKEN}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({
      // Add your agent input here
    }),
  });

  console.log(await response.json());
  ```

  ```go go theme={null}
  package main

  import (
      "bytes"
      "fmt"
      "io/ioutil"
      "net/http"
  )

  const (
      LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  )

  func main() {
      url := "https://api.logic.inc/v1/agents/{agent_id}/executions?maxAgentSteps=25"

      jsonStr := `{
        {YOUR INPUT JSON HERE}
      }`

      req, err := http.NewRequest("POST", url, bytes.NewBufferString(jsonStr))
      if err != nil {
          panic(err)
      }

      req.Header.Set("Authorization", "Bearer "+LOGIC_API_TOKEN)
      req.Header.Set("Content-Type", "application/json")

      client := &http.Client{}
      resp, err := client.Do(req)
      if err != nil {
          panic(err)
      }
      defer resp.Body.Close()

      body, _ := ioutil.ReadAll(resp.Body)
      fmt.Println(string(body))
  }
  ```

  ```java java theme={null}
  // 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("maxAgentSteps", "25")
              .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());
          }
      }
  }
  ```
</CodeGroup>
