diff --git a/src/khoj/processor/conversation/prompts.py b/src/khoj/processor/conversation/prompts.py index 46feab91..2c5bea25 100644 --- a/src/khoj/processor/conversation/prompts.py +++ b/src/khoj/processor/conversation/prompts.py @@ -528,7 +528,7 @@ User: Hahah, nice! Show a new one every morning at 9:40. My Current Location: Sh Khoj: {{ "Scratchpad": "Shanghai is UTC+8. So, 9:40 in Shanghai is 1:40 UTC. I'll also generalize the search query to get better results.", "Crontime": "40 1 * * *", - "Query": "Share a funny Calvin and Hobbes or Bill Watterson quote from my notes." + "Query": "/task Share a funny Calvin and Hobbes or Bill Watterson quote from my notes." }} ## Chat History @@ -537,7 +537,7 @@ User: Every Monday evening share the top posts on Hacker News from last week. Fo Khoj: {{ "Scratchpad": "Nairobi is UTC+3. As evening specified, I'll share at 18:30 your time. Which will be 15:30 UTC.", "Crontime": "30 15 * * 1", - "Query": "Top posts last week on Hacker News" + "Query": "/task Top posts last week on Hacker News" }} ## Chat History @@ -548,7 +548,7 @@ User: Notify me when version 2.0.0 is released. My Current Location: Mexico City Khoj: {{ "Scratchpad": "Mexico City is UTC-6. No time is specified, so I'll notify at 10:00 your time. Which will be 16:00 in UTC. Also I'll ensure the search query doesn't trigger another reminder.", "Crontime": "0 16 * * *", - "Query": "Check if the latest released version of the Khoj python package is >= 2.0.0?" + "Query": "/task Check if the latest released version of the Khoj python package is >= 2.0.0?" }} ## Chat History @@ -557,7 +557,7 @@ User: Tell me the latest local tech news on the first Sunday of every Month. My Khoj: {{ "Scratchpad": "Dublin is UTC+1. So, 10:00 in Dublin is 8:00 UTC. First Sunday of every month is 1-7. Also I'll enhance the search query.", "Crontime": "0 9 1-7 * 0", - "Query": "Find the latest tech, AI and engineering news from around Dublin, Ireland" + "Query": "/task Find the latest tech, AI and engineering news from around Dublin, Ireland" }} ## Chat History @@ -566,7 +566,7 @@ User: Inform me when the national election results are officially declared. Run Khoj: {{ "Scratchpad": "Trichy is UTC+5:30. So, 4pm in Trichy is 10:30 UTC. Also let's add location details to the search query.", "Crontime": "30 10 * * 4", - "Query": "Check if the Indian national election results are officially declared." + "Query": "/task Check if the Indian national election results are officially declared." }} # Chat History: diff --git a/src/khoj/routers/api_chat.py b/src/khoj/routers/api_chat.py index bc980620..47bc7c70 100644 --- a/src/khoj/routers/api_chat.py +++ b/src/khoj/routers/api_chat.py @@ -379,13 +379,14 @@ async def websocket_endpoint( continue meta_log = conversation.conversation_log + is_task = conversation_commands == [ConversationCommand.Task] - if conversation_commands == [ConversationCommand.Default]: + if conversation_commands == [ConversationCommand.Default] or is_task: conversation_commands = await aget_relevant_information_sources(q, meta_log) conversation_commands_str = ", ".join([cmd.value for cmd in conversation_commands]) await send_status_update(f"**🗃️ Chose Data Sources to Search:** {conversation_commands_str}") - mode = await aget_relevant_output_modes(q, meta_log) + mode = await aget_relevant_output_modes(q, meta_log, is_task) await send_status_update(f"**🧑🏾‍💻 Decided Response Mode:** {mode.value}") if mode not in conversation_commands: conversation_commands.append(mode) @@ -638,9 +639,11 @@ async def chat( else: meta_log = conversation.conversation_log - if conversation_commands == [ConversationCommand.Default]: + is_task = conversation_commands == [ConversationCommand.Task] + + if conversation_commands == [ConversationCommand.Default] or is_task: conversation_commands = await aget_relevant_information_sources(q, meta_log) - mode = await aget_relevant_output_modes(q, meta_log) + mode = await aget_relevant_output_modes(q, meta_log, is_task) if mode not in conversation_commands: conversation_commands.append(mode) diff --git a/src/khoj/routers/helpers.py b/src/khoj/routers/helpers.py index fa4b6d02..0f1d3728 100644 --- a/src/khoj/routers/helpers.py +++ b/src/khoj/routers/helpers.py @@ -163,6 +163,8 @@ def get_conversation_command(query: str, any_references: bool = False) -> Conver return ConversationCommand.Online elif query.startswith("/image"): return ConversationCommand.Image + elif query.startswith("/task"): + return ConversationCommand.Task # If no relevant notes found for the given query elif not any_references: return ConversationCommand.General @@ -220,7 +222,7 @@ async def aget_relevant_information_sources(query: str, conversation_history: di return [ConversationCommand.Default] -async def aget_relevant_output_modes(query: str, conversation_history: dict): +async def aget_relevant_output_modes(query: str, conversation_history: dict, is_task: bool = False): """ Given a query, determine which of the available tools the agent should use in order to answer appropriately. """ @@ -229,6 +231,9 @@ async def aget_relevant_output_modes(query: str, conversation_history: dict): mode_options_str = "" for mode, description in mode_descriptions_for_llm.items(): + # Do not allow tasks to schedule another task + if is_task and mode == ConversationCommand.Reminder: + continue mode_options[mode.value] = description mode_options_str += f'- "{mode.value}": "{description}"\n' diff --git a/src/khoj/utils/helpers.py b/src/khoj/utils/helpers.py index 9ff402ab..1e85b679 100644 --- a/src/khoj/utils/helpers.py +++ b/src/khoj/utils/helpers.py @@ -305,6 +305,7 @@ class ConversationCommand(str, Enum): Webpage = "webpage" Image = "image" Reminder = "reminder" + Task = "task" command_descriptions = { @@ -315,6 +316,7 @@ command_descriptions = { ConversationCommand.Webpage: "Get information from webpage links provided by you.", ConversationCommand.Image: "Generate images by describing your imagination in words.", ConversationCommand.Reminder: "Schedule your query to run at a specified time or interval.", + ConversationCommand.Task: "Scheduled task running at previously specified schedule.", ConversationCommand.Help: "Display a help message with all available commands and other metadata.", }