Stateful Responses API on TPU¶
Use this guide when agentic clients or coding harnesses speak the OpenAI Responses API (/v1/responses) and expect state: conversations continued by previous_response_id, webhook tool loops, WebSocket streaming. The router and vLLM are stateless, so vLLM Agentic API (vllm/agentic-api) sits in front of the router, persists each response in PostgreSQL 17 and rehydrates the conversation; every round it sends on is a stateless request the router places by prefix and load. The path is experimental. Its own model server overlay is NVIDIA GPU only, so on TPU you layer agentic-api onto a TPU guide you already run, which the upstream page documents. Chapter 19 and chapter 20 explain why agent turns reward prefix reuse.
The client sends only the new turn and a previous_response_id; agentic-api rebuilds the conversation from PostgreSQL and sends the router an ordinary stateless request, which the router places by prefix and load like any other.
Prerequisites¶
-
A TPU guide already deployed with vLLM whose overlay sets
--enable-auto-tool-choiceand the parsers for its model. The upstream table lists these TPU overlays as already setting them:Model Flags Overlay Qwen/Qwen3-32B--enable-auto-tool-choice --tool-call-parser=hermes --reasoning-parser=qwen3P/D disaggregation tpu/v6Qwen/Qwen3.5-397B-A17B-FP8--enable-auto-tool-choice --tool-call-parser=qwen3_xml --reasoning-parser=qwen3P/D disaggregation tpu/v7Qwen/Qwen3-Coder-480B-A35B-Instruct-FP8--enable-auto-tool-choice --tool-call-parser=qwen3_xmlP/D disaggregation tpu/v7-dynamic-sliceThe llm-d P/D disaggregation guide names
--tool-call-parser=qwen3_coderfor the same TPU7x overlay, so the two pages differ; read the flag in your overlay before relying on either. The same table says the tiered-prefix-cache overlay for Qwen3-32B omits them; add them to thevllm servearguments before deploying such a guide. A wrong parser is worse than none: vLLM starts and then parses tool calls with the wrong grammar. - The model server must serve/v1/responses. On the TPU overlays (vLLM 0.29) the precise-routing guide lists/v1/responseswith only a legacy render fallback; the verification script below tests the endpoint end to end. - A default StorageClass for the PostgreSQL PVC (1 GiB,ReadWriteOnce), plusenvsubst,openssland Python 3 on your machine.
Steps¶
1. Point the guide at the existing router¶
From the llm-d repository root, set the target guide's namespace, router Service (named after its Helm release) and model. For the TPU7x P/D deployment:
export REPO_ROOT=$(realpath $(git rev-parse --show-toplevel))
export GUIDE_NAME=agentic-api
export NAMESPACE=llm-d-pd-disaggregation
export LLM_API_BASE=pd-disaggregation-epp.${NAMESPACE}.svc.cluster.local:80
export MODEL=Qwen/Qwen3.5-397B-A17B-FP8
source ${REPO_ROOT}/guides/env.sh
Check: kubectl get service pd-disaggregation-epp -n ${NAMESPACE} exists.
2. Create the PostgreSQL credentials¶
if ! kubectl get secret agentic-api-postgres -n ${NAMESPACE} >/dev/null 2>&1; then
PGPASS=$(openssl rand -hex 16)
kubectl create secret generic agentic-api-postgres -n ${NAMESPACE} \
--from-literal=password="${PGPASS}" \
--from-literal=database-url="postgres://postgres:${PGPASS}@agentic-api-postgres:5432/agentic_api"
fi
The password exists only in the Secret; a rerun reuses it so it stays in sync with an initialized PVC.
Check: kubectl get secret agentic-api-postgres -n ${NAMESPACE} exists.
3. Deploy PostgreSQL and agentic-api¶
kubectl apply -n ${NAMESPACE} -f ${REPO_ROOT}/guides/${GUIDE_NAME}/manifests/postgres.yaml
kubectl rollout status -n ${NAMESPACE} deployment/agentic-api-postgres --timeout=120s
kubectl kustomize ${REPO_ROOT}/guides/${GUIDE_NAME}/manifests/base \
| envsubst '${LLM_API_BASE}' \
| kubectl apply -n ${NAMESPACE} -f -
kubectl rollout status -n ${NAMESPACE} deployment/agentic-api --timeout=120s
Check: both rollout status commands report success.
4. Send a request and continue it¶
kubectl port-forward --address 127.0.0.1 -n ${NAMESPACE} svc/agentic-api 9000:9000 &
PF_PID=$!
sleep 3
kill -0 ${PF_PID}
export AGENTIC_API_BASE_URL=http://127.0.0.1:9000
curl -sS -X POST ${AGENTIC_API_BASE_URL}/v1/responses \
-H "Content-Type: application/json" \
-d "{\"model\": \"${MODEL}\", \"input\": \"How are you today?\"}"
Check: the response is a response object whose id starts with resp_. Pass it as previous_response_id on the next request to continue without resending the history.
5. Verify state and tool loops¶
python3 ${REPO_ROOT}/guides/${GUIDE_NAME}/verify.py --base-url ${AGENTIC_API_BASE_URL}
kill ${PF_PID:-} 2>/dev/null || true
The script (standard library only) discovers the model from /v1/models and runs four tests: [1/4] health and model discovery; [2/4] a stored turn followed by a request carrying only previous_response_id; [3/4] a webhook tool loop, which fails, and says so, when the model server lacks the tool-calling flags; [4/4] WebSocket streaming (--skip-websocket behind an HTTP-only proxy).
Check: all four tests pass.
6. Clean up agentic-api only¶
kubectl kustomize ${REPO_ROOT}/guides/${GUIDE_NAME}/manifests/base \
| envsubst '${LLM_API_BASE}' \
| kubectl delete -n ${NAMESPACE} -f - --ignore-not-found=true
kubectl delete -n ${NAMESPACE} -f ${REPO_ROOT}/guides/${GUIDE_NAME}/manifests/postgres.yaml --ignore-not-found=true
kubectl delete secret agentic-api-postgres -n ${NAMESPACE} --ignore-not-found=true
The PVC goes with the manifest; the PV follows its StorageClass reclaim policy. The underlying guide stays as it was.
Check: kubectl get deployment agentic-api -n ${NAMESPACE} reports NotFound.
Troubleshooting¶
| Symptom | Cause | Fix |
|---|---|---|
verify.py [3/4] fails |
Model server started without --enable-auto-tool-choice and parsers |
Add them to the overlay's vllm serve arguments and redeploy that guide |
| Tool calls parsed as garbage | Wrong parser for the model's chat template | XML-style templates (Qwen3.5, Qwen3-Coder) need an XML parser, not hermes |
| Follow-up turn has no memory | PostgreSQL Secret out of sync with an existing PVC | Keep the Secret across reruns; the creation step reuses it |
agentic-api cannot reach the router |
LLM_API_BASE names the wrong Service or namespace |
<release>-epp.<namespace>.svc.cluster.local:80 |
[4/4] fails behind a proxy |
HTTP-only proxy blocks the WebSocket upgrade | --skip-websocket |
