diff --git a/python/DEV_SETUP.md b/python/DEV_SETUP.md index 6d06fb025a0..824f5406058 100644 --- a/python/DEV_SETUP.md +++ b/python/DEV_SETUP.md @@ -2,7 +2,7 @@ This document describes how to setup your environment with Python and uv, if you're working on new features or a bug fix for Agent Framework, or simply -want to run the tests included. +want to run the tests included. All commands shown here assume your terminal is opened in the "python" folder of your clone, where this file is located. For coding standards and conventions, see [CODING_STANDARD.md](CODING_STANDARD.md). @@ -61,7 +61,7 @@ The exact supported uv version is declared by `required-version` in `pyproject.toml`. uv will stop with an actionable error when the installed version does not match. -You can then run the following commands manually: +You can then run the following commands manually in a terminal opened in the "python" folder of your clone: ```bash # Install every Python version covered by CI @@ -69,6 +69,7 @@ uv python install 3.11 3.12 3.13 3.14 3.15 # Use Python 3.11 through 3.14 for a full-workspace development environment PYTHON_VERSION="3.13" uv venv --python $PYTHON_VERSION +# Activate your virtual environment per console instructions # Install AF and all workspace dependencies uv run poe install # Install prek hooks diff --git a/python/packages/foundry_hosting/README.md b/python/packages/foundry_hosting/README.md index 068188eb61f..6e8cea3c65a 100644 --- a/python/packages/foundry_hosting/README.md +++ b/python/packages/foundry_hosting/README.md @@ -256,13 +256,25 @@ official `azure-ai-agentserver-core` wheel, the minimum dependency and `uv.lock` concurrent queue-overflow regression proves rejected turns leave no pending futures. No future SDK version is assumed. Non-steerable background polling and legacy `WorkflowAgent` dispatch are unchanged. -Native CreateResponse generation fields become MAF runtime options (notably `max_output_tokens` -> `max_tokens` and -`parallel_tool_calls` -> `allow_multiple_tool_calls`). Flattened OpenAI `extra_body` fields overlay translated keys -**last**. A sync or async `prepare_options(request: HostedResponseRequest, options: dict)` hook can remove or replace -*caller* options before `Agent.run`; removed values fall back to the developer's unchanged agent defaults. Hosting -filters caller platform IDs and private continuation/storage controls from model options and rejects attempts to -reintroduce them through the hook. Nested `extra_body` transport overrides are rejected for both caller -input and developer hooks, because they could override the host's `store=False` after the OpenAI SDK merges +Allowed native CreateResponse generation fields become MAF runtime options (notably `max_output_tokens` -> +`max_tokens` and `parallel_tool_calls` -> `allow_multiple_tool_calls`). Caller-supplied top-level fields and +`extra_body` keys are checked against separate, hard-coded default allowlists, exposed as the read-only +`DEFAULT_CALLER_ALLOWED_FIELDS` and `DEFAULT_CALLER_ALLOWED_EXTRA_BODY_FIELDS` constants. Unlisted fields are rejected +even when their value is `null`, unless an author explicitly opts them in through `prepare_options`, so the constants +describe the default policy rather than every field an application accepts. Future releases may add fields; removing +one is a breaking change. These allowlists check field names, not arbitrary values or nested contents of allowed +fields. Allowed, flattened `extra_body` options overlay translated keys **last**, before the hook. + +A sync or async `prepare_options(request: HostedResponseRequest, options: dict)` hook can inspect a copy of the original +request, remove or replace caller options, or opt an unlisted caller field in by returning it as a run option. Validate +any caller-derived value before returning it; use trusted application or platform data for trusted context. Removed +options fall back to the developer's unchanged agent defaults. The hook is supported for regular agents and native +workflows, but not for legacy `WorkflowAgent` hosting. Requests rejected by this field policy do not run the agent or +workflow; a rejected approval resume leaves the pending approval usable. + +Hosting filters caller platform IDs and private continuation/storage controls from model options and rejects attempts +to reintroduce them through the hook. Nested `extra_body` transport overrides are rejected for both caller input and +developer hooks, because they could override the host's `store=False` after the OpenAI SDK merges the body. Developer defaults also cannot use this transport channel for host-controlled fields on explicit history modes or unstored requests. A custom agent cannot accept MAF runtime options: choose `unsupported_options` as `"ignore"`, `"warn"` (default), or `"error"` for that case. See the diff --git a/python/packages/foundry_hosting/agent_framework_foundry_hosting/__init__.py b/python/packages/foundry_hosting/agent_framework_foundry_hosting/__init__.py index cd37bfcf691..deb8efc99c5 100644 --- a/python/packages/foundry_hosting/agent_framework_foundry_hosting/__init__.py +++ b/python/packages/foundry_hosting/agent_framework_foundry_hosting/__init__.py @@ -5,7 +5,14 @@ if TYPE_CHECKING: from ._invocations import InvocationsHostServer - from ._request import HostedResponseRequest, InvocationRun, WorkflowTurn, response_input_messages + from ._request import ( + DEFAULT_CALLER_ALLOWED_EXTRA_BODY_FIELDS, + DEFAULT_CALLER_ALLOWED_FIELDS, + HostedResponseRequest, + InvocationRun, + WorkflowTurn, + response_input_messages, + ) from ._responses import ResponsesHostServer from ._scope import FoundryRequestScope from ._state_store import ( @@ -31,6 +38,8 @@ "AgentSessionStoreProvider": "._state_store", "CheckpointStoreProvider": "._state_store", "ContextScopedStoreProvider": "._state_store", + "DEFAULT_CALLER_ALLOWED_EXTRA_BODY_FIELDS": "._request", + "DEFAULT_CALLER_ALLOWED_FIELDS": "._request", "FoundryAgentSessionStore": "._state_store", "FoundryCheckpointStore": "._state_store", "FoundryFunctionApprovalStore": "._state_store", @@ -49,6 +58,8 @@ } __all__ = [ + "DEFAULT_CALLER_ALLOWED_EXTRA_BODY_FIELDS", + "DEFAULT_CALLER_ALLOWED_FIELDS", "AgentSessionStoreProvider", "CheckpointStoreProvider", "ContextScopedStoreProvider", diff --git a/python/packages/foundry_hosting/agent_framework_foundry_hosting/_request.py b/python/packages/foundry_hosting/agent_framework_foundry_hosting/_request.py index 335658f276f..73fc1dc7769 100644 --- a/python/packages/foundry_hosting/agent_framework_foundry_hosting/_request.py +++ b/python/packages/foundry_hosting/agent_framework_foundry_hosting/_request.py @@ -9,7 +9,7 @@ from copy import deepcopy from dataclasses import dataclass, field from types import MappingProxyType -from typing import Any, Generic, Literal, TypeAlias, cast +from typing import Any, Final, Generic, Literal, TypeAlias, cast from agent_framework import AgentRunInputs, Content, Message, WorkflowInvocationKwargs from azure.ai.agentserver.responses import ResponseContext @@ -94,6 +94,50 @@ def __post_init__(self) -> None: raise TypeError("InvocationRun.stream must be a boolean.") +DEFAULT_CALLER_ALLOWED_FIELDS: Final[frozenset[str]] = frozenset({ + "agent_session_id", + "agent_reference", + "background", + "conversation", + "extra_body", + "include", + "input", + "max_output_tokens", + "metadata", + "model", + "parallel_tool_calls", + "previous_response_id", + "reasoning", + "store", + "stream", + "temperature", + "text", + "top_p", + "user", +}) +"""Top-level Responses request fields callers may set by default. + +``prepare_options`` can opt in additional fields per request, so this set describes the default policy rather than +every field an application accepts. Future releases may add fields; removing one is a breaking change. +""" + +DEFAULT_CALLER_ALLOWED_EXTRA_BODY_FIELDS: Final[frozenset[str]] = frozenset({ + "allow_multiple_tool_calls", + "max_output_tokens", + "max_tokens", + "model", + "parallel_tool_calls", + "reasoning", + "temperature", + "text", + "top_p", +}) +"""Keys callers may set inside a Responses request's ``extra_body`` by default. + +``prepare_options`` can opt in additional keys per request, so this set describes the default policy rather than +every key an application accepts. Future releases may add keys; removing one is a breaking change. +""" + _HOST_CONTROLLED_FIELDS = frozenset({ "agent", "agent_reference", @@ -114,15 +158,61 @@ def __post_init__(self) -> None: "user", "user_id", }) +"""Fields protected at caller-option and agent-default transport boundaries. + +Some are allowed in outer requests but are not forwarded as caller options; hooks cannot return them. +The agent-default ``extra_body`` check also uses this set; it may permit ``store`` for agent-managed storage. +""" + _OPTION_NAMES = {"max_output_tokens": "max_tokens", "parallel_tool_calls": "allow_multiple_tool_calls"} +"""Map Responses request names to Agent Framework run-option names. + +Applied to allowed top-level and ``extra_body`` fields before the latter take precedence. +""" + _NATIVE_FIELDS = frozenset(CreateResponse.__annotations__) +def reject_disallowed_caller_fields(request: CreateResponse, options: Mapping[str, Any]) -> None: + """Reject caller fields not allowed by the default policy or explicitly returned by the developer hook. + + The hook can opt an individual caller field into the run options by returning it. Host-controlled + fields remain protected by ``validate_request_options``. + + Raises: + TypeError: If ``extra_body`` is not a mapping of string keys. + ValueError: If a caller field is not allowed. + """ + returned_fields = set(options) + rejected = set(request).difference(DEFAULT_CALLER_ALLOWED_FIELDS).difference(returned_fields) + extra_body = request.get("extra_body") + if extra_body is not None: + if not isinstance(extra_body, Mapping) or any( + not isinstance(key, str) for key in cast(Mapping[object, object], extra_body) + ): + raise TypeError("extra_body must be a mapping of model options.") + rejected.update( + f"extra_body.{name}" + for name in cast(Mapping[str, Any], extra_body) + if name not in DEFAULT_CALLER_ALLOWED_EXTRA_BODY_FIELDS and name not in returned_fields + ) + if rejected: + raise ValueError( + f"Responses requests cannot set fields that are not in the caller allowlist: {', '.join(sorted(rejected))}." + ) + + def response_run_options(request: CreateResponse) -> dict[str, Any]: - """Translate native generation fields, with flattened extra-body values winning collisions.""" + """Translate allowed native generation fields, with flattened extra-body values winning collisions.""" native: dict[str, Any] = {} - extra: dict[str, Any] = {} nested_extra: dict[str, Any] = {} + unlisted_option_names = set(request).difference(DEFAULT_CALLER_ALLOWED_FIELDS) + extra_body = request.get("extra_body") + if isinstance(extra_body, Mapping): + for field_name in cast(Mapping[object, object], extra_body): + if isinstance(field_name, str) and field_name not in DEFAULT_CALLER_ALLOWED_EXTRA_BODY_FIELDS: + unlisted_option_names.add(field_name) + for name, value in request.items(): if value is None or (name == "model" and value == ""): continue @@ -133,16 +223,18 @@ def response_run_options(request: CreateResponse) -> dict[str, Any]: raise TypeError("extra_body must be a mapping of model options.") if "extra_body" in value: raise ValueError("Nested extra_body is not supported; flatten provider options instead.") - nested_extra.update(cast(Mapping[str, Any], value)) + for name, item in cast(Mapping[str, Any], value).items(): + option_name = _OPTION_NAMES.get(name, name) + if name in DEFAULT_CALLER_ALLOWED_EXTRA_BODY_FIELDS and option_name not in unlisted_option_names: + nested_extra[option_name] = item elif name in _HOST_CONTROLLED_FIELDS: continue - elif name in _NATIVE_FIELDS: - native[_OPTION_NAMES.get(name, name)] = value - else: - extra[name] = value + elif name in DEFAULT_CALLER_ALLOWED_FIELDS and name in _NATIVE_FIELDS: + option_name = _OPTION_NAMES.get(name, name) + if option_name not in unlisted_option_names: + native[option_name] = value return { **native, - **{name: value for name, value in extra.items() if name not in _HOST_CONTROLLED_FIELDS}, **{name: value for name, value in nested_extra.items() if name not in _HOST_CONTROLLED_FIELDS}, } diff --git a/python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py b/python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py index f9853ed0548..7a66a6f99a9 100644 --- a/python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py +++ b/python/packages/foundry_hosting/agent_framework_foundry_hosting/_responses.py @@ -120,6 +120,7 @@ UnsupportedOptions, WorkflowTurn, prepare_response_options, + reject_disallowed_caller_fields, response_run_options, validate_default_transport_options, validate_request_options, @@ -1045,7 +1046,9 @@ def __init__( client into provider background polling and requires `history_source="service"`. Each poll retains the caller's run options and `background=True`; local tools must be idempotent because a crash before the next private token is saved can replay them. - prepare_options: Developer hook to remove or replace caller model options for an agent. + prepare_options: Developer hook to remove or replace caller model options. Returning a caller field + not included in the default allowlist explicitly opts that field into this request; host-controlled + fields remain forbidden. unsupported_options: `"warn"` (default), `"error"`, or `"ignore"` when a custom agent cannot accept runtime model options. **kwargs: Additional keyword arguments. @@ -1305,6 +1308,10 @@ async def _handle_response( if configuration.workflow: if self._prepare_options is not None: raise _PublicResponseFailure(ValueError("prepare_options is only supported for regular agents.")) + try: + reject_disallowed_caller_fields(request, response_run_options(request)) + except (TypeError, ValueError) as exc: + raise _PublicResponseFailure(exc) from None else: try: hosted_request = HostedResponseRequest(request, context, scope, response_run_options(request)) @@ -1312,6 +1319,7 @@ async def _handle_response( raise _PublicResponseFailure(exc) from None await prepare_response_options(hosted_request, self._prepare_options) try: + reject_disallowed_caller_fields(request, hosted_request.options) validate_request_options(hosted_request.options) except (TypeError, ValueError) as exc: raise _PublicResponseFailure(exc) from None diff --git a/python/packages/foundry_hosting/agent_framework_foundry_hosting/_workflow_responses.py b/python/packages/foundry_hosting/agent_framework_foundry_hosting/_workflow_responses.py index 2df89e5ecb7..0e7a967a7a4 100644 --- a/python/packages/foundry_hosting/agent_framework_foundry_hosting/_workflow_responses.py +++ b/python/packages/foundry_hosting/agent_framework_foundry_hosting/_workflow_responses.py @@ -47,6 +47,7 @@ OptionsHook, WorkflowTurn, prepare_response_options, + reject_disallowed_caller_fields, response_run_options, validate_request_options, ) @@ -429,6 +430,7 @@ async def abort() -> bool: ) hosted = HostedResponseRequest(request, context, scope, response_run_options(request)) await prepare_response_options(hosted, self.options_hook) + reject_disallowed_caller_fields(request, hosted.options) validate_request_options(hosted.options) workflow = await self.resolver.resolve(hosted) resources = AsyncExitStack() diff --git a/python/packages/foundry_hosting/tests/foundry_hosting/test_native_responses.py b/python/packages/foundry_hosting/tests/foundry_hosting/test_native_responses.py index bd90420d6a0..cf4f99f8cc8 100644 --- a/python/packages/foundry_hosting/tests/foundry_hosting/test_native_responses.py +++ b/python/packages/foundry_hosting/tests/foundry_hosting/test_native_responses.py @@ -621,13 +621,18 @@ def create(request: HostedResponseRequest) -> Workflow: async def parse(request: HostedResponseRequest) -> WorkflowTurn[Any]: return WorkflowTurn(input=[Message("user", await request.get_input_text() or "")]) - server = _server(create, parser=parse) - first = await _post(server, "one", temperature=0.7, max_output_tokens=12, store=True) + def prepare_options(request: HostedResponseRequest, options: dict[str, Any]) -> dict[str, Any]: + options["vendor_option"] = request.request["vendor_option"] + return options + + server = _server(create, parser=parse, prepare_options=prepare_options) + first = await _post(server, "one", temperature=0.7, max_output_tokens=12, store=True, vendor_option="first") assert first["status"] == "completed", first - second = await _post(server, "two", temperature=0.4, store=False, call="call-two") + second = await _post(server, "two", temperature=0.4, store=False, call="call-two", vendor_option="second") assert second["status"] == "completed", second assert [call["options"]["store"] for call in calls] == [False, False] assert [call["options"]["temperature"] for call in calls] == [0.7, 0.4] + assert [call["options"]["vendor_option"] for call in calls] == ["first", "second"] assert calls[0]["options"]["max_tokens"] == 12 assert all( agent.default_options["temperature"] == 0.2 and agent.default_options["store"] is True for agent in agents diff --git a/python/packages/foundry_hosting/tests/test_request.py b/python/packages/foundry_hosting/tests/test_request.py index 6496e7e8b6f..172033a4fe3 100644 --- a/python/packages/foundry_hosting/tests/test_request.py +++ b/python/packages/foundry_hosting/tests/test_request.py @@ -14,6 +14,7 @@ from agent_framework_foundry_hosting import HostedResponseRequest, InvocationRun, response_input_messages from agent_framework_foundry_hosting._request import ( prepare_response_options, + reject_disallowed_caller_fields, response_run_options, validate_default_transport_options, validate_request_options, @@ -31,19 +32,11 @@ def test_native_options_are_translated_before_flattened_extra_body() -> None: "store": True, "background": False, "conversation": "outer-conversation", - "agent_session_id": "forged-sandbox", - "session_id": "caller-session", "user": "forged-user", - "user_id": "forged-user", - "call_id": "forged-call", - "conversation_id": "inner-conversation", - "service_session_id": "private-session", - "continuation_token": {"response_id": "private"}, "max_output_tokens": 300, - "max_tokens": 150, "parallel_tool_calls": False, "reasoning": {"effort": "high"}, - "slogan_style": "retro", + "extra_body": {"max_tokens": 150, "temperature": 0.4}, }, ) @@ -52,10 +45,33 @@ def test_native_options_are_translated_before_flattened_extra_body() -> None: "max_tokens": 150, "allow_multiple_tool_calls": False, "reasoning": {"effort": "high"}, - "slogan_style": "retro", + "temperature": 0.4, } +@pytest.mark.parametrize( + ("payload", "field_name"), + [ + ({"instructions": None}, "instructions"), + ({"extra_body": {"vendor_option": None}}, "extra_body.vendor_option"), + ({"additional_function_arguments": {"tenant_id": "forged"}}, "additional_function_arguments"), + ({"max_output_tokens": 30, "max_tokens": 999}, "max_tokens"), + ({"parallel_tool_calls": False, "allow_multiple_tool_calls": True}, "allow_multiple_tool_calls"), + ( + {"extra_body": {"additional_function_arguments": {"tenant_id": "forged"}}}, + "extra_body.additional_function_arguments", + ), + ], +) +def test_unlisted_request_fields_are_rejected(payload: dict[str, Any], field_name: str) -> None: + request = cast(CreateResponse, {"input": "hello", **payload}) + options = response_run_options(request) + + with pytest.raises(ValueError) as exc_info: + reject_disallowed_caller_fields(request, options) + assert field_name in str(exc_info.value) + + def test_nested_extra_body_is_also_overlaid_last_without_reserved_fields() -> None: request = cast( CreateResponse, @@ -63,12 +79,15 @@ def test_nested_extra_body_is_also_overlaid_last_without_reserved_fields() -> No "max_output_tokens": 300, "extra_body": { "max_tokens": 150, - "session_id": "forged", - "continuation_token": {"response_id": "private"}, }, }, ) assert response_run_options(request) == {"max_tokens": 150} + with pytest.raises(ValueError, match="extra_body.session_id"): + reject_disallowed_caller_fields( + cast(CreateResponse, {"extra_body": {"session_id": "forged"}}), + {}, + ) with pytest.raises(TypeError, match="extra_body must be a mapping"): response_run_options(cast(CreateResponse, {"extra_body": ["not a mapping"]})) with pytest.raises(ValueError, match="Nested extra_body is not supported"): @@ -139,6 +158,39 @@ async def test_hook_rejects_reserved_fields_and_non_mapping_result() -> None: await prepare_response_options(request, lambda _view, _options: cast(Any, None)) +async def test_options_hook_can_opt_a_request_field_into_the_allowlist() -> None: + payload = cast( + CreateResponse, + { + "input": "hello", + "vendor_option": "caller-value", + "max_output_tokens": 30, + "max_tokens": 999, + "extra_body": {"provider_option": "nested-value"}, + }, + ) + context = MagicMock(spec=ResponseContext) + context.response_id = "outer-id" + context.conversation_id = None + scope = FoundryRequestScope(session_id="sandbox", user_id="user", call_id="call", is_hosted=False) + request = HostedResponseRequest(payload, context, scope, response_run_options(payload)) + + def allow_request_fields(view: HostedResponseRequest, options: dict[str, Any]) -> dict[str, Any]: + return { + **options, + "vendor_option": view.request["vendor_option"], + "max_tokens": view.request["max_tokens"], + "provider_option": view.request["extra_body"]["provider_option"], + } + + await prepare_response_options(request, allow_request_fields) + reject_disallowed_caller_fields(payload, request.options) + + assert request.options["vendor_option"] == "caller-value" + assert request.options["max_tokens"] == 999 + assert request.options["provider_option"] == "nested-value" + + def test_default_transport_cannot_override_host_storage_or_identity() -> None: with pytest.raises(ValueError, match="store"): validate_default_transport_options({"extra_body": {"store": True}}, allow_agent_store=False) diff --git a/python/packages/foundry_hosting/tests/test_responses.py b/python/packages/foundry_hosting/tests/test_responses.py index 6022b6c9467..e86b3cd6b3c 100644 --- a/python/packages/foundry_hosting/tests/test_responses.py +++ b/python/packages/foundry_hosting/tests/test_responses.py @@ -2241,8 +2241,9 @@ async def test_extra_options_overlay_then_developer_hook_preserves_defaults(self agent = Agent(client=client, default_options=OpenAIChatOptions(temperature=0.2, max_tokens=256)) defaults = dict(agent.default_options) - def prepare_options(_request: Any, options: dict[str, Any]) -> dict[str, Any]: + def prepare_options(request: Any, options: dict[str, Any]) -> dict[str, Any]: options.pop("temperature") + options["vendor_option"] = request.request["vendor_option"] return options server = _make_server(agent, prepare_options=prepare_options) @@ -2253,19 +2254,49 @@ def prepare_options(_request: Any, options: dict[str, Any]) -> dict[str, Any]: "model": "test-model", "temperature": 0.8, "max_output_tokens": 300, - "max_tokens": 150, - "session_id": "forged-sandbox", - "call_id": "forged-call", + "extra_body": {"max_tokens": 150}, + "vendor_option": "caller-value", }, ) assert response.json()["status"] == "completed" assert client.options[0]["temperature"] == 0.2 assert client.options[0]["max_tokens"] == 150 - assert "session_id" not in client.options[0] - assert "call_id" not in client.options[0] + assert client.options[0]["vendor_option"] == "caller-value" assert agent.default_options == defaults + @pytest.mark.parametrize( + ("location", "field_name"), + [ + ("top_level", "additional_function_arguments"), + ("extra_body", "extra_body.additional_function_arguments"), + ("alias_collision", "max_tokens"), + ], + ) + @pytest.mark.parametrize("stream", [False, True]) + async def test_unlisted_caller_option_fails_before_agent_run( + self, location: Literal["top_level", "extra_body", "alias_collision"], field_name: str, stream: bool + ) -> None: + agent = _make_agent() + server = _make_server(agent) + payload: dict[str, Any] = {"input": "one shot", "stream": stream} + if location == "top_level": + payload["additional_function_arguments"] = {"tenant_id": "forged"} + elif location == "extra_body": + payload["extra_body"] = {"additional_function_arguments": {"tenant_id": "forged"}} + else: + payload.update({"max_output_tokens": 30, "max_tokens": 999}) + + response = await _post_json(server, payload) + + if stream: + assert "response.failed" in response.text + assert field_name in response.text + else: + assert response.json()["status"] == "failed" + assert field_name in response.json()["error"]["message"] + agent.run.assert_not_called() + async def test_hook_cannot_reintroduce_host_owned_storage_or_identity(self) -> None: agent = _make_agent() server = _make_server( @@ -9971,6 +10002,24 @@ class TestWorkflowAgentHosting: relative to the regular agent path. """ + @pytest.mark.parametrize("location", ["top_level", "extra_body"]) + async def test_unlisted_caller_option_fails_before_workflow_run( + self, location: Literal["top_level", "extra_body"] + ) -> None: + workflow_agent, inner = _build_multi_update_workflow_agent(["done"]) + server = _make_server(workflow_agent) + payload: dict[str, Any] = {"input": "one shot", "stream": False} + if location == "top_level": + payload["additional_function_arguments"] = {"tenant_id": "forged"} + else: + payload["extra_body"] = {"additional_function_arguments": {"tenant_id": "forged"}} + + response = await _post_json(server, payload) + + assert response.json()["status"] == "failed" + assert "additional_function_arguments" in response.json()["error"]["message"] + assert inner.run_count == 0 + async def test_async_factory_creates_workflow_agent_for_each_request(self) -> None: created: list[tuple[WorkflowAgent, _MultiUpdateWorkflowAgentMock]] = [] @@ -10352,6 +10401,15 @@ async def test_round_trip_approval_response_resumes_workflow_agent(self) -> None "stream": False, "previous_response_id": first_response_id, } + rejected_payload = { + **second_payload, + "additional_function_arguments": {"tenant_id": "forged"}, + } + rejected = await _post_json(server, rejected_payload) + assert rejected.json()["status"] == "failed" + assert "additional_function_arguments" in rejected.json()["error"]["message"] + assert mock_agent.run_count == 1 + second = await _post_json(server, second_payload) assert second.status_code == 200 second_body = second.json()