You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Python: Agent(client=FoundryChatClient(...)) type-checks as invalid with ty, runtime works #6938
Agent(client=FoundryChatClient(...)) works at runtime in hosted samples, but ty reports a type mismatch.
In our deployed sample this currently requires an inline ignore on the client=... argument.
This looks similar in spirit to prior static-type mismatches (for example #560), but this case is specifically about FoundryChatClient not satisfying the expected Agent client protocol in ty diagnostics.
Minimal repro
fromagent_frameworkimportAgentfromagent_framework.foundryimportFoundryChatClientfromazure.identityimportDefaultAzureCredentialclient=FoundryChatClient(
project_endpoint="https://example.services.ai.azure.com/api/projects/example",
model="gpt-5.2",
credential=DefaultAzureCredential(),
)
agent=Agent(
client=client,
instructions="You are a friendly assistant",
)
Observed ty diagnostic
error[invalid-argument-type]: Argument to bound method `__init__` is incorrect
Expected `SupportsChatGetResponse[...]`, found `FoundryChatClient[...]`
Runtime behavior
The same pattern runs successfully in hosted agent code paths; this appears to be a typing/protocol mismatch rather than a runtime incompatibility.
Environment
OS: macOS
Python: 3.13.13
ty: 0.0.21
Relevant package versions
From sample agents/pyproject.toml:
agent-framework-core>=1.10.0
agent-framework-openai>=1.10.0
agent-framework-foundry>=1.10.0
agent-framework-foundry-hosting>=1.0.0a260630
agent-framework-orchestrations>=1.0.0
Request
Could you confirm whether this is an expected typing limitation with FoundryChatClient + Agent, or a bug in type annotations/protocol definitions? If it is a bug, a typing fix would help remove ignores from hosted sample code.
Your reported ty error (error[invalid-argument-type]: Expected SupportsChatGetResponse[...], found FoundryChatClient[...]) does not reproduce with ty 0.0.21 (your stated version) or ty 0.0.56 against the current v1.10.0 codebase — both pass cleanly on your exact repro snippet. To investigate further we would need: (1) your ty project configuration (any ty.toml, pyproject.toml [tool.ty] settings, or CLI flags you use), (2) the output of pip show agent-framework-core agent-framework-foundry confirming exact installed versions, and (3) whether ty is resolving types from your venv or from source. It's possible your environment is missing the .pyi stub at agent_framework/foundry/__init__.pyi or ty is picking up a different package installation.
Once you can share the details above, we'll take another look. 🙏
as a test, it also passes ty. When I run with ty==0.0.21 I also get passing checks. I am looking further, but if you have additional info, let me know!
When default_options is a dict literal such as {"store": False}, ty includes dict[str, bool] in the solution for OptionsCoT, and then FoundryChatClient[OpenAIChatOptions[None]] no longer matches the expected client type. The dict[str, bool] shows up at the end of the expected type in the error:
That would explain why the snippet in the original report didn't reproduce: it doesn't pass default_options.
Code that shows the error
fromagent_frameworkimportAgentfromagent_framework.foundryimportFoundryChatClientfromazure.identityimportDefaultAzureCredentialclient=FoundryChatClient(
project_endpoint="https://example.services.ai.azure.com/api/projects/example",
model="gpt-5.5",
credential=DefaultAzureCredential(),
)
agent=Agent(
client=client,
instructions="You are a friendly assistant",
default_options={"store": False}, # error is reported on `client=` above
)
Workaround
Passing a typed options object fixes the error, and it's still a plain dict at runtime:
fromagent_framework.openaiimportOpenAIChatOptionsagent=Agent(
client=client,
instructions="You are a friendly assistant",
default_options=OpenAIChatOptions(store=False),
)
Caveat: the error appears in the VS Code ty extension (language server). Running ty check from the command line with the same ty version and virtual environment passes for both versions of the snippet, so the CLI may not reproduce it.
A possible fix in agent-framework: let default_options accept a plain mapping without that type taking part in the type variable that client also uses.
This comment was written with help from GitHub Copilot.
Activity
github-actions commentedon Jul 7, 2026
👋 Hi Pamela Fox (@pamelafox) — thanks for the report!
Your reported
tyerror (error[invalid-argument-type]: Expected SupportsChatGetResponse[...], found FoundryChatClient[...]) does not reproduce with ty 0.0.21 (your stated version) or ty 0.0.56 against the current v1.10.0 codebase — both pass cleanly on your exact repro snippet. To investigate further we would need: (1) yourtyproject configuration (anyty.toml,pyproject.toml [tool.ty]settings, or CLI flags you use), (2) the output ofpip show agent-framework-core agent-framework-foundryconfirming exact installed versions, and (3) whethertyis resolving types from your venv or from source. It's possible your environment is missing the.pyistub atagent_framework/foundry/__init__.pyior ty is picking up a different package installation.Once you can share the details above, we'll take another look. 🙏
eavanvalkenburg commentedon Jul 7, 2026
Hi Pamela Fox (@pamelafox)
in this line, we specifically check for this:
agent-framework/python/packages/foundry/tests/foundry/test_foundry_chat_client.py
Line 159 in c67372f
and when I run ty (v 0.0.46) against the test file everything passes.
and when I add:
as a test, it also passes
ty. When I run with ty==0.0.21 I also get passing checks. I am looking further, but if you have additional info, let me know!pamelafox commentedon Jul 7, 2026
Hm, the full file is here:
https://github.com/Azure-Samples/foundry-hosted-agentframework-demos/blob/main/agents/stage4_foundry_hosted.py
I get the error both from the ty VS Code extension and my local ty, across all the versions (I just upgraded as well to check 0.56)
pamelafox commentedon Oct 19, 2026
I found what triggers this in my code: passing a plain
dictasdefault_options.Agent.__init__uses one type variable for both arguments:When
default_optionsis a dict literal such as{"store": False}, ty includesdict[str, bool]in the solution forOptionsCoT, and thenFoundryChatClient[OpenAIChatOptions[None]]no longer matches the expected client type. Thedict[str, bool]shows up at the end of the expected type in the error:That would explain why the snippet in the original report didn't reproduce: it doesn't pass
default_options.Code that shows the error
Workaround
Passing a typed options object fixes the error, and it's still a plain dict at runtime:
Environment
Caveat: the error appears in the VS Code ty extension (language server). Running
ty checkfrom the command line with the same ty version and virtual environment passes for both versions of the snippet, so the CLI may not reproduce it.A possible fix in agent-framework: let
default_optionsaccept a plain mapping without that type taking part in the type variable thatclientalso uses.This comment was written with help from GitHub Copilot.