Skip to content

Commit df0bd9a

Browse files
feat(scheduling): Enable dynamic handle dispatch for scheduled tasks
1 parent b299920 commit df0bd9a

File tree

2 files changed

+27
-5
lines changed

2 files changed

+27
-5
lines changed

mxgo/email_handles.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
aliases=["deep-research"],
4848
process_attachments=True,
4949
deep_research_mandatory=True,
50-
allowed_tools=COMMON_TOOLS + SEARCH_TOOLS + RESEARCH_TOOLS,
50+
allowed_tools=COMMON_TOOLS + SEARCH_TOOLS + RESEARCH_TOOLS + NEWS_TOOLS,
5151
add_summary=True,
5252
target_model="gpt-4",
5353
task_template=template_prompts.RESEARCH_TEMPLATE,
@@ -70,6 +70,7 @@
7070
deep_research_mandatory=False,
7171
allowed_tools=COMMON_TOOLS
7272
+ SEARCH_TOOLS
73+
+ NEWS_TOOLS
7374
+ RESEARCH_TOOLS
7475
+ [ToolName.MEETING_CREATOR, ToolName.SCHEDULED_TASKS],
7576
target_model="gpt-4",
@@ -140,7 +141,7 @@
140141
],
141142
process_attachments=True,
142143
deep_research_mandatory=False,
143-
allowed_tools=[*COMMON_TOOLS, ToolName.SCHEDULED_TASKS],
144+
allowed_tools=[*COMMON_TOOLS, ToolName.SCHEDULED_TASKS, *NEWS_TOOLS],
144145
target_model="gpt-4",
145146
task_template=template_prompts.FUTURE_TEMPLATE,
146147
output_template=output_prompts.FUTURE_OUTPUT_GUIDELINES,
@@ -171,7 +172,7 @@
171172
aliases=["breaking-news", "latest-news", "news-update", "current-events"],
172173
process_attachments=True,
173174
deep_research_mandatory=False,
174-
allowed_tools=COMMON_TOOLS + NEWS_TOOLS + SEARCH_TOOLS,
175+
allowed_tools=COMMON_TOOLS + NEWS_TOOLS + SEARCH_TOOLS + [ToolName.SCHEDULED_TASKS],
175176
target_model="gpt-4",
176177
task_template=template_prompts.NEWS_TEMPLATE,
177178
output_template=output_prompts.NEWS_OUTPUT_GUIDELINES,

mxgo/tools/scheduled_tasks_tool.py

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,10 @@ class ScheduledTaskInput(BaseModel):
126126
distilled_future_task_instructions: str = Field(
127127
..., description="Distilled and detailed instructions about how the task will be processed in future"
128128
)
129+
future_handle_alias: HandlerAlias | None = Field(
130+
None,
131+
description="The specific email handle (e.g., 'news', 'summarize') to use for the future task. Defaults to 'ask' if not provided.",
132+
)
129133
start_time: str | None = Field(
130134
None, description="Start time for the task - task will not execute before this time (ISO format)"
131135
)
@@ -185,6 +189,11 @@ class ScheduledTasksTool(Tool):
185189
"type": "string",
186190
"description": "Distilled and detailed instructions about how the task will be processed in future",
187191
},
192+
"future_handle_alias": {
193+
"type": "string",
194+
"description": "The specific email handle (e.g., 'news', 'summarize') to use for the future task. Defaults to 'ask' if omitted.",
195+
"nullable": True,
196+
},
188197
"start_time": {
189198
"type": "string",
190199
"description": "Optional start time for the task in ISO 8601 format - task will not execute before this time",
@@ -215,6 +224,7 @@ def forward(
215224
self,
216225
cron_expression: str,
217226
distilled_future_task_instructions: str,
227+
future_handle_alias: str | None = None,
218228
start_time: str | None = None,
219229
end_time: str | None = None,
220230
) -> dict:
@@ -224,6 +234,7 @@ def forward(
224234
Args:
225235
cron_expression: Valid cron expression for task scheduling
226236
distilled_future_task_instructions: Distilled and detailed instructions about how the task will be processed in future
237+
future_handle_alias: The specific email handle to use for the future task.
227238
start_time: Optional start time for the task in ISO 8601 format
228239
end_time: Optional end time for the task in ISO 8601 format
229240
@@ -233,6 +244,7 @@ def forward(
233244
"""
234245
logger.info(f"Storing and scheduling task: {distilled_future_task_instructions}")
235246
logger.info(f"Cron expression: {cron_expression}")
247+
logger.info(f"Future handle alias: {future_handle_alias}")
236248
logger.info(f"Is one-time task: {is_one_time_task(cron_expression) if cron_expression else 'Unknown'}")
237249

238250
# Get email request from context
@@ -253,6 +265,7 @@ def forward(
253265
input_data = ScheduledTaskInput(
254266
cron_expression=cron_expression,
255267
distilled_future_task_instructions=distilled_future_task_instructions,
268+
future_handle_alias=future_handle_alias,
256269
start_time=start_time,
257270
end_time=end_time,
258271
)
@@ -306,8 +319,16 @@ def forward(
306319
# Save distilled instructions and task description to email request
307320
email_request.distilled_processing_instructions = input_data.distilled_future_task_instructions
308321
email_request.task_description = distilled_future_task_instructions
309-
# TODO: Need an AI driver logic here but for now we'll just redirect to ask
310-
email_request.distilled_alias = HandlerAlias.ASK
322+
if input_data.future_handle_alias:
323+
try:
324+
email_request.distilled_alias = HandlerAlias(input_data.future_handle_alias)
325+
logger.info(f"Using specified handle alias: {input_data.future_handle_alias}")
326+
except ValueError:
327+
logger.warning(f"Invalid handle alias '{input_data.future_handle_alias}', defaulting to ASK")
328+
email_request.distilled_alias = HandlerAlias.ASK
329+
else:
330+
email_request.distilled_alias = HandlerAlias.ASK
331+
311332
email_request.parent_message_id = email_request.messageId
312333

313334
# Store task in database using CRUD

0 commit comments

Comments
 (0)