Skip to content

Commit 5bb1f47

Browse files
committed
Update README.md
1 parent 0154cc9 commit 5bb1f47

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,67 @@ return { messages: [result] };
123123

124124
This approach guarantees the message remains completely hidden from the user interface.
125125

126+
## Rendering Artifacts
127+
128+
The Agent Chat UI supports rendering artifacts in the chat. Artifacts are rendered in a side panel to the right of the chat. To render an artifact, you can obtain the artifact context from the `thread.meta.artifact` field. Here's a sample utility hook for obtaining the artifact context:
129+
130+
```tsx
131+
export function useArtifact<TContext = Record<string, unknown>>() {
132+
type Component = (props: {
133+
children: React.ReactNode;
134+
title?: React.ReactNode;
135+
}) => React.ReactNode;
136+
137+
type Context = TContext | undefined;
138+
139+
type Bag = {
140+
open: boolean;
141+
setOpen: (value: boolean | ((prev: boolean) => boolean)) => void;
142+
143+
context: Context;
144+
setContext: (value: Context | ((prev: Context) => Context)) => void;
145+
};
146+
147+
const thread = useStreamContext<
148+
{ messages: Message[]; ui: UIMessage[] },
149+
{ MetaType: { artifact: [Component, Bag] } }
150+
>();
151+
152+
return thread.meta?.artifact;
153+
}
154+
```
155+
156+
After which you can render additional content using the `Artifact` component from the `useArtifact` hook:
157+
158+
```tsx
159+
import { useArtifact } from "../utils/use-artifact";
160+
import { LoaderIcon } from "lucide-react";
161+
162+
export function Writer(props: {
163+
title?: string;
164+
content?: string;
165+
description?: string;
166+
}) {
167+
const [Artifact, { open, setOpen }] = useArtifact();
168+
169+
return (
170+
<>
171+
<div
172+
onClick={() => setOpen(!open)}
173+
className="cursor-pointer rounded-lg border p-4"
174+
>
175+
<p className="font-medium">{props.title}</p>
176+
<p className="text-sm text-gray-500">{props.description}</p>
177+
</div>
178+
179+
<Artifact title={props.title}>
180+
<p className="whitespace-pre-wrap p-4">{props.content}</p>
181+
</Artifact>
182+
</>
183+
);
184+
}
185+
```
186+
126187
## Going to Production
127188

128189
Once you're ready to go to production, you'll need to update how you connect, and authenticate requests to your deployment. By default, the Agent Chat UI is setup for local development, and connects to your LangGraph server directly from the client. This is not possible if you want to go to production, because it requires every user to have their own LangSmith API key, and set the LangGraph configuration themselves.

0 commit comments

Comments
 (0)