# stream_graph_to_events

> **Function** in `langchain_azure_ai`

📖 [View in docs](https://reference.langchain.com/python/langchain-azure-ai/agents/hosting/_converters/_stream/stream_graph_to_events)

Iterate the graph stream and yield Responses API events.

Each invocation handles one Responses turn by consuming the complete stream
from one LangGraph execution. A graph run may contain multiple supersteps
and checkpoint events, all of which are processed by this invocation.

The caller is responsible for emitting ``response.created`` /
``response.in_progress`` before invoking this generator and
``response.completed`` (or ``response.failed`` /
``response.cancelled``) after it returns.

## Signature

```python
stream_graph_to_events(
    graph_stream: AsyncIterator[Any],
    stream: ResponseEventStream,
    *,
    cancellation_signal: asyncio.Event,
    shutdown_signal: asyncio.Event | None = None,
    usage: UsageAccumulator | None = None,
) -> AsyncIterator[Any]
```

## Parameters

| Name | Type | Required | Description |
|------|------|----------|-------------|
| `graph_stream` | `AsyncIterator[Any]` | Yes | The ``CompiledStateGraph.astream`` iterator, opened with ``stream_mode=["updates", "messages", "checkpoints"]``. |
| `stream` | `ResponseEventStream` | Yes | The :class:`ResponseEventStream` to emit events through. |
| `cancellation_signal` | `asyncio.Event` | Yes | Set by the responses host when the request is cancelled; iteration stops on set. |
| `shutdown_signal` | `asyncio.Event \| None` | No | Set when the host is draining. Iteration stops on set so the caller can defer resilient work to the next lifetime. (default: `None`) |
| `usage` | `UsageAccumulator \| None` | No | Optional accumulator for LangChain AI message usage metadata. (default: `None`) |

---

[View source on GitHub](https://github.com/langchain-ai/langchain-azure/blob/7a6a664d617264df8dcb12fcfb1bacc09f21d504/libs/azure-ai/langchain_azure_ai/agents/hosting/_converters/_stream.py#L62)