✨ Add ScheduledTaskTool with global scheduler and frontend polling#3216
Open
2862282695gjh-afk wants to merge 1 commit into
Open
✨ Add ScheduledTaskTool with global scheduler and frontend polling#32162862282695gjh-afk wants to merge 1 commit into
2862282695gjh-afk wants to merge 1 commit into
Conversation
00e60b9 to
963cdbe
Compare
Add a scheduled task tool that enables agents to create, list, and cancel cron-based or one-shot scheduled tasks. The architecture uses a global scheduler singleton (independent of agent lifecycle), DB persistence, and frontend polling for real-time message delivery. Changes: - SDK: ScheduledTaskTool as thin CRUD wrapper with cron parser - Backend: global ScheduledTaskScheduler (10s DB poll), scheduled_task_db - Backend: new_messages polling API + batch endpoint - Backend: conversation_id passthrough for task-to-session binding - Backend: scheduler strips ScheduledTaskTool from triggered agent to prevent recursive task creation - Frontend: two-layer polling (5s active, 10s background conversations) - DB: scheduled_tasks_t table with multi-tenant fields No existing Nexent logic is modified — all changes are additive.
963cdbe to
66f0180
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Add a ScheduledTaskTool that enables Nexent agents to create, list, and cancel cron-based or one-shot scheduled tasks.
Architecture
Why not just a tool module?
Nexent creates a new agent instance per message — tools, scheduler threads, and all state are GCd after each run. A scheduled task tool needs to survive beyond a single agent run, which requires:
Key Design Decisions
message_idxfrom DBmax()save_messagescomputes idx fromhistory=[]→ always 0, causing collisionsget_new_messages_servicevalidatesconversation.created_by == user_idMulti-Tenant Compatibility
ScheduledTaskRecordincludestenant_idanduser_idfieldsquery_tasks_by_agentandcancel_taskfilter bytenant_idtenant_id/user_idfor agent runsFiles Changed (15 files, +877 lines, all additive)
New files (3):
backend/database/scheduled_task_db.py— 5 CRUD functionsbackend/services/scheduled_task_scheduler.py— global scheduler singletonsdk/nexent/core/tools/scheduled_task_tool.py— tool with cron parserModified files (12, no existing logic changed):
backend/database/db_models.py—ScheduledTaskRecordmodelbackend/database/conversation_db.py—get_max_message_index()backend/services/conversation_management_service.py—get_new_messages_service()backend/apps/conversation_management_app.py— polling endpointsbackend/apps/runtime_app.py— scheduler lifecyclebackend/agents/create_agent_info.py—conversation_idpassthroughsdk/nexent/core/agents/nexent_agent.py— ScheduledTaskTool metadata injectionsdk/nexent/core/tools/__init__.py— export ScheduledTaskTooldocker/init.sql—scheduled_tasks_ttablefrontend/services/api.ts— new endpointsfrontend/services/conversationService.ts— polling methodsfrontend/app/[locale]/chat/internal/chatInterface.tsx— polling useEffectTesting
Tested with Docker (v2.2.0 image + bind mounts):
ScheduledTaskTool not founderrors ✅