Repository navigation
Description
Maintainer-owned vNext task. Community contributors: please do not pick up or start implementing this issue. Removing a public API is a breaking change for the Agent Framework core team to design and schedule.
Summary
Remove as_agent() from chat clients in vNext: BaseChatClient.as_agent() and its RawFoundryAgentChatClient.as_agent() override. Agent(client=client, ...) already creates an agent from any chat client, and the repository's sample guidance already requires it: "Do not use client.as_agent(...) in samples; construct agents explicitly with Agent(client=client, ...)" (samples/AGENTS.md). The shorthand is a second construction path that must mirror the Agent constructor, has drifted from it, and does not behave the same on every client.
Workflow.as_agent() and FunctionalWorkflow.as_agent() are covered by #8949. The findings below come from a design review and were reproduced against main at a91fe66.
Problems
-
It duplicates the
Agentconstructor, and the copies drift.as_agent()re-declares everyAgentparameter and forwards them, so each constructor change must be made twice, with two docstrings. The copies have already diverged in released versions:as_agent()kept acceptingfunction_invocation_configurationafterAgentdropped it, failing withTypeErrorat call time (Python: [Bug]: The as_agent method of BaseChatClient accepts a function_invocation_configuration parameter, but Agent no longer agrees with that. #4985), and its typing rejectedMCPStdioToolwhileAgentaccepted it (Python: [Bug]: as_agent tools typing rejects MCPStdioTool #3936). They still differ today:instructionsis positional onAgent(client, instructions)but keyword-only onas_agent().default_options,context_providers, andadditional_propertiesare annotated differently, for exampleOptionsCoT | Mapping[str, Any]onas_agent()versusOptionsCoTonAgent.
-
It means something different on Foundry agent clients. On other clients it returns
Agent(client=self, ...).RawFoundryAgentChatClientoverrides it to return aFoundryAgentthat builds a new client from the project client, agent name, and version, so the agent does not use the client it was called on, and that client's configuration is silently lost:returned type: FoundryAgent | agent.client is client: False instruction_role: 'developer' -> None compaction_strategy: SlidingWindowStrategy -> None tokenizer: CharacterEstimatorTokenizer -> None additional_properties: {'team': 'support'} -> {} default_headers: {'x-tenant': 'contoso'} -> None OpenAI client timeout: 30 -> Timeout(connect=5.0, read=600, write=600, pool=600)Agent(client=client)keeps the same client. The override also adds afunction_invocation_configurationparameter that the base method does not have, so the sameas_agent(...)call is not valid on every client. -
It is not part of the chat client contract.
Agentaccepts anySupportsChatGetResponse, but that protocol has onlyadditional_propertiesandget_response(). A client written to the protocol, like the protocol's own docstring example, has noas_agent(), so code written against the protocol cannot rely on it. -
It reverses the dependency between layers.
_agents.pyimports_clients.pyat module level (L27), soBaseChatClienthas to importAgentinside the method (L644) to construct it.
Scope
- Remove
BaseChatClient.as_agent()and theRawFoundryAgentChatClient.as_agent()override, with their tests. - Replace the remaining
client.as_agent(...)usage withAgent(client=client, ...), orFoundryAgent(...)for Foundry agents:- docstring examples in core (
_clients.py),a2a,anthropic,declarative(WorkflowFactory),foundry_local, andorchestrations(handoff); - the
lab/gaiasamples; - READMEs and guidance:
packages/core/AGENTS.md("Usingas_agent()Shorthand"),packages/hosting,packages/azure-cosmos-memory,samples/05-end-to-end/evaluation/red_teaming, and the02-agents/chat_clientand02-agents/providers/customREADMEs, which still describecustom_chat_client.pyas usingas_agent()although it now usesAgent(...).
- docstring examples in core (
Workflow.as_agent()andFunctionalWorkflow.as_agent()are covered by Python: RemoveWorkflowAgentandWorkflow.as_agent()in vNext #8949.
Alternative
Use the Agent constructor, which accepts every chat client and keeps using the client instance you pass:
agent = Agent(client=client, name="assistant", instructions="You are a helpful assistant.")For Foundry agents, construct FoundryAgent directly. Samples already follow this pattern, so there will be one documented way to create an agent.
Related
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
MoeenAsim commentedon Oct 3, 2026
Eduard van Valkenburg (@eavanvalkenburg)
Hi Eduard! I’d like to contribute to the Agent Framework. Would this issue be open to a community contribution? thanks