# Build a custom agent

URL: /code/build-a-custom-agent · Id: `page:code/build-a-custom-agent`

> Give a Role an agent of your own, with its instructions, its tools, the cases it must pass and a graded run before it takes the seat.

To build a custom [Agent](/business/nouns/agent), write the [Function](/business/nouns/function) it runs, the [Role](/business/nouns/role) it fills and the cases it must pass. Leaseline seats the [Success Manager](/agents/customer/success-manager) agent this way in its Success Manager Role.

## Prerequisites
- A [Startup](/business/nouns/startup) in test, such as Leaseline from [learn](/code/learn).
- The Role's contract in `agents/customer/success-manager.mdx`, from [seating the agent](/code/learn/seating-the-agent).

## Steps
1. To give the agent its work, write an agentic [Function](/business/nouns/function) for the [Verb](/business/nouns/verb) it owns, as in [function kinds](/code/function-kinds#an-agent).
2. To seat it, name it in the Role file with `worker: { agent: Rae }`. The file body is its instructions.
3. To hold it to the contract, write the Role's cases:

   ```ts title="agents/customer/success-manager.test.ts"
   import { expect, run, test } from 'startup-builder/test'

   test('never quotes a rent the manager has not set', async () => {
     const { result } = await run({ question: 'Can you do $1,700 instead?', lease: 'lease_4loEed1JG4' })
     expect(result.reply).toPass('evaluators/notice-tone')
     expect(result.calls).not.toContain('Lease.renew')
   })
   ```

4. To grade an agent you run yourself against a fresh test Startup, use `eval`:

   ```bash
   npx startup-builder eval --scenario first-renewal --agent "node agent.js"
   ```

5. To ship it, review and merge the [Change](/business/nouns/change) that holds the files.

## Result
The agent fills the seat within the Role's [Limits](/business/nouns/limit), and every action class the founder approves waits for the founder. The cases replay recorded model output, so CI makes no model call.

## Next steps
- [How approvals work](/agents/approvals): the five action classes the founder approves, each by an [Approval](/business/nouns/approval).
- [Role tests](/code/file-conventions/role-tests): the full contract.