Skip to content

Human in the loop

Page as Markdown

Make an agent stop and ask for your approval before it runs a tool, in the kagent UI.

Human in the loop

Make an agent stop and ask for your approval before it runs a tool, in the kagent UI.

About this tutorial

Some agents only answer questions. Others call tools that change something, cost money, or read sensitive data. For those, you can put a person in the loop: the agent stops before it runs the tool, shows you what it wants to do, and continues only after you approve.

In this tutorial, you turn on approval for the weather tool of the personal assistant, and then approve a call in the chat. The weather tool is harmless, which makes it a safe one to practice on. For how a pause works, see Human in the loop.

Time: about 5 minutes.

Before you begin

  1. Complete Build an agent and Add an MCP server, so that the personal-assistant agent has the weather tool.

Require approval for a tool

Follow the steps in the kagent UI, or apply the same resources as YAML from the command line.

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.

Require approval for a tool

The kagent UI editing the personal-assistant agent and selecting Require approval on its weather tools
Figure: Turning on approval for the agent's weather tools, sped up
  1. In the sidebar, click Agents. In the row of the personal-assistant agent, click the edit icon.

  2. Under Tools from MCP servers, find the row of the kagent/weather server, and select Require approval.

    Approval belongs to the row, not to one tool. It covers every tool that the row lists, or every tool on the server when the list is left on All tools.

  3. Click Save agent, and wait until the agent returns to Ready.

Approve a tool call

  1. Click the agent name to open its chat page, and start a New chat.

  2. Ask something that needs the tool, such as What is the weather in Toronto right now?

  3. The agent stops, and the chat shows that the agent is asking permission to run a tool, with the name of the tool. Click Approve to let the call run. The agent then finishes its answer.

    To refuse instead, click Reject. You can type a reason, and then click Send rejection. The agent receives the reason and carries on without the tool.

Mix free tools and approved tools

One server can supply both kinds. Add the server twice: once with the tools that the agent can use freely, and once with the tools that need approval, with Require approval selected on the second row. Build a K8s SRE does this with the Kubernetes tools.

Agents on the codex and claude harnesses accept each server only once, so approval there covers the whole server.

Verify that the agent asks first

  1. Check that the agent is ready after the change.

    kubectl get agent personal-assistant -n kagent

    Example output:

    NAME                READY   AGE
    personal-assistant  True    2m
    
  2. Check that the weather tool binding requires approval.

    kubectl get agent personal-assistant -n kagent -o jsonpath='{.spec.template.inline.tools[0].mcp.requireApproval}'

    Example output:

    true
    
  3. In a New chat, ask What is the weather in Toronto right now? The agent stops before it calls the tool and waits for you to click Approve or Reject.

What you built

An agent that stops for your approval before it runs a tool. Along the way, you used these features:

FeatureWhat you didRead more
Tool approvalSet requireApproval on an MCP tool binding, then approved and rejected callsHuman in the loop
MCP toolsBound the weather server’s tools to the agentAbout tools

Clean up

  1. To let the agent call the weather tool freely again, open its edit form, clear Require approval on the kagent/weather row, and click Save agent. From the command line, apply the YAML again without the requireApproval line.

Next steps