Tool Call Rendering

Render a frontend or backend tool call in Angular chat with a standalone component.

Render a tool result

A renderer is a standalone component with a required toolCall signal input. Its status moves through "in-progress", "executing", and "complete".

src/app/weather-card.component.ts
import { Component, input } from "@angular/core";
import {
  type AngularToolCall,
  type ToolRenderer,
} from "@copilotkit/angular";

type WeatherArgs = { city: string };

@Component({
  selector: "app-weather-card",
  template: `
    @let call = toolCall();
    @if (call.status === "complete") {
      <article>
        <strong>{{ call.args.city }}</strong>
        <p>{{ call.result }}</p>
      </article>
    } @else {
      <p>Loading weather for {{ call.args.city ?? "…" }}</p>
    }
  `,
})
export class WeatherCardComponent implements ToolRenderer<WeatherArgs> {
  readonly toolCall = input.required<AngularToolCall<WeatherArgs>>();
}

Pass the class as component when the tool runs in the browser:

registerFrontendTool({
  name: "getWeather",
  description: "Get the current weather for a city",
  parameters: z.object({ city: z.string() }),
  component: WeatherCardComponent,
  handler: async ({ city }, { signal }) => {
    const response = await fetch(`/api/weather?city=${encodeURIComponent(city)}`, {
      signal,
    });
    return response.text();
  },
});

Use registerRenderToolCall instead when the tool runs on the server and the browser only renders its call:

registerRenderToolCall({
  name: "getWeather",
  args: z.object({ city: z.string() }),
  component: WeatherCardComponent,
});

Ask the agent for the weather in Paris. The weather card shows "Loading weather for Paris", then the city and the tool result.

Next steps

How is this guide?