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

# Generate AI Answer

> Generate an answer grounded in memory by querying the agent's context and synthesizing an LLM response.

## Overview

Answer questions using stored agent memories. This operation retrieves relevant context from the agent's Moorcheh namespace (scoped by the active session) and calls Moorcheh **answer generation** to produce a grounded reply.

## Authentication

API clients do not send an API key or `Authorization` header.

<ParamField header="X-Session-Token" type="string" required>
  Session token from [Activate Agent](/api-reference/sessions/activate-agent). Must match `agent_id`.
</ParamField>

<ParamField header="Content-Type" type="string" required>
  Must be `application/json`
</ParamField>

## Path Parameters

<ParamField path="agent_id" type="string" required>
  The unique identifier of the agent.
</ParamField>

## Body

<ParamField body="question" type="string" required>
  The question to answer using retrieved memories as context.
</ParamField>

<ParamField body="limit" type="integer">
  Maximum memories to use as context (`top_k`). Range `1`–`100`. If omitted, the server default applies (see deployment configuration).
</ParamField>

<ParamField body="temperature" type="number">
  LLM temperature, `0.0`–`2.0`. If omitted, the server default applies.
</ParamField>

<ParamField body="ai_model" type="string">
  Model identifier for answer generation (snake\_case field name: `ai_model`). If omitted, the server default applies.
</ParamField>

<ParamField body="kiosk_mode" type="boolean">
  When `true`, relevance filtering uses a confidence threshold. When `false` (default), **`threshold` is ignored** and not sent to Moorcheh.
</ParamField>

<ParamField body="threshold" type="number">
  Confidence threshold (`0.0`–`1.0`). **Only used when `kiosk_mode` is `true`.** If `kiosk_mode` is `true` and `threshold` is omitted, the server uses **0.15**.
</ParamField>

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST "http://localhost:8000/api/v2/agents/my-agent/answer" \
    -H "X-Session-Token: your_session_token" \
    -H "Content-Type: application/json" \
    -d '{
      "question": "How should we contact the user?",
      "limit": 5,
      "temperature": 0.7,
      "ai_model": "anthropic.claude-sonnet-4-6",
      "kiosk_mode": false
    }'
  ```

  ```bash cURL (kiosk mode with default threshold 0.15) theme={null}
  curl -X POST "http://localhost:8000/api/v2/agents/my-agent/answer" \
    -H "X-Session-Token: your_session_token" \
    -H "Content-Type: application/json" \
    -d '{
      "question": "How should we contact the user?",
      "kiosk_mode": true
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json 200 - OK theme={null}
  {
    "agent_id": "my-agent",
    "session_id": "sess_123abc",
    "question": "How should we contact the user?",
    "answer": "Based on stored preferences, the user prefers email communication. Send email during business hours.",
    "sources": [
      {
        "id": "3e681f12-a28c-4d1d-9632-b8dadf1f9d0c",
        "score": 0.86
      }
    ],
    "namespace": "memanto_agent_my-agent"
  }
  ```

  ```json 401 - Unauthorized (Missing Token) theme={null}
  {
    "detail": "Missing session token. Use X-Session-Token header."
  }
  ```

  ```json 401 - Unauthorized (Expired Token) theme={null}
  {
    "detail": {
      "error": "SessionExpired",
      "message": "Session has expired",
      "details": {}
    }
  }
  ```

  ```json 422 - Validation Error theme={null}
  {
    "detail": [
      {
        "type": "missing",
        "loc": [
          "body",
          "question"
        ],
        "msg": "Field required",
        "input": {}
      }
    ]
  }
  ```

  ```json 500 - Server Error theme={null}
  {
    "detail": {
      "error": "InternalServerError",
      "message": "An unexpected error occurred",
      "details": {
        "original_error": "Session is for agent 'other-agent', cannot access 'my-agent'"
      }
    }
  }
  ```

  ```json 413 - Payload Too Large (Question Too Long) theme={null}
  {
    "detail": {
      "error": "query_too_long",
      "message": "Query exceeds maximum length of 1000 characters",
      "actual_length": 1500,
      "max_length": 1000
    }
  }
  ```

  ```json 400 - Bad Request (Limit Too Large) theme={null}
  {
    "detail": {
      "error": "k_too_large",
      "message": "k exceeds maximum of 100",
      "actual_k": 200,
      "max_k": 100
    }
  }
  ```
</ResponseExample>

<Snippet file="temperature.mdx" />

## Available Models

<Snippet file="available-models.mdx" />

## Next Steps

* [Recall](/api-reference/search/recall) to fetch raw memories without generating an AI answer
* [Remember](/api-reference/data/remember) to add more context to the agent
