What are the Best way to schedule LangGraph workflows on Windows?

Hi LangChain :waving_hand:
I’m working on a project using LangGraph workflows, and I want to add self-scheduling tool so that the agent itself can decide to schedule tasks in the future (instead of only executing immediately after user input).

My current setup:

The workflow works like a chatbot interaction (user gives an instruction → workflow runs).
I want the agent to schedule itself as a background task, so at a future time the workflow automatically re-runs without me manually triggering it.

For example:

User: “Remind me to practice DSA at 7:00 PM.”

Agent: calls a scheduling tool → schedules workflow to run at 7:00 PM → at that time, the workflow starts and asks me if I completed the task.
What i am doing:

def schedule_yourself(task: str, time: str) -> str:
    """
    Schedule the assistant script to run at a specific time to check task completion.
    """
    script_path = r"D:\Secrets_agent\personal_assistant\chatbot.py"
    task_name = f"AssistantReminder_{task.replace(' ', '_')}"

    cmd = (
        f'schtasks /create /sc once /tn "{task_name}" '
        f'/tr "python {script_path} {task_name}" /st {time}'
    )
    try:
        subprocess.run(cmd, shell=True, check=True)
        return f"Scheduled assistant to ask about '{task}' at {time}."
    except subprocess.CalledProcessError as e:
        return f"Failed to schedule task: {e}"

:stop_sign: But it’s not working properly (fails to create reliable scheduled tasks on Windows).

My Question

  • What is the best way to schedule LangGraph workflows on Windows?

  • Should I continue with schtasks (but maybe with a different setup/command)?

  • Is there any LangGraph-specific pattern for scheduling workflows?

Your schtasks approach can work. The issue is on this line:

f'/tr "python {script_path} {task_name}" /st {time}'

You’re passing task_name (which is “AssistantReminder_practice_DSA”) instead of the actual task content (“practice DSA”). So when your chatbot.py runs, it receives the wrong argument.

Here’s the fix:

import sys

def schedule_yourself(task: str, time: str) -> str:
    """
    Schedule the assistant script to run at a specific time to check task completion.
    """
    script_path = r"D:\Secrets_agent\personal_assistant\chatbot.py"
    python_path = sys.executable  # Important: preserves your venv
    task_name = f"AssistantReminder_{task.replace(' ', '_')}"

    cmd = [
        "schtasks", "/create", "/sc", "once", "/tn", task_name,
        "/tr", f'"{python_path}" "{script_path}" --scheduled-task "{task}"',
        "/st", time, "/f"
    ]
    
    try:
        subprocess.run(cmd, capture_output=True, check=True)
        return f"Scheduled assistant to ask about '{task}' at {time}."
    except subprocess.CalledProcessError as e:
        return f"Failed to schedule task: {e.stderr.decode()}"

Important: Your chatbot.py needs to handle the --scheduled-task argument when it runs. You’ll need to check if the script was called with this flag and process the task accordingly.

Key changes:

  • Use list format instead of string (proper escaping)
  • Pass the actual task content via --scheduled-task flag
  • Use sys.executable so schtasks uses your venv Python

Regarding LangGraph-specific patterns:

Yes, LangGraph Platform has built-in cron job scheduling. You can schedule your graph to run on a schedule without dealing with OS task schedulers, check out the docs here Use cron jobs - Docs by LangChain

1 Like