From e3315828169c94baa153646f30cb1ba321979eb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Sch=C3=A4ublin?= <11610660+bschaeublin@users.noreply.github.com> Date: Tue, 13 Oct 2026 21:48:11 +0200 Subject: [PATCH] Python: Filter caller options in hosting-responses README example The README route passed every caller-supplied Responses body field from responses_to_run() straight to agent.run(). Apps copying it let callers set tools, instructions, or additional_function_arguments, which override app-owned tool kwargs. Allowlist request options the same way the local_responses samples already do. Co-Authored-By: Claude Opus 5.5 --- python/packages/hosting-responses/README.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/python/packages/hosting-responses/README.md b/python/packages/hosting-responses/README.md index 0e06858dc1c..68d6d4b88f7 100644 --- a/python/packages/hosting-responses/README.md +++ b/python/packages/hosting-responses/README.md @@ -51,6 +51,9 @@ from fastapi.responses import JSONResponse app = FastAPI() state = AgentState(agent) +# Request options are caller-controlled; pass through only the ones this route honors. +ALLOWED_REQUEST_OPTIONS = frozenset({"max_tokens", "reasoning"}) + @app.post("/responses") async def responses(body: dict = Body(...)) -> JSONResponse: @@ -58,10 +61,11 @@ async def responses(body: dict = Body(...)) -> JSONResponse: session_id, is_conversation_id = responses_session_id(body) response_id = create_response_id() session = await state.get_or_create_session(session_id or response_id) + options = {key: value for key, value in run["options"].items() if key in ALLOWED_REQUEST_OPTIONS} result = await (await state.get_target()).run( run["messages"], session=session, - options=run["options"], + options=options, ) if is_conversation_id: # The app must serialize writers that advance this stable id.