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

# Python SDK: DeepResearch human review

> Add human-in-the-loop checkpoints to DeepResearch tasks in Python: answer planning questions, approve the research plan and respond to checkpoints in code.

Pause deep research at key decision points so a human can review and guide the agent.

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

> [!NOTE]
>
> For the conceptual overview, checkpoint shapes, and lifecycle, see the [HITL Guide](https://docs.valyu.ai/guides/deepresearch-hitl.md). This page is the Python SDK reference.

> [!WARNING]
>
> HITL is only available for individual deep research tasks, **not for batch requests**.

## Quick start

Enable a plan-review checkpoint and collect a real response before continuing. This terminal example approves the plan when the user presses Enter, or submits the requested changes.

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

client = Valyu()
task = client.deepresearch.create(
    query="Compare battery recycling companies operating in Europe",
    mode="standard",
    hitl={"plan_review": True},
)
if not task.success:
    raise RuntimeError(task.error)

def review_plan(interaction):
    if interaction.type != "plan_review":
        return None
    print(interaction.data)
    changes = input("Enter changes, or press Enter to approve: ").strip()
    if changes:
        return {"approved": False, "modifications": changes}
    return {"approved": True}

result = client.deepresearch.wait(
    task.deepresearch_id,
    on_interaction=review_plan,
)
if result.status == "completed":
    print(result.output)
else:
    print(result.status, result.error)
```

In a web application, persist the task and interaction IDs, show the checkpoint to the user, then call `respond()` when they submit their decision. Returning `None` from a callback leaves the checkpoint unanswered; it does not approve or dismiss it.

### Checkpoints

| Checkpoint | Phase | When it fires |
| - | - | - |
| `planning_questions` | Pre-research | Before research - clarifying questions for the user |
| `plan_review` | Pre-research | After planning - review the research plan |
| `source_review` | Post-research | After research - filter sources by domain |
| `outline_review` | Post-research | After source review - review the report outline |

Checkpoints fire in order; only enabled ones fire.

## Reference

> [accordion] Manual polling and respond()
>
> If you'd rather drive the loop yourself, poll `status()` and respond when `status.status` is `awaiting_input` or `paused`:
>
> ```python theme={null}
> import time
>
> while True:
>     status = client.deepresearch.status(task_id)
>
>     if status.status in ("awaiting_input", "paused"):
>         interaction = status.interaction
>         client.deepresearch.respond(
>             task_id,
>             interaction_id=interaction.interaction_id,
>             response=build_response(interaction),  # see checkpoint shapes below
>         )
>     elif status.status in ("completed", "failed", "cancelled"):
>         break
>
>     time.sleep(5)
> ```
>
> | Status | Meaning |
> | - | - |
> | `awaiting_input` | Checkpoint active, container held, fast resume |
> | `paused` | Checkpoint timed out (5 min), state saved, respond anytime |
> | `running` | Research or writing in progress |
> | `queued` | Re-enqueued after responding to a paused task |
>
> `respond()` returns `DeepResearchRespondResponse` with `success`, `status` (`"running"` or `"queued"`), `deepresearch_id`, `error`.

> [accordion] Checkpoint response shapes
>
> Each checkpoint expects a specific response dict:
>
> ```python theme={null}
> # planning_questions - interaction.data has {"questions": [{"question": ..., "context": ...}]}
> {"answers": [{"question": "What regions?", "answer": "North America and EU"}]}
>
> # plan_review - interaction.data has {"plan": ..., "estimated_steps": ..., "research_areas": [...]}
> {"approved": True}
> {"approved": False, "modifications": "Focus more on supply chain analysis"}
>
> # source_review - interaction.data has {"domains": [{"domain": ..., "ai_recommendation": ...}], "total_sources": ...}
> {"included_domains": ["sec.gov"], "excluded_domains": ["example.com"]}
> # Domains not listed fall back to the AI recommendation; pass [] to accept all recommendations.
>
> # outline_review - interaction.data has {"outline": ..., "sections": [...], "write_plan": {...}}
> # Each section has "title", "description", "estimated_length", and optional "weight", "depth" and "nodes".
> {"approved": True}
> {"approved": False, "modifications": "Add a regulatory risks section"}
> # To edit the outline, send the write_plan object from interaction.data with your changes (use respond()):
> {"write_plan": {"sections": [...], "exclude": [], "open_questions": []}}
> # The report uses the approved section titles as its main headings, in order.
> ```

> [accordion] Typed helpers
>
> ```python theme={null}
> client.deepresearch.respond_planning_questions(
>     task_id, interaction_id=...,
>     answers=[("What regions?", "North America and EU")],
> )
> client.deepresearch.approve_plan(task_id, interaction_id, modifications="...")     # omit modifications to approve
> client.deepresearch.respond_source_review(
>     task_id, interaction_id,
>     included_domains=["sec.gov"], excluded_domains=["example.com"],
> )
> client.deepresearch.approve_outline(task_id, interaction_id, modifications="...")  # omit to approve
> ```

> [accordion] HITL history and types
>
> After checkpoints complete, `status.hitl_history` records each interaction (`type`, `auto_continued`, `created_at`, `responded_at`, `response`):
>
> ```python theme={null}
> for entry in client.deepresearch.status(task_id).hitl_history or []:
>     print(entry.type, "auto_continued:", entry.auto_continued)
> ```
>
> | Type | Description |
> | - | - |
> | `HitlConfig` | Config with 4 optional boolean fields |
> | `InteractionType` | `planning_questions` \| `plan_review` \| `source_review` \| `outline_review` |
> | `Interaction` | Checkpoint payload: `interaction_id`, `type`, `data`, `created_at`, `timeout_ms` |
> | `InteractionHistoryEntry` | Completed checkpoint record |
> | `DeepResearchRespondResponse` | Response from `respond()` |


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