Skip to content

Add microsoft-agents-hosting-starlette package#447

Open
Hameedkunkanoor wants to merge 1 commit into
microsoft:mainfrom
Hameedkunkanoor:hameed/hosting-starlette
Open

Add microsoft-agents-hosting-starlette package#447
Hameedkunkanoor wants to merge 1 commit into
microsoft:mainfrom
Hameedkunkanoor:hameed/hosting-starlette

Conversation

@Hameedkunkanoor

Copy link
Copy Markdown

Summary

Adds a new microsoft-agents-hosting-starlette integration library, mirroring the existing microsoft-agents-hosting-fastapi package 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-fastapi adapter is effectively Starlette code plus FastAPI's APIRouter. 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 Starlette Request through HttpAdapterBase.process_request and converts the HttpResponse back to a Starlette response.
  • AgentHttpAdapter protocol.
  • start_agent_process helper.
  • channel_service_routes — returns list[Route] (data-driven, to stay within the repo's flake8 C901 complexity limit).
  • JwtAuthorizationMiddleware — Starlette-native ASGI middleware.
  • Re-exports Citation / CitationUtil / StreamingResponse from core (parity with the FastAPI package).
  • Depends only on microsoft-agents-hosting-core + starlette>=1.0.1.
  • README package-table row added.

Testing

  • All public symbols import; CloudAdapter subclasses HttpAdapterBase.
  • Response conversion verified: body -> JSONResponse, bodyless -> Response (status preserved).
  • channel_service_routes generates 13 routes across GET/POST/PUT/DELETE.
  • Passes black libraries --check and flake8 (max-line-length 127, C901<=10).

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).
Copilot AI review requested due to automatic review settings July 8, 2026 09:37
@Hameedkunkanoor Hameedkunkanoor requested a review from a team as a code owner July 8, 2026 09:37

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants