# Angular LLM Kit Chain of Thought

When an agent takes multiple steps to answer a question—searching the web, analyzing documents, querying a database—a single reasoning block cannot show how the work is structured in detail. Use the ChainOfThought component to make each operation visible in sequence.

The [ChainOfThought component](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/chainofthoughtcomponent) renders each operation step as a named row under one collapsible header. This format helps users follow the sequence of the agent's work and gives you control over how each step appears.

The following example demonstrates the ChainOfThought component displaying a step-by-step sequence of operations.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/conversational-ui/llm-kit/chain-of-thought/source.txt)

## Rendering Thought Rows

The [`thoughts`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/chainofthoughtcomponent#thoughts) property accepts an ordered array of [`Thought`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/thought) objects. Add a new thought to the array when its operation starts and update its [`label`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/thought#label) and [`completed`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/thought#completed) properties dynamically as the operation progresses.

Each thought can include supporting context in its [`secondaryLabel`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/thought#secondarylabel) property, detailed output in its [`content`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/thought#content) property, and an operation icon through its [`icon`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/thought#icon) or [`svgIcon`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/thought#svgicon) inputs.

The following snippets show how to configure the ChainOfThought header and its thought rows.

```HTML
<kendo-chainofthought
    [svgIcon]="brainIcon"
    label="Thought"
    secondaryLabel="for 6.0s"
    [thoughts]="thoughts"
    [expandable]="true"
></kendo-chainofthought>
```

```TypeScript
public thoughts: Thought[] = [
    { id: 1, label: 'Analyzing query intent', svgIcon: searchIcon, completed: true },
    { id: 2, label: 'Selecting relevant tables', secondaryLabel: '3 found', svgIcon: tableIcon, completed: true },
    { id: 3, label: 'Building SQL query', content: 'GROUP BY customer_name ORDER BY total DESC', svgIcon: codeIcon }
 ];
```

The component-level [`label`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/chainofthoughtcomponent#label) and [`secondaryLabel`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/chainofthoughtcomponent#secondarylabel) properties describe the chain as a whole. Use them for a concise summary that remains visible when the thought rows are collapsed.

## Showing Chain Progress

After the final operation completes, set the [`completed`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/chainofthoughtcomponent#completed) property of the ChainOfThought to `true`. The header will then communicate that the chain has finished by replacing its in-progress shimmering effect with a completed rendering of the header.

For coding workflows, [`linesAdded`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/chainofthoughtcomponent#linesadded) and [`linesRemoved`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/chainofthoughtcomponent#linesremoved) expose diff counters directly in the header so reviewers can see the scope of a change at a glance. Leave these properties unset for workflows that do not report line changes.

Use the [`expanded`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/chainofthoughtcomponent#expanded) property when you need to control the disclosure of the chain through the application state. Use the [`expandedChange`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/chainofthoughtcomponent#expandedchange) event when your application needs to respond to changes in the chain's disclosure state.

```HTML
<kendo-chainofthought
    [thoughts]="thoughts"
    [completed]="isComplete"
    [linesAdded]="linesAdded"
    [linesRemoved]="linesRemoved"
    [expanded]="isExpanded"
    (expandedChange)="isExpanded = $event"
></kendo-chainofthought>
```

```TypeScript
public thoughts: Thought[] = [
    { id: 1, label: 'Analyzing query intent', completed: true },
    { id: 2, label: 'Selecting relevant tables', completed: true },
    { id: 3, label: 'Building SQL query', completed: true }
];

public isComplete: boolean = true;
public linesAdded: number = 12;
public linesRemoved: number = 3;
public isExpanded: boolean = true;
```

## Customizing the Thoughts

The default row layout covers common thought data elements. For richer step content, provide a custom template through the [`kendoThoughtTemplate`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/thoughttemplatedirective) directive and render the current [`Thought`](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/thought) item as needed. The template allows you to define how each step is rendered, giving you full control over the presentation of the thinking process.

```html
<kendo-chainofthought [thoughts]="thoughts">
    <ng-template kendoThoughtTemplate let-thought>
        <kendo-svgicon [icon]="thought.svgIcon" size="small"></kendo-svgicon>
        <span>{{ thought.label }}</span>
        <span>{{ thought.secondaryLabel }}</span>
        <span>{{ thought.content }}</span>
    </ng-template>
</kendo-chainofthought>
```

The following example demonstrates a custom template that adds step categories, tool details, and durations while preserving the standard thought icons.

[Demo Source](https://demos.telerik.com/kendo-angular-ui/demos/conversational-ui/llm-kit/chain-of-thought-custom-template/source.txt)

## See Also

* [LLM Kit Overview](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/llm-kit)
* [Reasoning](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/llm-kit/reasoning)
* [API Reference of the ChainOfThoughtComponent](https://www.telerik.com/kendo-angular-ui-develop/components/conversational-ui/api/chainofthoughtcomponent)
