A2UI Launched: Full CopilotKit support at launch!

A2UI Launched: CopilotKit has partnered with Google to deliver full support in both CopilotKit and AG-UI!

Check it out
LogoLogo
  • Overview
  • Integrations
  • API Reference
  • Copilot Cloud
Slanted end borderSlanted end border
Slanted start borderSlanted start border
Select integration...

Please select an integration to view the sidebar content.

Tutorial: AI Textarea

Step 4: Copilot Textarea

Currently, our app has a simple textarea for replying to emails. Let's replace this with an AI-powered textarea so that we can benefit from our helpful AI assistant.

The <Reply /> Component

Head over to the /components/Reply.tsx file.

At a glance, you can see that this component uses useState to hold the current input value and provide it to the textarea. We also use the onChange prop of the textarea to update the state.

Implementing <CopilotTextarea />

The <CopilotTextarea /> component was designed to be a drop-in replacement for the <textarea /> component. Let's implement it!

components/Reply.tsx
// ... the rest of the file

import { CopilotTextarea } from "@copilotkit/react-textarea"; 

export function Reply() {
  // ...
  return (
    <div className="mt-4 pt-4 space-y-2 bg-background p-4 rounded-md border">
      <CopilotTextarea
        className="min-h-40 border h-40 p-2 overflow-hidden"
        value={input}
        onChange={(e) => setInput(e.target.value)}
        placeholder="Write your reply..."
        autosuggestionsConfig={{
          textareaPurpose: `Assist me in replying to this email thread. Remember all important details.`,
          chatApiConfigs: {}
        }}
      />
      <Button disabled={!input} onClick={handleReply}>
        Reply
      </Button>
    </div>
  );
}

We import the <CopilotTextarea /> component and use it in place of the <textarea /> component. There are also some optional style changes made here.

We can provide more specific instructions for this particular textarea via the autoSuggestionsConfig.textareaPurpose property.

Try it out!

Now, go back to the app and type anything in the textarea. You will see that the AI assistant provides suggestions as you type. How cool is that?

The CMD + K/CTRL + K Shortcut

While focused on the textarea, you can use the CMD + K (macOS) or CTRL + K (Windows) shortcut to open the action popup. Here, you can give the copilot specific instructions, such as:

  • Rephrase the text to be more formal
  • Make the reply shorter
  • Tell John that I'm happy to help


We have implemented the <CopilotTextarea /> component, but there is an issue - the copilot assistant is not aware of the email thread. In the next step, we'll make CopilotKit aware of our email history.

PREV
Step 2: Setup CopilotKit
Slanted end borderSlanted end border
Slanted start borderSlanted start border
NEXT
Step 3: Copilot Readable State

On this page

The <Reply /> Component
Implementing <CopilotTextarea />
Try it out!
The CMD + K/CTRL + K Shortcut