Repository navigation
Description
Description
python/samples/05-end-to-end/m365-agent/m365_agent_demo/app.py does not start. Fixing each error only reveals the next one:
- aiohttp keyword.
web.Application(middleware=[middleware_fn])raises immediately. aiohttp's parameter ismiddlewares. The bulkmiddlewares→middlewarerename in Python: [BREAKING]: removed display_name, renamed context_providers, middleware and AggregateContextProvider #3139 appears to have caught this third-party call.TypeError: Application.__init__() got an unexpected keyword argument 'middleware'. Did you mean 'middlewares'? - No credential.
build_agent()callsFoundryChatClient()with no credential:The README still documentsValueError: Azure credential is required when using project_endpoint without a project_client.OPENAI_API_KEY/OPENAI_CHAT_COMPLETION_MODELfrom before the sample moved toFoundryChatClient. - Anonymous mode with the current M365 Agents SDK (
microsoft-agents-hosting-core1.9.0; the PEP 723 header does not pin it):CloudAdapter(connection_manager=None)raisesHttpAdapterBase.__init__: Either channel_service_client_factory or connection_manager must be provided.- With
authorization=None,AgentApplicationraisesThe AgentApplication requires a connection_manager to initialize the Authorization instance. ClaimsIdentity's signature is now(claims, authentication_type, security_token), soClaimsIdentity({...}, False, "Anonymous")builds a non-anonymous identity. The adapter then tries to get an MSAL token and fails withTENANT_ID is not set in the configuration.(HTTP 500 on/api/messages).
05-end-to-end is in SAMPLE_TYPING_EXCLUDES. Pyright on the file reports (1) and the ClaimsIdentity argument mismatch.
Reproduction
I loaded the sample module and called create_app(load_app_config()) with USE_ANONYMOUS_MODE=true, using aiohttp's test client. The agent was replaced by an echo stub so no model call is made, and a local endpoint captured the bot's reply:
| result | |
|---|---|
main |
TypeError from web.Application(middleware=...) at startup |
| with all fixes below | GET /api/health 200, GET /api/messages 200, POST /api/messages 202, and the reply activity reaches the channel |
Expected behavior
The sample starts locally in anonymous mode, as the README describes, and answers messages.
Proposed fix
web.Application(middlewares=[...]).FoundryChatClient(credential=AzureCliCredential()), and README configuration forFOUNDRY_PROJECT_ENDPOINT/FOUNDRY_MODELplusaz login.- In anonymous mode, give the adapter a connection manager with an empty
SERVICE_CONNECTION, and always buildAuthorization. Anonymous requests never request tokens. - Inject a claim-less
ClaimsIdentity(authentication_type="Anonymous"), which the adapter treats as anonymous.
I have a PR ready. Authenticated (non-anonymous) mode keeps its existing configuration path. I could not test it without an Azure Bot registration.
Package Versions
agent-framework-core / agent-framework-foundry from main at 8be57da, aiohttp 3.14.3, microsoft-agents-hosting-core / -hosting-aiohttp / -authentication-msal 1.9.0.
Python Version
3.13
AI Assistance
Claude Code helped find the breakages, build the aiohttp test-client reproduction, and draft this report. I verified the reproduction locally.
Metadata
Metadata
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
github-actions commentedon Oct 22, 2026
🤖 Automated triage reproduction notes (agent-authored — trust but verify)
Agent analysis
The primary failure is in
python/samples/05-end-to-end/m365-agent/m365_agent_demo/app.py::create_appat line 201 when any configuration reachesweb.Application(middleware=[...]); anonymous mode additionally fails inbuild_adapterwhenbuild_connection_managerreturnsNone, and its middleware assignsFalsetoClaimsIdentity.authentication_type. Minimal repro: run the sample withUSE_ANONYMOUS_MODE=true, or runuv run python/samples/05-end-to-end/m365-agent/test_issue_9595.py -q.python/samples/05-end-to-end/m365-agent/test_issue_9595.pyagent-framework-core/agent-framework-foundry main@8be57da33; aiohttp 3.14.3; microsoft-agents-* 1.9.0agent-framework-core 1.22.0; agent-framework-foundry 1.15.0eavanvalkenburg commentedon Oct 26, 2026
/plan Coordinate with existing PR #9598 to establish the smallest correct repair for the maintained M365 agent sample. Current main fails at aiohttp Application(middleware=...), omits the Foundry credential, and has incompatible connection-manager/Authorization/ClaimsIdentity setup for the documented anonymous mode. Validate the supported M365 Agents SDK contracts before choosing anonymous-mode construction; explicitly decide whether an empty SERVICE_CONNECTION is supported rather than treating the proposed placeholder as accepted design. Preserve authenticated behavior and require anonymous message handling to avoid token acquisition. Include offline startup/health/messages/reply tests with a stub agent, authenticated-path mocks, Foundry credential/configuration and README alignment. The work spans linked startup/authentication contracts, so do not mark it ready based only on zero SDK production changes. Keep #9601 run-command cleanup coordinated but separately scoped; this planning request is not implementation agreement or PR approval.
eavanvalkenburg commentedon Nov 12, 2026
/plan Coordinate with existing PR #9598 to establish the smallest correct repair for the maintained M365 agent sample. Current main fails at aiohttp Application(middleware=...), omits the Foundry credential, and has incompatible connection-manager/Authorization/ClaimsIdentity setup for the documented anonymous mode. Validate the supported M365 Agents SDK contracts before choosing anonymous-mode construction; explicitly decide whether an empty SERVICE_CONNECTION is supported rather than treating the proposed placeholder as accepted design. Preserve authenticated behavior and require anonymous message handling to avoid token acquisition. Include offline startup/health/messages/reply tests with a stub agent, authenticated-path mocks, Foundry credential/configuration and README alignment. The work spans linked startup/authentication contracts, so do not mark it ready based only on zero SDK production changes. Keep #9601 run-command cleanup coordinated but separately scoped; this planning request is not implementation agreement or PR approval.
github-actions commentedon Nov 12, 2026
Summary
The maintained sample
m365_agent_demo/app.pydoes not start on currentmain, and its documented default (USE_ANONYMOUS_MODE=true) cannot answer messages. The report lists four linked problems. I checked each against the repository source. I did not inspect PR #9598's diff and did not run anything.Confirmed from the repo source
create_appcallsweb.Application(middleware=[...]). aiohttp's keyword ismiddlewares, so startup fails in every mode, not just anonymous.build_agent()callsFoundryChatClient()with no credential. The repo's sample convention (python/samples/AGENTS.md) isFoundryChatClient(project_endpoint=..., model=..., credential=AzureCliCredential())withFOUNDRY_PROJECT_ENDPOINT/FOUNDRY_MODEL.OPENAI_API_KEY/OPENAI_CHAT_COMPLETION_MODEL, and the header still sayssamples/demos/....connection_manager=None,authorization=None, andClaimsIdentity({...}, False, "Anonymous").microsoft-agents-*version.Not verified here
CloudAdapter,AuthorizationandClaimsIdentitybehave as described in 1.9.0.Recommendation
Code changes to the sample only are warranted. No framework change is needed, because the breakage is in sample code and in its use of a third-party SDK. Existing guidance in the README and
.env.exampleis stale, so documentation changes belong in the same fix. This is a sample the repo maintains, and it currently fails on first run, so the fix is proportionate.The main open design point is how anonymous mode should be built. The proposed "connection manager with an empty
SERVICE_CONNECTION" is a workaround that depends on SDK internals. It should not be accepted until the SDK contract is checked. Three options:Proposed plan
This is a proposal only. No changes have been made.
Pin the contract first. Read the
microsoft-agents-hosting-core/-aiohttp/-authentication-msalsource or docs for the version the sample will use. Answer these three questions, with citations in the PR:SERVICE_CONNECTIONsupported?ClaimsIdentityaccept, and what makes an identity anonymous?Authorizationrequire a connection manager?Then pin a minimum SDK version in the PEP 723 header.
Fix startup. Change to
web.Application(middlewares=[...]).Fix the Foundry client. Pass
AzureCliCredential()and readFOUNDRY_PROJECT_ENDPOINT/FOUNDRY_MODEL. Addazure-identityto the PEP 723 header if it is missing.Anonymous mode. Use whichever option step 1 supports. It must build a connection manager, an
Authorizationand a valid anonymous identity. Anonymous requests must not trigger token acquisition (no MSAL call, no tenant lookup).Authenticated mode. Keep the current path unchanged. Cover it with mocked tests, since no Azure Bot registration is available.
README and
.env.example. Replace the OpenAI variables with the Foundry ones plusaz login. Fix the run command. Check whethersamples/README.md's env-var inventory needs updating, assamples/AGENTS.mdrequires.Offline tests. Use an aiohttp test client with a stub agent and a local capture endpoint. Check all of these:
GET /api/healthreturns 200.GET /api/messagesreturns 200.POST /api/messagesreturns 202 in anonymous mode.Decide where the tests live.
05-end-to-endis excluded from typing checks, so also decide whether Pyright coverage is worth adding.Done when the sample starts in anonymous mode and answers a message offline, the authenticated path still builds, and the README matches the code.
Scope notes