# create_analyst_subgraph

> **Function** in `langchain_azure_ai`

📖 [View in docs](https://reference.langchain.com/python/langchain-azure-ai/evaluation/helpers/create_analyst_subgraph)

Build a compiled analyst subgraph with embedded eval-optimize loop.

Creates a LangGraph ``StateGraph`` for a specialist analyst:
research → write → eval-optimize (subgraph) → build_completed.

The eval-optimize loop is invoked as a subgraph with a different
state schema, demonstrating the parent→child→grandchild pattern
with state transformation.

## Signature

```python
create_analyst_subgraph(
    *,
    research_fn: Callable[[Any], dict[str, Any]],
    write_fn: Callable[[Any], dict[str, Any]],
    eval_optimize_graph: Any,
    build_completed_fn: Callable[[Any], dict[str, Any]],
    state_schema: type,
    max_iterations: int = 3,
    state_to_eval_input: Callable[[dict[str, Any], int], dict[str, Any]] | None = None,
    eval_output_to_state: Callable[[dict[str, Any], dict[str, Any]], dict[str, Any]] | None = None,
) -> Any
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `research_fn` | `Callable[[Any], dict[str, Any]]` | Yes | Node that gathers research data. |
| `write_fn` | `Callable[[Any], dict[str, Any]]` | Yes | Node that writes the section draft. |
| `eval_optimize_graph` | `Any` | Yes | Compiled eval-optimize subgraph. |
| `build_completed_fn` | `Callable[[Any], dict[str, Any]]` | Yes | Node that packages final output. |
| `state_schema` | `type` | Yes | The analyst TypedDict state. |
| `max_iterations` | `int` | No | Safety limit passed to the eval-optimize subgraph. (default: `3`) |
| `state_to_eval_input` | `Callable[[dict[str, Any], int], dict[str, Any]] \| None` | No | Optional callback that maps the analyst state to the eval-optimize subgraph input. When omitted, the helper uses the conventional analyst state keys ``section``, ``draft_content``, ``evaluation_feedback``, ``evaluation_result``, ``accepted``, ``iteration``/``iteration_count``, and ``max_iterations``. ``section`` may be either a mapping or an object with ``area`` and ``title`` attributes. (default: `None`) |
| `eval_output_to_state` | `Callable[[dict[str, Any], dict[str, Any]], dict[str, Any]] \| None` | No | Optional callback that maps the eval-optimize output back into analyst state updates. When omitted, the helper returns ``draft_content``, ``evaluation_result``, and ``iteration_count`` updates. (default: `None`) |

## Returns

`Any`

A compiled LangGraph ``StateGraph``.

---

[View source on GitHub](https://github.com/langchain-ai/langchain-azure/blob/7a6a664d617264df8dcb12fcfb1bacc09f21d504/libs/azure-ai/langchain_azure_ai/evaluation/helpers.py#L138)