> For clean Markdown of any page, append .md to the page URL. > For a complete documentation index, see https://docs.alfa.boosted.ai/alfa/guides/legacy-workflows/scheduling-agents/schedule-and-automate-agents/llms.txt. > For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.alfa.boosted.ai/_mcp/server. # Schedule and automate agents > Learn how to set up automatic updates and scheduling for your Alfa agents Once you've created agents to analyze your data, you'll often want them to update automatically to reflect the latest information. This guide explains how to schedule and automate your agents to keep their outputs fresh. ## Enabling automatic updates To keep your agent's outputs fresh with the latest data, you can enable automation. ```python import requests BASE_URL = "https://alfa.boosted.ai/client" API_KEY = "YOUR_API_KEY_HERE" headers = {"x-api-key": API_KEY, "Content-Type": "application/json"} def enable_agent_automation(agent_id): """Set an agent to automatically update on a schedule.""" url = f"{BASE_URL}/agent/enable-automation" payload = {"agent_id": agent_id} response = requests.post(url, headers=headers, json=payload) if response.status_code == 200: data = response.json() next_run = data.get("next_run", "Unknown") print(f"Automation enabled. Next run scheduled for: {next_run}") return True else: print(f"Error: {response.status_code}, {response.text}") return False # Enable automatic updates for our agent enable_agent_automation("your-agent-id") ``` By default, agents are scheduled to run daily at 8AM in the US/Eastern timezone. You can customize this schedule using the `set-schedule` endpoint. ### Example: Enable automation for a stock analysis agent #### Create your agent First, create an agent to analyze stock market data #### Enable automation Enable automation to keep the analysis updated daily: ```python # Enable updates for a market analysis agent agent_id = "a1b2c3d4-5678-90ef-ghij-klmnopqrstuv" success = enable_agent_automation(agent_id) if success: print("Your market analysis will now update automatically!") ``` #### Check status Verify the agent's status after enabling automation ## Customizing the schedule You can customize when your agent runs using natural language schedules. ```python def set_agent_schedule(agent_id, schedule_description, timezone=None): """Set a custom schedule for an agent using natural language.""" url = f"{BASE_URL}/agent/set-schedule" payload = { "agent_id": agent_id, "user_schedule_description": schedule_description } if timezone: payload["agent_timezone"] = timezone response = requests.post(url, headers=headers, json=payload) if response.status_code == 200: data = response.json() print(f"Schedule updated: {data['schedule']['generated_schedule_description']}") print(f"Next run will use timezone: {data['schedule']['timezone']}") return data else: print(f"Error: {response.status_code}, {response.text}") return None # Set a custom schedule set_agent_schedule("your-agent-id", "Weekly on Friday at 3pm", "US/Pacific") ``` The schedule is interpreted by our backend and converted to the appropriate cron expression. You can use natural language to describe when you want your agent to run. ### Example schedule descriptions Here are some examples of schedule descriptions you can use: * **"Daily at 9:30am"**: Every day at 9:30 AM * **"Weekly on Monday at 7am"**: Every Monday at 7:00 AM * **"Every weekday at 4pm"**: Monday through Friday at 4:00 PM * **"Monthly on the 1st at 12pm"**: First day of each month at 12:00 PM ### Example: Schedule an earnings report agent to run weekly #### Identify the agent Select the earnings report agent you want to schedule #### Set the schedule Configure it to run weekly before market open: ```python # Schedule weekly earnings report before market open agent_id = "earnings-report-123456" schedule = "Weekly on Monday at 8:30am" timezone = "US/Eastern" result = set_agent_schedule(agent_id, schedule, timezone) print(f"Your earnings report will run every Monday at 8:30am Eastern Time") ``` ## Disabling automation If you no longer want an agent to run automatically, you can disable its automation. ```python def disable_agent_automation(agent_id): """Disable automatic updates for an agent.""" url = f"{BASE_URL}/agent/disable-automation" payload = {"agent_id": agent_id} response = requests.post(url, headers=headers, json=payload) if response.status_code == 200: data = response.json() if data.get("success"): print("Automation successfully disabled") return data.get("success", False) else: print(f"Error: {response.status_code}, {response.text}") return False # Disable automation for an agent disable_agent_automation("your-agent-id") ``` When you disable automation, the agent will retain its schedule configuration but won't run automatically. You can re-enable it later with the same schedule. ## Manually triggering updates If you need updated results immediately, you can manually trigger a rerun. ```python def rerun_agent(agent_id): """Manually trigger an agent to run again.""" url = f"{BASE_URL}/agent/rerun-agent" payload = {"agent_id": agent_id} response = requests.post(url, headers=headers, json=payload) if response.status_code == 200: data = response.json() success = data.get("success", False) if success: print("Agent rerun successfully initiated") return success else: print(f"Error: {response.status_code}, {response.text}") return False # Rerun our agent to get fresh data rerun_agent("your-agent-id") ``` After triggering a rerun, you'll need to check the agent's status again and retrieve the new outputs once it completes. ### Example: Rerun after breaking news #### Breaking news happens A significant event occurs that impacts your analysis #### Trigger immediate update Don't wait for the next scheduled run: ```python # Trigger immediate update after breaking news agent_id = "breaking-news-analyzer-123" # Trigger the rerun rerun_success = rerun_agent(agent_id) if rerun_success: print("Breaking news analysis has been initiated!") ``` > Learn how to set up automatic updates and scheduling for your Alfa agents