-
Notifications
You must be signed in to change notification settings - Fork 4.3k
feat(framework): add agent support to @novu/framework SDK fixes NV-7358 #10710
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
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
679d1b1
refactor(api-service): remove unused ON_START and ON_ACTION from Agen…
ChmaraX 41fa639
feat(framework): add agent() primitive and types for conversational a…
ChmaraX 9124dd7
feat(framework): add AgentContext implementation and wire agents into…
ChmaraX cff8590
feat(framework): dispatch agent events from NovuRequestHandler
ChmaraX d3640db
feat(framework): build verification and agent dispatch tests
ChmaraX 8c29d92
feat(api-service): rewrite mock agent handler to use @novu/framework SDK
ChmaraX 7d385b8
fix(framework,api-service): fix CI failures for agent SDK PR
ChmaraX f032e21
fix(dal): add signingSecret to integration Mongoose schema
ChmaraX c0c9a20
fix(api-service): update bridge call assertion to use ON_MESSAGE
ChmaraX 9485d56
fix(framework): address CodeRabbit review comments
ChmaraX 2197a08
fix(framework): reject unknown agent events instead of falling throug…
ChmaraX 671540a
feat(framework): add waitUntil support for agent background execution
ChmaraX 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
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 |
|---|---|---|
| @@ -1,6 +1,4 @@ | ||
| export enum AgentEventEnum { | ||
| ON_START = 'onStart', | ||
| ON_MESSAGE = 'onMessage', | ||
| ON_ACTION = 'onAction', | ||
| ON_RESOLVE = 'onResolve', | ||
| } |
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
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
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,76 @@ | ||
| /** | ||
| * Agent Handler — E2E test utility using @novu/framework | ||
| * | ||
| * This is a real serve() endpoint that uses the agent SDK to handle bridge calls. | ||
| * Run alongside the Novu API to test the full agent round-trip with Slack. | ||
| * | ||
| * Usage: | ||
| * NOVU_SECRET_KEY=<your-env-secret-key> npx ts-node apps/api/src/app/agents/e2e/mock-agent-handler.ts | ||
| * | ||
| * Setup: | ||
| * 1. Start Novu API: pnpm start:api:dev | ||
| * 2. Set environment bridge URL to http://localhost:4111/api/novu (dashboard or direct DB update) | ||
| * 3. Create an agent + link a Slack integration via the API | ||
| * 4. Point Slack event subscriptions to your Novu webhook URL (ngrok/tunnel) | ||
| * 5. @mention the bot in Slack — watch the round-trip in the logs | ||
| */ | ||
|
|
||
| import { agent, Client, serve } from '@novu/framework/express'; | ||
| import express from 'express'; | ||
|
|
||
| const NOVU_SECRET_KEY = process.env.NOVU_SECRET_KEY; | ||
| const PORT = Number(process.env.MOCK_PORT) || 4111; | ||
|
|
||
| if (!NOVU_SECRET_KEY) { | ||
| console.error('NOVU_SECRET_KEY is required. Set it to your environment secret key.'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| const echoBot = agent('novu-agent', { | ||
| onMessage: async (ctx) => { | ||
| console.log('\n─────────────────────────────────────────'); | ||
| console.log(`[${ctx.event}] from ${ctx.subscriber?.firstName ?? 'unknown'} on ${ctx.platform}`); | ||
| console.log(`Message: ${ctx.message?.text ?? '(none)'}`); | ||
| console.log(`Conversation: ${ctx.conversation.identifier} (${ctx.conversation.status})`); | ||
| console.log(`History: ${ctx.history.length} entries`); | ||
| console.log('─────────────────────────────────────────'); | ||
|
|
||
| const userText = ctx.message?.text ?? ''; | ||
| const turnCount = (ctx.conversation.metadata?.turnCount as number) ?? 0; | ||
|
|
||
| ctx.metadata.set('turnCount', turnCount + 1); | ||
|
|
||
| if (userText.toLowerCase().includes('done')) { | ||
| ctx.resolve(`Conversation resolved after ${turnCount + 1} turns`); | ||
| await ctx.reply('Thanks for chatting! Resolving this conversation.'); | ||
|
|
||
| return; | ||
| } | ||
|
|
||
| await ctx.reply(`Echo: ${userText}`); | ||
| }, | ||
|
|
||
| onResolve: async (ctx) => { | ||
| console.log(`\n[onResolve] Conversation ${ctx.conversation.identifier} closed.`); | ||
| ctx.metadata.set('resolvedAt', new Date().toISOString()); | ||
| }, | ||
| }); | ||
|
|
||
| const app = express(); | ||
| app.use(express.json()); | ||
|
|
||
| app.use( | ||
| '/api/novu', | ||
| serve({ | ||
| agents: [echoBot], | ||
| client: new Client({ | ||
| secretKey: NOVU_SECRET_KEY, | ||
| strictAuthentication: false, | ||
| }), | ||
| }) | ||
| ); | ||
|
|
||
| app.listen(PORT, () => { | ||
| console.log(`\nAgent Handler (using @novu/framework) running on http://localhost:${PORT}/api/novu`); | ||
| console.log('\nWaiting for bridge calls...\n'); | ||
| }); |
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
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
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
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
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
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
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
Oops, something went wrong.
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.