# Create an agent

Create an agent with a model, the instructions it follows on every reply and the tools it can use.

## Before you start

You need a project. See [Create a project](/docs/projects/create-project.md).

## Create an agent

**Studio**

1. In your project, open **Agents**.
2. Click **Create agent**.
3. Enter `Support assistant` as the **Name**.
4. Enter the **Instructions**: `Answer customer questions about orders and refunds. Keep replies to two sentences.`
5. Leave the **Model** as it is to use the project's default, or pick another.
6. Click **Create agent**. You can add skills, knowledge and tools later.
7. Open **Chat**.
8. Pick Support assistant under the message box.
9. Write "Can I get a refund on an order I placed yesterday?" in the message box.
10. Press Enter. You should now see Support assistant answer in two sentences or fewer.

**Code**

1. Add the agent. Its `system` is the instructions it follows on every reply; leave out `model` to use the project's default:

```ts title="agents/support.ts"
import { agent } from "veryfront/agent";

export default agent({
  id: "support",
  name: "Support assistant",
  system: "Answer customer questions about orders and refunds. Keep replies to two sentences.",
});
```

2. Start the project with `npm run dev`. It syncs the project to Veryfront.
3. Open **Chat** in Studio.
4. Pick Support assistant.
5. Ask "Can I get a refund on an order I placed yesterday?". You should now see Support assistant answer in two sentences or fewer.

### Try it in a sandbox

```playground
step: Create a project | npm create -y veryfront@latest support-desk -- --template ai-agent --yes
step: Add the agent | cd support-desk && mkdir -p agents && printf '%s\n' 'import { agent } from "veryfront/agent";' '' 'export default agent({' '  id: "support",' '  name: "Support assistant",' '  system: "Answer customer questions about orders and refunds. Keep replies to two sentences.",' '});' > agents/support.ts
step: Start it | npm run dev
agent: support
ask: Can I get a refund on an order I placed yesterday?
expect: refund
```

**API**

1. Set `PROJECT` to your project's ID ([Find your IDs](/docs/authentication/api-keys.md#find-your-ids)): `export PROJECT=<id>`.
2. Create the agent with your [API key](/docs/authentication/api-keys.md). Leave out `model` to use the project's default:

```bash
curl -X POST https://api.veryfront.com/projects/$PROJECT/agents \
  -H "Authorization: Bearer $VERYFRONT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "id": "support",
    "name": "Support assistant",
    "system_prompt": "Answer customer questions about orders and refunds. Keep replies to two sentences."
  }'
```

3. Get the agent. You should now see `"name": "Support assistant"` and your instructions in `system_prompt`:

```bash
curl https://api.veryfront.com/projects/$PROJECT/agents/support \
  -H "Authorization: Bearer $VERYFRONT_API_KEY"
```

### Try it in a sandbox

```playground
step: Set PROJECT | export PROJECT=$VERYFRONT_PROJECT_ID
step: Create the agent | curl -X POST https://api.veryfront.com/projects/$PROJECT/agents -H "Authorization: Bearer $VERYFRONT_API_KEY" -H "Content-Type: application/json" -d '{"id": "support", "name": "Support assistant", "system_prompt": "Answer customer questions about orders and refunds. Keep replies to two sentences."}'
check: curl https://api.veryfront.com/projects/$PROJECT/agents/support -H "Authorization: Bearer $VERYFRONT_API_KEY"
expect: Keep replies to two sentences.
```

## With MCP

`my-project` is your project's reference: its slug or its ID.

1. Call `veryfront__create_agent`. The instructions go in `system`; leave out `model` to use the project's default:

```json
{
  "project_reference": "my-project",
  "id": "support",
  "name": "Support assistant",
  "system": "Answer customer questions about orders and refunds. Keep replies to two sentences."
}
```

2. Call `veryfront__get_agent` with `"project_reference": "my-project"` and `"agent_id": "support"`. It worked when the agent comes back with `"name": "Support assistant"`.

## Next steps

* [Add a tool](/docs/agents/tools.md)
* [Chat with your agent](/docs/agents/chat.md)
