showcase/shell-docs/src/content/reference/vue/hooks/useSuggestions.mdx
useSuggestions provides reactive access to the current chat suggestions for a given agent. It subscribes to suggestion changes on the CopilotKit core and updates its returned refs whenever suggestions are added, cleared, reloaded, or finish loading.
Suggestions are configured via useConfigureSuggestions and can be either static (a predefined list) or dynamic (generated by the agent).
import { useSuggestions } from "@copilotkit/vue/v2";
function useSuggestions(options?: UseSuggestionsOptions): UseSuggestionsResult;
The composable returns an object of Vue refs and control functions. Because suggestions and isLoading are refs, access their .value in <script setup> (they unwrap automatically in <template>).
<script setup lang="ts">
import { useSuggestions } from "@copilotkit/vue/v2";
const { suggestions, isLoading } = useSuggestions();
</script>
<template>
<div v-if="isLoading">Loading suggestions...</div>
<ul v-else>
<li v-for="(suggestion, i) in suggestions" :key="i">
<strong>{{ suggestion.title }}</strong>
<p>{{ suggestion.message }}</p>
</li>
</ul>
</template>
<script setup lang="ts">
import { useSuggestions } from "@copilotkit/vue/v2";
const { suggestions, reloadSuggestions, clearSuggestions, isLoading } =
useSuggestions();
</script>
<template>
<div>
<div>
<button :disabled="isLoading" @click="reloadSuggestions">Refresh</button>
<button @click="clearSuggestions">Clear</button>
</div>
<button
v-for="(suggestion, i) in suggestions"
:key="i"
:disabled="suggestion.isLoading"
>
{{ suggestion.title }}
</button>
</div>
</template>
<script setup lang="ts">
import { useSuggestions } from "@copilotkit/vue/v2";
const { suggestions } = useSuggestions({ agentId: "support-agent" });
</script>
<template>
<div>
<h3>Support Agent Suggestions</h3>
<div v-for="(s, i) in suggestions" :key="i">{{ s.title }}</div>
</div>
</template>
Because agentId accepts a ref or getter, the composable re-resolves and re-subscribes whenever the source changes, swapping in the new agent's suggestions automatically.
<script setup lang="ts">
import { ref } from "vue";
import { useSuggestions } from "@copilotkit/vue/v2";
const activeAgentId = ref("default");
const { suggestions } = useSuggestions({ agentId: activeAgentId });
</script>
<template>
<select v-model="activeAgentId">
<option value="default">Default</option>
<option value="support-agent">Support</option>
</select>
<div v-for="(s, i) in suggestions" :key="i">{{ s.title }}</div>
</template>
onSuggestionsChanged, onSuggestionsStartedLoading, onSuggestionsFinishedLoading, onSuggestionsConfigChanged) and updates its refs whenever suggestions are added, removed, updated, or change loading state for the resolved agent. The subscription is cleaned up automatically when the component unmounts.agentId option (a string, ref, or getter), then the agentId from the nearest chat configuration, then the default agent ID ("default").isLoading becomes true when a dynamic suggestion reload begins and returns to false when generation completes.useConfigureSuggestions - configure static or dynamic suggestionsuseCopilotKit - access the underlying CopilotKit instanceCopilotKitProvider - provides the CopilotKit instance to descendant composables