Skip to content

Build a scheduled agent

Page as Markdown

Build an agent that writes a cluster health report every day, without being asked.

Build a scheduled agent

Build an agent that writes a cluster health report every day, without being asked.

About this tutorial

Build an agent that works on a timer. Every day, it reads the cluster, writes a short health report, and leaves the report in a conversation for you to read. Nobody has to ask.

The agent gets only tools that read, because nobody watches it while it runs. A schedule starts a new Session with the agent each time it fires. For how schedules work, see Scheduled runs.

Time: about 15 minutes.

Before you begin

If kagent already runs in your cluster, skip these steps.

  1. Install kubectl, helm 3, and kind v0.32.0 or later.

  2. Create a local kind cluster. To use a Kubernetes cluster that you already run, at version 1.37 or later, skip this step.

    kind create cluster --name kagent --image kindest/node:v1.37.0
  3. Set the API key of your model provider, then install the kagent CLI and run it. kagent install sets up the CRDs, Agent Substrate, a development PostgreSQL database, and kagent, and takes a few minutes.

    export OPENAI_API_KEY="your-api-key-here"
    curl -sL https://kagent.dev/install | bash && kagent install
  4. Check that the kagent pods run. Every pod reports Running.

    kubectl get pods -n kagent

Build the reporting agent

Build the agent step by step in the kagent UI, or apply the same resources as YAML and talk to the agent with the kagent CLI.

Open the kagent UI

kagent dashboard

The command forwards the UI to http://localhost:8082 and opens it in your browser. Leave it running while you work.

Create the agent

The kagent UI creating an agent named cluster-reporter and a daily schedule that runs it
Figure: Creating the cluster-reporter agent and its daily schedule, sped up
  1. In the sidebar, click Agents, and then click New Agent.

  2. In the Name field, enter cluster-reporter. Leave the Namespace as kagent, and leave Shared harness set to kagent-default.

  3. In the Template section, select Inline, and fill in the template.

    FieldValue
    Model configurationkagent/default-model-config
    DescriptionWrites a short cluster health report
  4. In the System prompt field, enter the following prompt.

    You write a short health report for a Kubernetes cluster.
    List pods that are not Running or Ready, and recent Warning events.
    Keep the report under ten lines. If everything is healthy, say so in one line.
  5. Under Tools from MCP servers, click Add an MCP server, and choose kagent/kagent-tool-server. From the tool list beside it, choose k8s_get_resources and k8s_get_events. An agent that runs unattended gets only tools that read.

  6. Click Create agent, and then click Refresh until the agent is Ready.

Schedule it

  1. In the sidebar, click Schedules, and then click New Schedule.

  2. From the Agent list, choose kagent/cluster-reporter.

  3. In the Name field, enter nightly-health-report.

  4. Leave Repeat set to Daily, and set At time and Time zone to when you want the report.

  5. In the Prompt field, enter Write the health report for all namespaces.

  6. Leave Enable Schedule on, and click Create schedule.

Read the reports

The page of the schedule shows the next execution and an Execution history table. To get the first report without waiting, click Run. Each row of the table links to the conversation of that run, which holds the report.

Verify the agent

  1. Check that the agent is ready.

    kubectl get agent cluster-reporter -n kagent

    Example output:

    NAME               READY   AGE
    cluster-reporter   True    5m
    
  2. In the kagent UI, click Schedules, and open nightly-health-report. The page shows the next execution time. After you click Run, or after the first scheduled time, the Execution history lists the run.

  3. Click the run’s conversation link, and check that it holds a report of ten lines or fewer.

What you built

An agent that writes a cluster health report every day without being asked. Along the way, you used these features:

FeatureWhat you didRead more
Scheduled runsRan the agent every day with a fixed promptScheduled runs
MCP toolsBound only the read-only tools of the built-in kagent-tool-serverAbout tools, Tools ecosystem
Agents and inline templatesGave the agent its report format in its system promptSystem prompts

Clean up

  1. In the kagent UI, click Schedules, and delete nightly-health-report. If you created it with grpcurl, see Scheduled runs for the DeleteScheduledRun call.

  2. Delete the agent.

    kubectl delete agent cluster-reporter -n kagent

Next steps