> ## 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.

# Dynamic Learning

> How Logic uses previous executions to improve future ones.

## Dynamic Learning

Logic can improve future executions based on past ones using dynamic learning.

When enabled, Logic can learn from your previous executions - such as the kinds of recommendations, outputs, or patterns that performed well - and apply that knowledge to improve future responses.

## How to use Dynamic Learning

To enable dynamic learning for an agent execution, add the `useDynamicLearning` query parameter to your request URL. The value of this parameter can be `true` or `false`.

If omitted, dynamic learning is disabled by default.

### Example with `useDynamicLearning`

Here’s how to enable dynamic learning in different environments.

<CodeGroup>
  ```bash curl theme={null}
  curl -X POST 'https://api.logic.inc/v1/agents/{agent_id}/executions?useDynamicLearning=true'
      -H "Authorization: Bearer $LOGIC_API_TOKEN"
      -H "Content-Type: application/json"
      -d '{
          /* your input JSON here */
      }'

  ```

  ```bash httpie theme={null}
  http -A bearer -a $LOGIC_API_TOKEN POST 'https://api.logic.inc/v1/agents/{agent_id}/executions?useDynamicLearning=true'
      --raw '{
        {YOUR INPUT JSON HERE}
      }'
  ```

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

  LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

  headers = {
      "Authorization": f"Bearer {LOGIC_API_TOKEN}",
      "Content-Type": "application/json"
  }

  response = requests.post(
      "https://api.logic.inc/v1/agents/{agent_id}/executions?useDynamicLearning=true",
      headers=headers,
      json={
          # Your input fields here
      }
  )

  print(response.json())
  ```

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

  uri = URI('https://api.logic.inc/v1/agents/{agent_id}/executions?useDynamicLearning=true')
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = uri.scheme == 'https'

  LOGIC_API_TOKEN = 'ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
  request = Net::HTTP::Post.new(uri)
  request['Authorization'] = "Bearer #{LOGIC_API_TOKEN}"
  request['Content-Type'] = 'application/json'
  request.body = '{
      /* your input here */
  }'


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

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

  const response = await fetch(
    "https://api.logic.inc/v1/agents/{agent_id}/executions?useDynamicLearning=true",
    {
      method: "POST",
      headers: {
        Authorization: `Bearer ${LOGIC_API_TOKEN}`,
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        // Your input fields here
      }),
    },
  );

  const data = await response.json();
  console.log(data);
  ```

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

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

  const (
      LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  )

  func main() {
      jsonStr := `{
        {YOUR INPUT JSON HERE}
      }`

      // Create request
      req, err := http.NewRequest("POST", "https://api.logic.inc/v1/agents/{agent_id}/executions?useDynamicLearning=true", bytes.NewBufferString(jsonStr))
      if err != nil {
          panic(err)
      }

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

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

      // Read response
      body, err := ioutil.ReadAll(resp.Body)
      if err != nil {
          panic(err)
      }

      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 ApiClient {
      private static final String LOGIC_API_TOKEN = "ls-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";

      public static void main(String[] args) {
          OkHttpClient client = new OkHttpClient();


          MediaType JSON = MediaType.get("application/json; charset=utf-8");
          String jsonBody = """
      {
        {YOUR INPUT JSON HERE}
      }
          """;

          RequestBody body = RequestBody.create(jsonBody, JSON);
          Request request = new Request.Builder()
              .url("https://api.logic.inc/v1/agents/{agent_id}/executions?useDynamicLearning=true")
              .post(body)
              .addHeader("Authorization", "Bearer " + LOGIC_API_TOKEN)

              .addHeader("Content-Type", "application/json")
              .build();

          try (Response response = client.newCall(request).execute()) {
              String responseBody = response.body().string();
              System.out.println(responseBody);
          } catch (IOException e) {
              e.printStackTrace();
          }
      }
  }
  ```
</CodeGroup>

<Note>
  Replace any **\{id}** in the example code, such as **\{agent\_id}** with the ID you need for your specific API call.
</Note>

## How to Isolate Dynamic Learning to a Specific Tenant

If you support multiple tenants or customers, you can scope learning behavior per tenant by adding a tenantId parameter.

<Info>
  Learn more about how to use the `tenantId` parameter in the [Tenant
  ID](/api-reference/execution-params/tenant-id) section.
</Info>
