InvocationsHostServer(
self,
graph: Runnable[GraphInputT, GraphOutputT],
*,
output_parser: Optional| Name | Type | Description |
|---|---|---|
graph* | Runnable[GraphInputT, GraphOutputT] | The runnable to host. The default converters expect a
LangGraph-style messages state input and output. Pass
|
| Name | Type |
|---|---|
| graph | Runnable[GraphInputT, GraphOutputT] |
| output_parser | Optional[InvocationOutputParser[GraphOutputT]] |
| options | Optional[ResponsesServerOptions] |
| app | Optional[InvocationAgentServerHost] |
| applicationinsights_connection_string | Optional[str] |
| graceful_shutdown_timeout | Optional[int] |
Host a LangChain Runnable as the Invocations API.
Example:
Create an agent graph with a checkpointer and host it on
POST /invocations::
import os
from langchain.agents import create_agent
from langchain_openai import ChatOpenAI
from langgraph.checkpoint.memory import MemorySaver
from langchain_azure_ai.agents.hosting import InvocationsHostServer
model = ChatOpenAI(
model=os.environ.get("AZURE_AI_MODEL_DEPLOYMENT_NAME", "gpt-4o"),
)
graph = create_agent(model, tools=[], checkpointer=MemorySaver())
InvocationsHostServer(graph).run(port=8088)
The host maps agent_session_id to a user-partitioned internal
RunnableConfig.configurable.thread_id so follow-up turns continue
the same checkpointed conversation without colliding across users.
.. code-block:: json
{ "message": "Hello!", "stream": false }
Where:
- ``message`` (required) — user message text, or a non-empty list containing
a Responses-style ``function_call_output`` / ``mcp_approval_response``
item that answers a pending LangGraph interrupt.
stream (optional, default false) — when true returns SSE
with token deltas; when false returns a single JSON response.
background (optional, default false) — when true starts a
durable invocation and returns 202. Requires
options.resilient_background=True and a LangGraph checkpointer.previous_invocation_id (optional) — linear-chain precondition for a
continued agent_session_id.Pending LangGraph interrupts are exposed beside response as the same
paired function_call and mcp_approval_request output items used by
:class:ResponsesHostServer. Streaming requests emit each item as an
output_item SSE event.
Multi-turn continuation uses the agent_session_id query param /
x-agent-session-id header populated by
:class:InvocationAgentServerHost. The public session id remains in the
API envelope, while task and LangGraph state use an internal id derived
from the user partition and session id.