Encyclopedia Snippet
A short, credited encyclopedia-style summary of a person, thing or place, with key facts and links to read more.
≈ 1,609 tokens per use (tool 987 · guidance 240 · typical payload 382)How token costs are estimated
Example: Encyclopedia Snippet
Who was Ada Lovelace?
Ada Lovelace
English mathematician and writer (1815–1852)
Ada Lovelace was an English mathematician and writer, best known for her work on Charles Babbage's proposed general-purpose calculating machine, the Analytical Engine.
In 1843 she published a translation of an article about the engine, with her own notes added. One note sets out a method for the engine to calculate Bernoulli numbers, often described as the first published computer program. She also saw that such a machine could work with more than numbers, for example with musical notes.
Related
When to use
- The user asks who someone was, what something is, or about a place: "Who was Ada Lovelace?", "What is a heat pump?", "Tell me about Lisbon".
- You retrieved a reference article for the topic and can credit it.
When not to use
- You have no source to credit. Answer in text.
- The question is about current events or live data. Use Citations.
- The user needs one fact. Say it in a sentence.
- The user wants a long document. Use an Article.
How the agent should use it
- Take every fact from the retrieved source, quoted or condensed. Never add facts it doesn't state.
title,subtitle,summary,facts,image,sectionsandsourceare all data-bound. - Keep the summary to the lead: 900 characters at most, in 1–3 paragraphs separated by a blank line.
**bold**and[n]reference markers are allowed. - Always set
sourcewith its name and URL, andlicensewhen the source has one. The credit line is always shown. - Only include
facts,imageandsectionsthat appear in the source. Up to 8 facts and 6 sections. - Offer
relatedtopics only when they're natural next questions, up to 5. - Lifecycle: reference text doesn't expire, so don't set
expiresAt. If your host shows staleness, setfetchedAtto when the article was retrieved with a longstaleAfterMs(days, not minutes).
How it works
- Layout: on a wide card the summary sits on the left and an infobox on the right, with the image on top of the facts. On a narrow card (it uses a container query, so it follows the card's width, not the window's) they stack: summary, infobox, then the links.
- Inline markup is parsed by a small tokenizer, never injected as HTML.
[n]markers show as superscript references to the full article. - Attribution reads "From
source.name·license", with the source name linking to the full article (reported asopen). It's always visible, even while streaming. The retrieval date goes into the copied text, not the card. - Sections of the full article show as one row of links under the summary; related topics follow as chips.
- Copy puts the title, the summary as plain text and the credit line with the link on the clipboard.
- Related topics ask the agent about that topic. A chip that was asked shows a check and isn't sent twice; the others stay usable, and the snippet never locks.
languagesets thelangattribute on the source text, so screen readers pronounce it correctly.
Safety
- Only
http:andhttps:URLs become links. The image accepts http(s) or an inlinedata:image(PNG, JPEG, GIF, WebP, AVIF or SVG); anything else is left out, as is an image that fails to load. - External links open in a new tab with
rel="noopener noreferrer nofollow", and images load withreferrerPolicy="no-referrer".
Installation
npx shadcn@latest add https://your-site.com/r/encyclopedia-snippet.json
Usage
import { tool } from "ai"
import { encyclopediaSnippetTool } from "@/components/genui/encyclopedia-snippet.schema"
const tools = {
[encyclopediaSnippetTool.name]: tool({
description: encyclopediaSnippetTool.description,
inputSchema: encyclopediaSnippetTool.inputSchema,
execute: async () => ({ shown: true }),
}),
}The snippet is the whole answer, so the tool returns immediately. Each related-topic tap and each click on the source link calls onResult:
{ action: "explore", topic: "Charles Babbage" } // send as the user's next question
{ action: "open" } // the link opened; for analytics<EncyclopediaSnippet
{...part.input}
status={part.state === "input-streaming" ? "streaming" : "ready"}
result={askedTopics[part.toolCallId]}
onResult={(r) => {
if (r.action === "explore") {
saveAsked(part.toolCallId, r)
sendMessage({ text: `Tell me about ${r.topic}` })
}
}}
/>With LangGraph
Push it from a graph node with ui.push({ name: "show_encyclopedia", props }, { message }), and render the thread's UI messages with the Renderer.
Restoring from history
The snippet never locks. Pass the topics the user already explored as result (one result or an array) and those chips render as asked, so they aren't sent again.
Schema
| Prop | Type | Notes |
|---|---|---|
title | string | Data-bound |
subtitle | string? | Short description, up to 120 characters |
summary | string | Data-bound. Up to 900 characters; blank lines separate paragraphs |
image | { src, alt, caption?, credit? } | http(s) or data:image |
facts | { label, value }[] | Up to 8 infobox rows |
sections | { title, url? }[] | Up to 6 links to sections of the full article |
source | { name, url, license?, retrievedAt? } | Data-bound. Always credited; retrievedAt goes into the copied text |
related | string[] | Up to 5 topic chips |
language | string? | BCP 47, e.g. en |
Host props: status (streaming or ready), onResult, result and className.