Add microsoft-agents-hosting-starlette package#447
Open
Hameedkunkanoor wants to merge 1 commit into
Open
Conversation
Adds a Starlette integration library mirroring microsoft-agents-hosting-fastapi so agents can be hosted on a bare Starlette ASGI app (or any Starlette-based framework) without pulling in FastAPI. - CloudAdapter + StarletteRequestAdapter (HttpAdapterBase.process_request bridge) - AgentHttpAdapter protocol - start_agent_process helper - channel_service_routes (list[Route], data-driven to stay within flake8 C901) - JwtAuthorizationMiddleware (ASGI, Starlette-native) - Re-exports Citation / CitationUtil / StreamingResponse from core - Depends only on microsoft-agents-hosting-core + starlette>=1.0.1 - README package table row added Passes black (libraries --check) and flake8 (max-line-length 127, C901<=10).
Contributor
There was a problem hiding this comment.
Pull request overview
This PR introduces a new microsoft-agents-hosting-starlette integration library to host Agents on a Starlette ASGI app without taking a FastAPI dependency, mirroring the existing FastAPI adapter’s surface area.
Changes:
- Adds a new Starlette hosting package (CloudAdapter, middleware, route table, start helper, exports) aligned with the FastAPI adapter.
- Adds packaging metadata for the new library (pyproject/setup/MANIFEST/LICENSE) and documents usage in a package readme.
- Updates the repository README package table to include
microsoft-agents-hosting-starlette.
Reviewed changes
Copilot reviewed 12 out of 12 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Adds the new microsoft-agents-hosting-starlette package to the top-level package list. |
| libraries/microsoft-agents-hosting-starlette/setup.py | Defines version/dependency wiring (dynamic deps via setup.py) for the new package. |
| libraries/microsoft-agents-hosting-starlette/readme.md | Provides installation + usage documentation for the Starlette integration. |
| libraries/microsoft-agents-hosting-starlette/pyproject.toml | Adds project metadata for publishing the new Starlette integration package. |
| libraries/microsoft-agents-hosting-starlette/microsoft_agents/hosting/starlette/jwt_authorization_middleware.py | Implements Starlette-native ASGI JWT authorization middleware. |
| libraries/microsoft-agents-hosting-starlette/microsoft_agents/hosting/starlette/cloud_adapter.py | Implements a Starlette Request adapter and CloudAdapter that bridges to HttpAdapterBase. |
| libraries/microsoft-agents-hosting-starlette/microsoft_agents/hosting/starlette/channel_service_route_table.py | Provides a data-driven Starlette Route list for Channel Service endpoints. |
| libraries/microsoft-agents-hosting-starlette/microsoft_agents/hosting/starlette/agent_http_adapter.py | Defines the AgentHttpAdapter protocol for Starlette. |
| libraries/microsoft-agents-hosting-starlette/microsoft_agents/hosting/starlette/_start_agent_process.py | Adds a helper to invoke adapter processing for a Starlette Request. |
| libraries/microsoft-agents-hosting-starlette/microsoft_agents/hosting/starlette/init.py | Exposes the Starlette adapter API surface and re-exports streaming utilities. |
| libraries/microsoft-agents-hosting-starlette/MANIFEST.in | Includes VERSION.txt in the sdist (consistent with existing hosting packages). |
| libraries/microsoft-agents-hosting-starlette/LICENSE | Adds MIT license file for the new package. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+32
to
+40
| app = scope.get("app") | ||
| state = getattr(app, "state", None) if app else None | ||
| auth_config: AgentAuthConfiguration = getattr( | ||
| state, "agent_configuration", None | ||
| ) | ||
|
|
||
| request = Request(scope, receive=receive) | ||
| token_validator = JwtTokenValidator(auth_config) | ||
| auth_header = request.headers.get("Authorization") |
Comment on lines
+49
to
+50
| connection_manager: Connections = None, | ||
| channel_service_client_factory: ChannelServiceClientFactoryBase = None, |
Comment on lines
+12
to
+35
| class StarletteRequestAdapter: | ||
| """Adapter for Starlette requests to use with ChannelServiceRoutes.""" | ||
|
|
||
| def __init__(self, request: Request): | ||
| self._request = request | ||
|
|
||
| @property | ||
| def method(self) -> str: | ||
| return self._request.method | ||
|
|
||
| @property | ||
| def headers(self): | ||
| return self._request.headers | ||
|
|
||
| async def json(self): | ||
| return await self._request.json() | ||
|
|
||
| def get_claims_identity(self): | ||
| return getattr(self._request.state, "claims_identity", None) | ||
|
|
||
| def get_path_param(self, name: str) -> str: | ||
| return self._request.path_params.get(name, "") | ||
|
|
||
|
|
| JwtAuthorizationMiddleware, | ||
| ) | ||
|
|
||
| # Import streaming utilities from core for backward compatibility |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
microsoft-agents-hosting-starletteintegration library, mirroring the existingmicrosoft-agents-hosting-fastapipackage but depending only on Starlette. This lets agents be hosted on a bare Starlette ASGI app (or any Starlette-based framework) without pulling in FastAPI.Why
FastAPI is built on Starlette, and the existing
microsoft-agents-hosting-fastapiadapter is effectively Starlette code plus FastAPI'sAPIRouter. Consumers that already run on Starlette (or embed the agent in another Starlette-based host) currently must take a FastAPI dependency they don't use. This package provides the same integration surface with a Starlette-only dependency.What's included
CloudAdapter+StarletteRequestAdapter— bridges a StarletteRequestthroughHttpAdapterBase.process_requestand converts theHttpResponseback to a Starlette response.AgentHttpAdapterprotocol.start_agent_processhelper.channel_service_routes— returnslist[Route](data-driven, to stay within the repo's flake8C901complexity limit).JwtAuthorizationMiddleware— Starlette-native ASGI middleware.Citation/CitationUtil/StreamingResponsefrom core (parity with the FastAPI package).microsoft-agents-hosting-core+starlette>=1.0.1.Testing
CloudAdaptersubclassesHttpAdapterBase.JSONResponse, bodyless ->Response(status preserved).channel_service_routesgenerates 13 routes across GET/POST/PUT/DELETE.black libraries --checkandflake8(max-line-length 127,C901<=10).