How do I create an agent?
"use client"
import { useEffect, useState } from "react"
import { Message, MessageContent } from "@/components/ui/message"
import { Orb } from "@/components/ui/orb"
import { Response } from "@/components/ui/response"
const assistantMessageTokens = [
"To",
" create",
" a",
" new",
" agent",
" with",
" **",
"ElevenLabs",
" Agents",
"**",
",",
" head",
" to",
" this",
" link",
":",
" ",
"[",
"https://elevenlabs.io/app/agents",
"](",
"https://elevenlabs.io/app/agents",
")",
".",
"\n\n",
"1.",
" Sign",
" in",
" to",
" your",
" ElevenLabs",
" account",
".",
"\n",
"2.",
" Click",
" **New",
" Agent**",
" to",
" start",
".",
"\n",
"3.",
" Give",
" your",
" agent",
" a",
" name",
" and",
" description",
".",
"\n",
"4.",
" Configure",
" its",
" behavior",
",",
" knowledge",
" sources",
",",
" and",
" voice",
".",
"\n",
"5.",
" Save",
" it",
" —",
" and",
" your",
" agent",
" is",
" ready",
" to",
" use",
".",
]
const Example = () => {
const [content, setContent] = useState("\u200B")
const [isStreaming, setIsStreaming] = useState(false)
useEffect(() => {
let currentContent = ""
let index = 0
const startTimeout = setTimeout(() => {
setIsStreaming(true)
}, 500)
const interval = setInterval(() => {
if (index < assistantMessageTokens.length) {
currentContent += assistantMessageTokens[index]
setContent(currentContent)
index++
} else {
clearInterval(interval)
setIsStreaming(false)
}
}, 100)
return () => {
clearInterval(interval)
clearTimeout(startTimeout)
}
}, [])
return (
<>
<style jsx global>{`
.message-demo-lists ol,
.message-demo-lists ul {
padding-left: 1.25rem !important;
}
.message-demo-lists li {
margin-left: 0 !important;
}
`}</style>
<div className="flex h-full max-h-[400px] w-full max-w-2xl flex-col overflow-hidden">
<div className="flex flex-col gap-4 overflow-y-auto px-4 py-4">
<div className="flex-shrink-0">
<Message from="user">
<MessageContent>
<Response>How do I create an agent?</Response>
</MessageContent>
</Message>
</div>
<div className="message-demo-lists flex-shrink-0">
<Message from="assistant">
<MessageContent>
<Response>{content}</Response>
</MessageContent>
<div className="ring-border size-8 overflow-hidden rounded-full ring-1">
<Orb
className="h-full w-full"
agentState={isStreaming ? "talking" : null}
/>
</div>
</Message>
</div>
</div>
</div>
</>
)
}
export Example
Installation
pnpm dlx @elevenlabs/agents-cli@latest components add message
Usage
import { Message, MessageAvatar, MessageContent } from "@/components/ui/message"
Basic Message
<Message from="user">
<MessageAvatar src="/user-avatar.jpg" name="John" />
<MessageContent>Hello, how can I help you?</MessageContent>
</Message>
<Message from="assistant">
<MessageAvatar src="/assistant-avatar.jpg" name="AI" />
<MessageContent>I'm here to assist you with any questions!</MessageContent>
</Message>
Message Variants
The MessageContent
component supports two variants:
{
/* Contained variant - default, has background and padding */
}
;<Message from="user">
<MessageAvatar src="/user-avatar.jpg" />
<MessageContent variant="contained">
This is a contained message with background
</MessageContent>
</Message>
{
/* Flat variant - no background for assistant, minimal styling */
}
;<Message from="assistant">
<MessageAvatar src="/assistant-avatar.jpg" />
<MessageContent variant="flat">
This is a flat message with minimal styling
</MessageContent>
</Message>
In a Conversation
import { Conversation, ConversationContent } from "@/components/ui/conversation"
import { Message, MessageAvatar, MessageContent } from "@/components/ui/message"
;<Conversation>
<ConversationContent>
{messages.map((message) => (
<Message key={message.id} from={message.from}>
<MessageAvatar src={message.avatarUrl} name={message.name} />
<MessageContent>{message.content}</MessageContent>
</Message>
))}
</ConversationContent>
</Conversation>
API Reference
Message
The main container component that handles layout and alignment based on message sender.
Props
Prop | Type | Description |
---|---|---|
from | "user" | "assistant" | Required. Determines alignment and styling |
className | string | Optional CSS classes |
...props | HTMLDivElement | All standard div element props |
MessageContent
Container for message text and content with variant styling.
Props
Prop | Type | Description |
---|---|---|
variant | "contained" | "flat" | Visual style variant (default: "contained") |
className | string | Optional CSS classes |
children | ReactNode | Message content |
...props | HTMLDivElement | All standard div element props |
MessageAvatar
Avatar component for displaying user or assistant profile images.
Props
Prop | Type | Description |
---|---|---|
src | string | Required. Avatar image URL |
name | string | Name for fallback (shows first 2 chars if no image) |
className | string | Optional CSS classes |
...props | AvatarProps | All standard Avatar component props |
Notes
- Uses CSS group selectors for context-aware styling based on
from
prop - User messages align to the right, assistant messages to the left
- Contained variant provides background colors that differ for user/assistant
- Flat variant is useful for assistant messages in a minimal design
- Avatar has a subtle ring border and fallback text support
- Works seamlessly with the Conversation component
- This component is inspired by Vercel's AI SDK Message component with modifications for ElevenLabs UI
Deploy and Scale Agents with ElevenLabs
ElevenLabs delivers the infrastructure and developer experience you need to ship reliable audio & agent applications at scale.
Talk to an expert