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

# Review research before it continues

> Add human-in-the-loop checkpoints to DeepResearch so a user can answer planning questions, approve the plan or choose sources before the task continues.

Let a user approve the research plan, clarify scope or choose which sources to include before the task continues. These optional checkpoints are configured through `hitl` (human-in-the-loop). Enable only the decisions your user needs to make; an ordinary research task needs none.

> [!NOTE]
>
> HITL is for individual tasks only. It is **not available for batch requests**.

Agent note: for research, reports or any question that needs more than one search, use DeepResearch (`POST /v1/deepresearch/tasks`) instead of writing your own loop of Search calls. Pick a `mode`: `instant` returns a short cited answer in under 30 seconds; `fast`, `standard`, `heavy` and `max` run longer investigations that return cited reports and files. Use Search when your own model needs raw results to reason over. Docs index: [/llms.txt](https://docs.valyu.ai/llms.txt). Append `.md` to any page URL for Markdown. Docs MCP server: `https://docs.valyu.ai/mcp`. Integration guide for coding agents: [/AGENTS.md](https://docs.valyu.ai/AGENTS.md).

## Checkpoints

| Checkpoint | Phase | What happens |
| - | - | - |
| `planning_questions` | Pre-research | Agent asks clarifying questions before researching |
| `plan_review` | Pre-research | User reviews the research plan |
| `source_review` | Post-research | User filters sources by domain |
| `outline_review` | Post-research | User reviews the report outline |

Each pause sets the task status to `awaiting_input`. If you don't respond within 5 minutes it becomes `paused` (state saved) - you can still respond later to resume; the task re-enqueues at highest priority with a brief cold-start delay. If you resume more than 24 hours after the pause, the task needs enough available balance for its mode price when it restarts; otherwise it fails with an `Insufficient credits - ...` error and is not charged.

## Quick start

Pass an `on_interaction` callback to `wait()` to handle checkpoints. The example below shows the response shapes and automatically approves reviews. For human review, display the checkpoint in your application and submit the user's decision through the respond endpoint.

```python Python theme={null}
from valyu import Valyu

client = Valyu()

task = client.deepresearch.create(
    query="Analyze the competitive landscape of AI chip manufacturers",
    mode="heavy",
    hitl={"plan_review": True, "source_review": True},
)

def handle_interaction(interaction):
    if interaction.type in ("plan_review", "outline_review"):
        return {"approved": True}
    if interaction.type == "source_review":
        return {"included_domains": [], "excluded_domains": []}
    if interaction.type == "planning_questions":
        return {
            "answers": [
                {"question": q["question"], "answer": "Use your best judgment"}
                for q in interaction.data["questions"]
            ]
        }
    return None

result = client.deepresearch.wait(
    task.deepresearch_id,
    on_interaction=handle_interaction,
)
print(result.output)
```

```typescript TypeScript theme={null}
import Valyu from "valyu-js";

const client = new Valyu();

const task = await client.deepresearch.create({
  query: "Analyze the competitive landscape of AI chip manufacturers",
  mode: "heavy",
  hitl: { planReview: true, sourceReview: true },
});

const result = await client.deepresearch.wait(task.deepresearch_id!, {
  onInteraction: async (interaction) => {
    if (interaction.type === "plan_review" || interaction.type === "outline_review") {
      return { approved: true };
    }
    if (interaction.type === "source_review") {
      return { included_domains: [], excluded_domains: [] };
    }
    if (interaction.type === "planning_questions") {
      return {
        answers: interaction.data.questions.map((q: any) => ({
          question: q.question,
          answer: "Use your best judgment",
        })),
      };
    }
    return null;
  },
});

console.log(result.output);
```

```bash cURL theme={null}
# 1. Create task with HITL
curl -X POST https://api.valyu.ai/v1/deepresearch/tasks \
  -H "Content-Type: application/json" \
  -H "x-api-key: $VALYU_API_KEY" \
  -d '{
    "query": "Analyze the competitive landscape of AI chip manufacturers",
    "mode": "heavy",
    "hitl": { "planning_questions": true, "plan_review": true }
  }'

# 2. Poll status until "awaiting_input"
curl https://api.valyu.ai/v1/deepresearch/tasks/{id}/status \
  -H "x-api-key: $VALYU_API_KEY"

# 3. Respond to the checkpoint
curl -X POST https://api.valyu.ai/v1/deepresearch/tasks/{id}/respond \
  -H "Content-Type: application/json" \
  -H "x-api-key: $VALYU_API_KEY" \
  -d '{
    "interaction_id": "int_abc123",
    "response": {
      "answers": [{"question": "What geographic regions?", "answer": "North America and EU"}]
    }
  }'
```

Both SDKs also ship type-safe helpers: `respond_planning_questions()` / `respondPlanningQuestions()`, `approve_plan()` / `approvePlan()`, `respond_source_review()` / `respondSourceReview()`, and `approve_outline()` / `approveOutline()`. See the [Python](https://docs.valyu.ai/sdk/python-sdk/deepresearch-hitl.md) and [TypeScript](https://docs.valyu.ai/sdk/typescript-sdk/deepresearch-hitl.md) SDK references.

## Where checkpoints fire

**1. Query analysis**

The agent analyzes the query.

**2. planning\_questions**

**Pause:** clarifying questions before research starts. You answer to set scope.

**3. plan\_review**

**Pause:** review the research plan. Approve or request changes.

**4. Research execution**

The agent searches and reads sources.

**5. source\_review**

**Pause:** review sources grouped by domain. Include or exclude domains.

**6. outline\_review**

**Pause:** review the report outline. Approve or request structural changes.

**7. Report writing**

The agent writes the final report and the task completes.

## Checkpoint response shapes

When status is `awaiting_input`, `status.interaction.data` holds the checkpoint payload and you reply with a matching `response`.

> [accordion] planning\_questions
>
> The agent asks questions; you answer them.
>
> ```json theme={null}
> // interaction.data
> { "questions": [
>   { "question": "What geographic regions should the research focus on?" },
>   { "question": "Are there specific competitors you want analyzed?" }
> ] }
>
> // response
> { "answers": [
>   { "question": "What geographic regions?", "answer": "North America and EU" },
>   { "question": "Specific competitors?", "answer": "Tesla, BYD, Rivian" }
> ] }
> ```
>
> `answers` is required: an array of `{ question, answer }` strings.

> [accordion] plan\_review
>
> Approve, or reject with free-text guidance.
>
> ```json theme={null}
> // approve
> { "approved": true }
>
> // request modifications
> { "approved": false, "modifications": "Focus more on supply chain analysis" }
> ```
>
> `approved` (boolean) is required; `modifications` (string) is optional free-text guidance for the model. `interaction.data` contains the `plan` for you to display.

> [accordion] outline\_review
>
> `interaction.data` holds the proposed outline of the report:
>
> | Field | Type | Description |
> | - | - | - |
> | `outline` | string | The outline as numbered lines. A short description follows each title. |
> | `sections` | array | The sections, in report order. |
> | `write_plan` | object | The same outline as an object that you can edit and send back. |
>
> Each item in `sections` has these fields:
>
> | Field | Type | Description |
> | - | - | - |
> | `title` | string | The section heading. |
> | `description` | string | One sentence on what the section covers. |
> | `estimated_length` | string | `short`, `medium` or `long`. |
> | `weight` | integer | Optional. Relative importance, from 1 to 5. |
> | `depth` | string | Optional. `brief`, `standard` or `deep`. |
> | `nodes` | integer | Optional. The number of research topics that supply evidence for the section. |
>
> ```json theme={null}
> // interaction.data
> {
>   "outline": "1. Launch history - When each probe flew and on which rocket.\n2. Science targets - Which moons each probe studies and why.",
>   "sections": [
>     { "title": "Launch history", "description": "When each probe flew and on which rocket.", "estimated_length": "short", "weight": 2, "depth": "brief", "nodes": 1 },
>     { "title": "Science targets", "description": "Which moons each probe studies and why.", "estimated_length": "long", "weight": 4, "depth": "deep", "nodes": 1 }
>   ],
>   "write_plan": {
>     "sections": [
>       { "title": "Launch history", "description": "When each probe flew and on which rocket.", "estimated_length": "short", "weight": 2, "depth": "brief", "nodes": ["n_00"] },
>       { "title": "Science targets", "description": "Which moons each probe studies and why.", "estimated_length": "long", "weight": 4, "depth": "deep", "nodes": ["n_00"] }
>     ],
>     "exclude": [],
>     "open_questions": []
>   }
> }
> ```
>
> If the outline cannot be prepared, `sections` holds one section with the title `Report`. The task still pauses, and then writes the report as usual.
>
> You have three ways to reply:
>
> ```json theme={null}
> // approve the outline as shown
> { "approved": true }
>
> // describe changes in text
> { "approved": false, "modifications": "Add a section on regulatory risks after Science targets" }
>
> // send an edited outline
> { "write_plan": { "sections": [ ... ], "exclude": [], "open_questions": [] } }
> ```
>
> | Field | Type | Required | Description |
> | - | - | - | - |
> | `approved` | boolean | Yes, unless you send `write_plan` | `true` approves the outline as shown. |
> | `modifications` | string | No | Written changes to the outline. The report follows the outline and then applies these changes. Maximum 8,000 characters. |
> | `write_plan` | object | No | The edited outline. It replaces the proposed outline. |
>
> To edit the outline in a structured way, send the `write_plan` object from the review data with your changes. Each item in `write_plan.sections` has these fields:
>
> | Field | Type | Required | Description |
> | - | - | - | - |
> | `title` | string | Yes | The section heading. |
> | `nodes` | array of strings | Yes | The research topics that supply evidence. Copy the values from the review data. At least one. |
> | `weight` | integer | Yes | From 1 to 5. |
> | `depth` | string | Yes | `brief`, `standard` or `deep`. |
> | `description` | string | No | One sentence on what the section covers. Maximum 400 characters. |
> | `estimated_length` | string | No | `short`, `medium` or `long`. |
> | `must_cite` | array of strings | No | Documents that the section must cite. |
>
> `write_plan` also has the fields `exclude` (documents to leave out, each as `{ "id", "reason" }`) and `open_questions` (an array of strings). You must send both. Send `[]` if you have nothing to add.
>
> If the edited `write_plan` is not valid (for example, a section has no evidence), the task uses the proposed outline.
>
> > [!NOTE]
> >
> > The report uses the approved section titles as its main headings, in the same order.

> [accordion] source\_review
>
> `interaction.data` lists sources grouped by `domain` with a `source_count`, `avg_relevance_score`, and an `ai_recommendation` of `include` or `exclude`. You reply with explicit include/exclude lists.
>
> ```json theme={null}
> {
>   "included_domains": ["sec.gov", "plos.org"],
>   "excluded_domains": ["example.com"]
> }
> ```
>
> Both arrays are required but may be empty. Domains you don't list fall back to the AI recommendation.

## Manual polling and the respond endpoint

If you poll yourself instead of using `wait()`, watch for `awaiting_input` (or `paused`), then POST your response:

```
POST /v1/deepresearch/tasks/:id/respond
{ "interaction_id": "<must match status.interaction.interaction_id>", "response": { ... } }
```

| Code | Meaning |
| - | - |
| `200` | Accepted - `{ "success": true, "status": "running" \| "queued" }` |
| `400` | Validation error (bad response shape) |
| `409` | Wrong status or `interaction_id` mismatch. Also `Task is no longer paused.` if the task was cancelled while you were resuming it |

> [accordion] Status values and interaction fields
>
> | Status | Meaning |
> | - | - |
> | `awaiting_input` | Checkpoint active, container held, fast resume on response |
> | `paused` | Checkpoint timed out (5 min), state saved, respond later to resume |
> | `running` | Research or writing in progress |
> | `queued` | Re-enqueued after responding to a paused task |
>
> When HITL is enabled, the status response also carries `hitl_config` (mirrors the request), `interaction` (present while `awaiting_input`/`paused`), and `hitl_history` (one entry per completed checkpoint with `interaction_id`, `type`, `created_at`, `responded_at`, `auto_continued`, and `response`).

## Best practices

* **Poll faster around checkpoints** - 2-3s when expecting input, 5-10s during research phases.
* **Handle both `awaiting_input` and `paused`** - the UX is identical, only resume speed differs.
* **Enable selectively** - each checkpoint adds latency equal to the user's response time.
* **Review decisions that matter** - enable checkpoints where user input can change scope, sources or report structure. Choose the research mode separately.

## Next steps

Use [the application guide](https://docs.valyu.ai/guides/research-in-your-application.md) to persist task IDs and display waiting states. For every request and response field, see the [Python](https://docs.valyu.ai/sdk/python-sdk/deepresearch-hitl.md) or [TypeScript](https://docs.valyu.ai/sdk/typescript-sdk/deepresearch-hitl.md) reference.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.