mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: Support GPT-5 verbosity option and restore Foundry agent_reference (#5619)
* Python: Support GPT-5 verbosity option and restore Foundry agent_reference Adds verbosity as a typed Literal["low","medium","high"] field on OpenAIChatOptions (Responses API) and OpenAIChatCompletionOptions (Chat Completions API), set in the same way as the existing reasoning options. For the Responses API, top-level verbosity is translated to the nested text.verbosity shape the OpenAI service expects. The same field flows through to FoundryChatClient via the existing FoundryChatOptions alias. Also fixes #5582: PR #5447 removed the agent_reference injection from RawFoundryAgentChatClient._prepare_options, so first-turn calls against a Foundry Prompt Agent went out without model and without agent_reference and were rejected by the Responses API with "Missing required parameter: 'model'". Restores the injection on the non-preview path (allow_preview=False) and adds a guard test that asserts the preview path does not inject agent_reference, since the preview SDK injects it via project_client.get_openai_client(agent_name=...). Closes #5516 Closes #5582 * Python: Address Copilot review on PR #5619 - Foundry verbosity sample docstring: replace the misleading "set deployment name on model=" instruction with the actual env-var pattern the sample relies on (FOUNDRY_PROJECT_ENDPOINT and FOUNDRY_MODEL). - _build_agent_reference docstring: clarify the helper is used for both Prompt Agents and HostedAgents on the non-preview path. - Add a Responses API test that locks in the documented precedence rule: when both top-level verbosity and text["verbosity"] are supplied, the top-level value wins. * Python: Drop redundant Foundry verbosity sample and list OpenAI sample in README - Remove samples/02-agents/providers/foundry/foundry_chat_client_verbosity.py per review feedback. The verbosity functionality is identical across the OpenAI and Foundry clients (FoundryChatOptions is an alias of OpenAIChatOptions), so a single sample on the OpenAI side is sufficient. - Add the new client_verbosity.py entry to the OpenAI samples README.
This commit is contained in:
committed by
GitHub
Unverified
parent
4a2da953ca
commit
f3db60fa65
@@ -135,6 +135,18 @@ def _uses_foundry_agent_session(conversation_id: Any) -> bool:
|
||||
)
|
||||
|
||||
|
||||
def _build_agent_reference(agent_name: str, agent_version: str | None) -> dict[str, str]:
|
||||
"""Build the Responses API ``agent_reference`` payload for non-preview Foundry agent calls.
|
||||
|
||||
Used for both Prompt Agents and HostedAgents on the ``allow_preview=False`` code path —
|
||||
the preview branch instead injects identity via ``project_client.get_openai_client(agent_name=...)``.
|
||||
"""
|
||||
ref: dict[str, str] = {"name": agent_name, "type": "agent_reference"}
|
||||
if agent_version:
|
||||
ref["version"] = agent_version
|
||||
return ref
|
||||
|
||||
|
||||
class RawFoundryAgentChatClient( # type: ignore[misc]
|
||||
RawOpenAIChatClient[FoundryAgentOptionsT],
|
||||
Generic[FoundryAgentOptionsT],
|
||||
@@ -342,6 +354,12 @@ class RawFoundryAgentChatClient( # type: ignore[misc]
|
||||
run_options.pop("previous_response_id", None)
|
||||
run_options.pop("conversation", None)
|
||||
extra_body["agent_session_id"] = conversation_id
|
||||
# Non-preview Prompt/Hosted Agent calls need agent_reference in the request body to
|
||||
# tell the Responses API which Foundry agent (and version) is in use, since ``model``
|
||||
# is stripped below. The preview path injects the reference via the OpenAI client kwarg
|
||||
# ``agent_name`` instead, so skip there. See issue #5582.
|
||||
if not self.allow_preview:
|
||||
extra_body.setdefault("agent_reference", _build_agent_reference(self.agent_name, self.agent_version))
|
||||
if extra_body:
|
||||
run_options["extra_body"] = extra_body
|
||||
|
||||
|
||||
Reference in New Issue
Block a user