-
Notifications
You must be signed in to change notification settings - Fork 86
Tethered agent sample #526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Rodrigo Brandão (rodrigobr-msft)
merged 2 commits into
main
from
users/robrandao/tethered-sample
Aug 13, 2026
+118
−0
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Empty file.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTID= | ||
| CONNECTIONS__SERVICE_CONNECTION__SETTINGS__CLIENTSECRET= | ||
| CONNECTIONS__SERVICE_CONNECTION__SETTINGS__TENANTID= | ||
|
|
||
| LOGGING__LOGLEVEL__microsoft_agents=DEBUG | ||
|
|
||
| CONNECTIONSMAP__0__SERVICEURL=* | ||
| CONNECTIONSMAP__0__CONNECTION=SERVICE_CONNECTION | ||
|
|
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| python-dotenv | ||
| aiohttp | ||
| microsoft-agents-hosting-aiohttp | ||
| microsoft-agents-hosting-core | ||
| microsoft-agents-authentication-msal | ||
| microsoft-agents-activity | ||
| tethered |
Empty file.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. | ||
|
|
||
| import aiohttp | ||
|
|
||
| from os import environ, path | ||
| from dotenv import load_dotenv | ||
| from microsoft_agents.activity import load_configuration_from_env | ||
| from microsoft_agents.authentication.msal import ( | ||
| MsalConnectionManager, | ||
| ) | ||
| from microsoft_agents.hosting.core import ( | ||
| AgentApplication, | ||
| TurnState, | ||
| TurnContext, | ||
| MemoryStorage, | ||
| ) | ||
| from microsoft_agents.hosting.aiohttp import CloudAdapter | ||
| from microsoft_agents.hosting.core.app.oauth.authorization import Authorization | ||
|
|
||
| load_dotenv() | ||
|
|
||
| agents_sdk_config = load_configuration_from_env(environ) | ||
|
|
||
| STORAGE = MemoryStorage() | ||
| CONNECTION_MANAGER = MsalConnectionManager(**agents_sdk_config) | ||
| ADAPTER = CloudAdapter(connection_manager=CONNECTION_MANAGER) | ||
|
|
||
| AUTHORIZATION = Authorization(STORAGE, CONNECTION_MANAGER, **agents_sdk_config) | ||
|
|
||
| AGENT_APP = AgentApplication[TurnState]( | ||
| storage=STORAGE, adapter=ADAPTER, authorization=AUTHORIZATION, **agents_sdk_config | ||
| ) | ||
|
|
||
|
|
||
| @AGENT_APP.conversation_update("membersAdded") | ||
| @AGENT_APP.message("/help") | ||
| async def _help(context: TurnContext, _state: TurnState): | ||
| await context.send_activity( | ||
| "Welcome to the Echo Agent sample 🚀. " | ||
| "Type /help for help or send a message to see the echo feature in action." | ||
| ) | ||
|
|
||
| @AGENT_APP.message("/get") | ||
| async def _get(context: TurnContext, _state: TurnState): | ||
| async with aiohttp.ClientSession() as session: | ||
| async with session.get("https://www.bing.com") as response: | ||
| await context.send_activity( | ||
| f"This is a GET request. You can use this to retrieve information. Status: {response.status}" | ||
| ) | ||
|
|
||
| @AGENT_APP.activity("message") | ||
| async def on_message(context: TurnContext, _): | ||
| await context.send_activity(f"you said: {context.activity.text}") | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import tethered | ||
|
|
||
| tethered.activate(allow=[ | ||
| "login.microsoftonline.com", | ||
| "login.botframework.*", | ||
| "api.botframework.*", | ||
| "www.botframework.", | ||
| ]) | ||
|
rodrigobr-msft marked this conversation as resolved.
|
||
|
|
||
| from .agent import AGENT_APP, CONNECTION_MANAGER | ||
| from .start_server import start_server | ||
|
|
||
| start_server( | ||
| agent_application=AGENT_APP, | ||
| auth_configuration=CONNECTION_MANAGER.get_default_connection_configuration(), | ||
| ) | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| from os import environ | ||
| from microsoft_agents.hosting.core import AgentApplication, AgentAuthConfiguration | ||
| from microsoft_agents.hosting.aiohttp import ( | ||
| start_agent_process, | ||
| jwt_authorization_middleware, | ||
| CloudAdapter, | ||
| ) | ||
| from aiohttp.web import Request, Response, Application, run_app | ||
|
|
||
|
|
||
| def start_server( | ||
| agent_application: AgentApplication, auth_configuration: AgentAuthConfiguration | ||
| ): | ||
| async def entry_point(req: Request) -> Response: | ||
| agent: AgentApplication = req.app["agent_app"] | ||
| adapter: CloudAdapter = req.app["adapter"] | ||
| return await start_agent_process( | ||
| req, | ||
| agent, | ||
| adapter, | ||
| ) | ||
|
|
||
| APP = Application(middlewares=[jwt_authorization_middleware]) | ||
| APP.router.add_post("/api/messages", entry_point) | ||
| APP["agent_configuration"] = auth_configuration | ||
| APP["agent_app"] = agent_application | ||
| APP["adapter"] = agent_application.adapter | ||
|
|
||
| try: | ||
| run_app(APP, host="localhost", port=environ.get("PORT", 3978)) | ||
| except Exception as error: | ||
| raise error |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.