---
title: "CopilotTask"
description: "Execute one-off tasks using Copilot intelligence."
---
This class is used to execute one-off tasks, for example on button press. It
can use the context available via [useMakeCopilotReadable](../useMakeCopilotReadable)
and the actions provided by [useMakeCopilotActionable](../useMakeCopilotActionable), or
you can provided your own context and actions.
```jsx CopilotTask Example
import {
CopilotTask,
useCopilotContext
} from "@copilotkit/react-core";
const task = new CopilotTask({
instructions: "Set a random message",
actions: [
{
name: "setMessage",
description: "Set the message.",
argumentAnnotations: [
{
name: "message",
type: "string",
description:
"A message to display.",
required: true,
},
],
implementation: async (message) => {
// ...
},
}
]
});
const context = useCopilotContext();
await task.run(context);
```
In the simplest case, use CopilotTask in the context of your app by giving it instructions on what to do.
```jsx
import {
CopilotTask,
useCopilotContext
} from "@copilotkit/react-core";
const randomSlideTask = new CopilotTask({
instructions: "Make a random slide",
});
const context = useCopilotContext();
return (
);
```
Have a look at the [Hello world example](https://github.com/CopilotKit/CopilotKit/blob/main/CopilotKit/examples/next-openai/src/app/helloworld/page.tsx)
for a more complete example.
It's also possible to provide your own context and actions. In addition, you can specify to ignore
`useMakeCopilotReadable` and `useMakeCopilotActionable`.
```jsx
import {
CopilotTask,
useCopilotContext
} from "@copilotkit/react-core";
const standaloneTask = new CopilotTask({
instructions: "Do something standalone",
data: [...],
actions: [...],
includeCopilotReadable: false, // Don't use current context
includeCopilotActionable: false, // Don't use current actions
});
const context = useCopilotContext();
standaloneTask.run(context);
```
## Constructor
The instructions to be given to the assistant.
An array of action definitions that can be called.
Whether to include the copilot readable context in the task.
Whether to include actions defined via `useMakeCopilotActionable` in the task.
## run()
Run the task.
The CopilotContext to use for the task. Use `useCopilotContext` to obtain the current context.
The data to use for the task.