# Frontend Tools

> Let your agent interact with and update your application's UI.

## What is this? [#what-is-this]

A frontend tool is a function that you register in the browser. Your agent can call it, and the function runs in the user's browser. Because the handler runs in the browser, it has direct access to component state, browser APIs, and any third-party UI library the page already uses. That's how an agent can "reach into" the app: update Vue state, trigger animations, read `localStorage`, pop a toast, or steer the user's view.

This page covers the "agent drives the UI" shape of frontend tools. To render a component for a tool call, see [Components as Tools](/vue/generative-ui/tool-based). To ask the user before a tool runs, see [Human in the Loop](/vue/human-in-the-loop).

## When should I use this? [#when-should-i-use-this]

Use frontend tools when your agent needs to:

- Read or modify Vue component state
- Access browser APIs like `localStorage`, `sessionStorage`, or cookies
- Trigger UI updates, animations, or transitions
- Show alerts, toasts, or notifications
- Interact with third-party frontend libraries

## How it works in code [#how-it-works-in-code]

Register a frontend tool with `useFrontendTool`. Give it a name, a Zod schema for parameters, and a handler. The agent can then call it like any other tool and your frontend runs it in the browser.

```vue title="src/components/DashboardAgent.vue"
<script setup lang="ts">
import { ref } from "vue";
import { z } from "zod";
import { CopilotChat, useFrontendTool } from "@copilotkit/vue/v2";

const severity = ref("all");

useFrontendTool(
  {
    name: "filter_incidents",
    description: "Filter the visible incident list by severity.",
    parameters: z.object({
      severity: z.enum(["all", "sev1", "sev2", "sev3"]),
    }),
    handler: async ({ severity: nextSeverity }) => {
      severity.value = nextSeverity;
      return { applied: true, severity: nextSeverity };
    },
  },
  [severity],
);
</script>

<template>
  <p>Current filter: {{ severity }}</p>
  <CopilotChat />
</template>
```

The handler receives the parsed, type-safe parameters and can do anything the browser can: update state, call an API, or touch the DOM. Its return value is sent back to the agent as the tool result so the model can reason about what happened.

The second argument is an optional array of Vue watch sources. When one changes, CopilotKit registers the tool again. The handler reads refs when it runs, so it always sees current values.

```vue title="src/App.vue"
<script setup lang="ts">
import { CopilotKitProvider } from "@copilotkit/vue/v2";
import DashboardAgent from "./components/DashboardAgent.vue";
</script>

<template>
  <CopilotKitProvider runtime-url="/api/copilotkit">
    <DashboardAgent />
  </CopilotKitProvider>
</template>
```

Ask the agent to show only sev1 incidents. "Current filter" changes to `sev1`, and the agent replies after it reads the `{ applied: true }` result.

Your agent discovers the name, description, and parameter schema through the runtime connection. Before you ship a tool:

- Keep the description narrow.
- Validate the inputs.
- Ask the user before an action that cannot be undone.
- Keep privileged changes, secret API calls, and authorization checks on your backend.

For a tool that must wait for a user's answer, use `useHumanInTheLoop` instead.

<IntegrationGrid path="frontend-tools" />
