Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions python/PACKAGE_STATUS.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Status is grouped into these buckets:
| `agent-framework-foundry-local` | `python/packages/foundry_local` | `beta` |
| `agent-framework-gemini` | `python/packages/gemini` | `alpha` |
| `agent-framework-github-copilot` | `python/packages/github_copilot` | `beta` |
| `agent-framework-hosting-discord` | `python/packages/hosting-discord` | `alpha` |
| `agent-framework-hyperlight` | `python/packages/hyperlight` | `beta` |
| `agent-framework-lab` | `python/packages/lab` | `beta` |
| `agent-framework-mem0` | `python/packages/mem0` | `beta` |
Expand Down
22 changes: 22 additions & 0 deletions python/packages/hosting-discord/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
MIT License

Copyright (c) Microsoft Corporation.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE

78 changes: 78 additions & 0 deletions python/packages/hosting-discord/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# agent-framework-hosting-discord

Discord HTTP Interactions channel for [agent-framework-hosting](../hosting).
The channel exposes a signed Starlette route for Discord slash commands, maps a
configurable slash command to the hosted agent, maps `ChannelCommand` instances
to native Discord commands, and supports push to Discord channel ids.

## Usage

```python
from agent_framework_hosting import AgentFrameworkHost
from agent_framework_hosting_discord import DiscordChannel

host = AgentFrameworkHost(
target=my_agent,
channels=[
DiscordChannel(
application_id="<discord application id>",
public_key="<discord public key>",
bot_token="<discord bot token>",
guild_id="<guild id for fast dev command registration>",
)
],
)
host.serve()
```

Configure the Discord Developer Portal interaction endpoint as:

```text
https://<your-host>/discord/interactions
```

The channel verifies Discord's `X-Signature-Ed25519` header against the raw
request body before parsing JSON. `skip_signature_verification=True` exists only
for local tests and should not be used on a public endpoint.

## Slash commands

By default, `/ask prompt:<text>` invokes the hosted agent. Additional
`ChannelCommand` instances are registered as Discord slash commands with an
optional `input` string option:

```python
from agent_framework_hosting import ChannelCommand

async def reset(ctx):
await ctx.reply("Reset acknowledged")

DiscordChannel(
application_id="...",
public_key="...",
bot_token="...",
commands=[ChannelCommand("reset", "Reset the conversation", reset)],
)
```

When `guild_id` is set, commands are registered only for that guild and usually
appear quickly. Global command registration can take much longer to propagate.
If `register_commands=True` but `bot_token` is omitted, the channel logs a
warning and assumes commands were registered outside the host.

## Identity, sessions, and push

The default isolation key is `discord:<guild-or-dm>:<channel_id>:<user_id>`,
which keeps each user private inside a Discord channel or thread. Pass
`isolation_key_factory=` to use a different scope.

`ChannelIdentity.native_id` is the Discord user id. Push requires
`identity.attributes["channel_id"]`; the first slice intentionally does not
create DM channels as a fallback.

## Streaming

Set `streaming=True` to consume the host stream and edit the original Discord
interaction response as text accumulates. Edits are debounced with
`edit_interval` to avoid excessive Discord REST calls.

Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright (c) Microsoft. All rights reserved.

"""Discord channel for ``agent-framework-hosting``."""

import importlib.metadata

from ._channel import DiscordChannel, DiscordIsolationKeyFactory, discord_isolation_key

try:
__version__ = importlib.metadata.version(__name__)
except importlib.metadata.PackageNotFoundError:
__version__ = "0.0.0"

__all__ = [
"DiscordChannel",
"DiscordIsolationKeyFactory",
"__version__",
"discord_isolation_key",
]
Loading