Skip to content

Fixing issue with test sample for FastAPI#458

Draft
rodrigobr-msft wants to merge 1 commit into
mainfrom
users/robrandao/fastapi-sample-fix
Draft

Fixing issue with test sample for FastAPI#458
rodrigobr-msft wants to merge 1 commit into
mainfrom
users/robrandao/fastapi-sample-fix

Conversation

@rodrigobr-msft

Copy link
Copy Markdown
Contributor

This pull request refactors the FastAPI sample agent to improve configuration management, authentication, and application setup. The main changes include loading configuration from environment variables, integrating MSAL-based authentication, and updating how the agent application and FastAPI app are initialized.

Configuration and Authentication Improvements:

  • Added dotenv integration and load_configuration_from_env to load agent configuration from environment variables, making the setup more flexible and secure.
  • Introduced MsalConnectionManager and updated the agent to use MSAL-based authentication, enabling better support for secure connections.
  • Added Authorization and JwtAuthorizationMiddleware to the FastAPI app for improved authorization handling. [1] [2]

Application Initialization Updates:

  • Refactored agent and adapter initialization to use the loaded configuration and new authentication components.
  • Updated the main entry point to add the authorization middleware and set up the agent configuration on app startup.

Copilot AI review requested due to automatic review settings July 9, 2026 22:19

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 refactors the FastAPI “empty agent” test sample to initialize the agent using environment-based configuration and MSAL authentication, and to wire JWT-based authorization into the FastAPI host so requests can be authorized consistently.

Changes:

  • Load agent configuration from environment variables (with dotenv support) and construct shared SDK components (storage, MSAL connection manager, adapter, authorization).
  • Update AgentApplication initialization to use the new configuration/authentication components.
  • Add/update JWT authorization middleware wiring and app configuration setup for FastAPI.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +6 to +8
from dotenv import load_dotenv

from os import environ
Comment on lines 81 to +86
if __name__ == "__main__":
import os

app.state.agent_configuration = (CONNECTION_MANAGER.get_default_connection_configuration())
app.add_middleware(JwtAuthorizationMiddleware)

port = int(os.environ.get("PORT", 3978))
port = int(environ.get("PORT", 3978))
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.

Running the fastapi/empty_agent.py sample results in a 500 error

2 participants