Skip to content

Python: add agent-framework-hosting-discord channel#6081

Open
eavanvalkenburg wants to merge 2 commits into
microsoft:feature/python-hostingfrom
eavanvalkenburg:feat/hosting-channel-discord
Open

Python: add agent-framework-hosting-discord channel#6081
eavanvalkenburg wants to merge 2 commits into
microsoft:feature/python-hostingfrom
eavanvalkenburg:feat/hosting-channel-discord

Conversation

@eavanvalkenburg
Copy link
Copy Markdown
Member

@eavanvalkenburg eavanvalkenburg commented May 26, 2026

Motivation and Context

Adds a Discord channel package for the Python hosting work, validating the shared Channel abstractions with a real HTTP Interactions transport, slash commands, identity/session extraction, push, response hooks, and streaming edits.

Description

Adds agent-framework-hosting-discord as an alpha package. The channel:

  • exposes Discord HTTP Interactions at /discord/interactions
  • verifies Ed25519 signatures over timestamp + raw_body before JSON parsing
  • handles PING and defers slash-command interactions within Discord's ACK window
  • maps /ask prompt:<text> to the hosted agent and maps configured ChannelCommands to Discord slash commands
  • registers guild/global slash commands through Discord REST when configured
  • builds Discord identities and default isolation keys as discord:<guild-or-dm>:<channel_id>:<user_id>
  • supports originating response hooks, edit-based streaming, follow-up chunks for long content, and push via identity.attributes["channel_id"]

Also factors the common channel response-hook context/application boilerplate into hosting core as apply_channel_response_hook, so host fan-out and originating channel replies use the same helper.

Stack

PR-8 of 10. Depends on #PR-2 (feat/hosting-core). Independent of the other channel PRs; the samples PR remains the final PR in the stack.

# Branch Required for samples
PR-1 refactor/foundry-hosted-agent-history-provider foundry_hosted_agent/
PR-2 feat/hosting-core all
PR-3 feat/hosting-channel-responses all
PR-4 feat/hosting-channel-invocations foundry_hosted_agent/, local_identity_link/
PR-5a feat/hosting-channel-activity-protocol local_identity_link/
PR-5b feat/hosting-channel-teams follow-up Teams-native samples
PR-6 feat/hosting-channel-telegram local_telegram/, local_identity_link/
PR-7 feat/hosting-entra-helpers local_identity_link/
PR-8 feat/hosting-channel-discord validates channel abstractions; no current sample dependency
PR-9 feat/hosting-samples final runnable sample apps

Contribution Checklist

  • The code builds clean without any errors or warnings
  • The PR follows the Contribution Guidelines
  • All unit tests pass, and I have added new tests where possible
  • Is this a breaking change? No — new alpha package plus shared hosting helper.

Add an alpha agent-framework-hosting-discord package backed by Discord HTTP Interactions. The channel verifies signed slash-command requests, registers commands, runs hosted agents and ChannelCommand handlers, supports originating response hooks, streams by editing the original interaction response, and can push through Discord channel ids.

Factor standard channel response-hook context application into hosting core so both host fan-out and originating channel replies use one helper.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@moonbox3 moonbox3 added documentation Improvements or additions to documentation python labels May 26, 2026
Copy link
Copy Markdown

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

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

Automated Code Review

Reviewers: 4 | Confidence: 87%

✓ Correctness

The Discord channel implementation is well-structured and the apply_channel_response_hook host refactoring is correct. One correctness issue found: during streaming, intermediate edits send accumulated text to Discord without respecting the 2000-character message limit, which will cause a RuntimeError crash when streaming responses exceed that threshold.

✓ Security Reliability

The Discord channel implementation is well-structured from a security perspective. Ed25519 signature verification is correctly applied before JSON parsing, body size limits are enforced, command names are validated with a strict regex, and secrets (bot_token) are not logged. The interaction token is used only in authenticated webhook paths. Resource lifecycle (httpx client, background tasks) is properly managed with startup/shutdown hooks. No significant security or reliability issues found.

✓ Test Coverage

The test suite for the new Discord channel is comprehensive, covering the main agent command flow, streaming, push, command registration, signature verification, validation, hooks, and chunking. The apply_channel_response_hook helper also has solid coverage. A few meaningful code paths lack test coverage: the DM-interaction identity extraction fallback (where interaction.user is used instead of interaction.member.user), the exception-handling path in _dispatch_application_command that edits an error message before re-raising, and the streaming edit throttle with a positive edit_interval. None of these are blocking, but they represent real behavioral gaps.

✓ Design Approach

The overall shape looks sound, but the Discord transport currently applies its 200-character chunking strategy inconsistently. Long /ask final replies and proactive pushes are split correctly, while streamed intermediate edits and ChannelCommandContext.reply() responses still send oversized single-message bodies, so those paths will fail once content grows past Discord's own limit.


Automated review by eavanvalkenburg's agents

Comment thread python/packages/hosting-discord/agent_framework_hosting_discord/_channel.py Outdated
Comment thread python/packages/hosting-discord/agent_framework_hosting_discord/_channel.py Outdated
Ensure Discord command replies are chunked and streaming preview edits stay under Discord's content limit while final streamed replies continue through the chunked reply path.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Improvements or additions to documentation python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants