> ## Documentation Index
> Fetch the complete documentation index at: https://docs.canary.effectiveai.app/llms.txt
> Use this file to discover all available pages before exploring further.

# Create and run an agent

> Save a research agent for a line of business, run it from the API or an AI assistant, and get back a comparison that cites each filing.

A saved agent keeps your instructions, model and tools, so the same kind of research runs the same way each time. You send it a question, and a few minutes later it returns a Markdown reply that cites the SERFF tracking number behind each fact.

This guide saves an agent that researches how insurers rate boatowners coverage, then asks it to compare two carriers in Florida. Here is part of a real reply to that request:

> **Bottom line:** The two carriers with Florida boatowners rate filings that include rate pages are American Modern Property and Casualty (FL-26-028984) and Atlantic Specialty (FL-26-019149). American Modern prices named storm as its own hull coverage with 1%–20% options. Atlantic Specialty has no separate named-storm deductible and instead sets a minimum 10% windstorm deductible.
>
> | | American Modern, FL-26-028984 | Atlantic Specialty, FL-26-019149 |
> | - | - | - |
> | Rate change | Exhibit B: Hull -13.2%, Liability 0.0%, overall -11.5% | -20.4% requested and -19.4% indicated; 55 policies in force |
> | Named storm | Separate Hull - Named Storm coverage, with percentage deductibles of 1, 2, 3, 4, 5, 10, 15 and 20% | "Yachts subject to this manual are subject to a minimum 10% windstorm deductible." Waived to 1% (minimum \$300) with a hurricane-protection plan |

The full reply goes on to rating factors, deductibles, fees, and the conflicts and gaps it found in each filing.

You need an [Effective API key](https://docs.canary.effectiveai.app/getting-started/authentication.md) for a workspace member who can spend credits, and `jq` to build the request. To work from an AI assistant instead, see [Run it from an AI assistant](#run-it-from-an-ai-assistant).

## Save the agent

Write the instructions as plain text. Say what to report for each filing, how to cite it, and what to do when a filing does not show something or the request leaves a choice open.

```bash theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
cat > instructions.md <<'EOF'
You research how insurers rate boatowners and personal watercraft coverage, using their rate and rule filings.

For each carrier and state in the request, find the most recent rate or rule filing and read its rate pages and rules. Report what applies of the following:
- How the base premium is set, such as by hull value, boat type and length, and how liability is priced.
- The main rating factors and their ranges, such as horsepower or top speed, boat age, operator age and experience, and navigation territory.
- Discounts and surcharges, such as a boating safety course credit or a high-performance surcharge.
- Deductible options, including any separate named-storm deductible.
- Minimum premiums and fees.
- The overall rate change and what the filing gives as its reasons.

Cite the SERFF tracking number for each fact. When a filing does not show something, say so rather than estimating it. Keep what the filing states apart from your own reading of it, and note when a rule applies in one state only. When the request leaves a choice open, such as which carriers to compare, choose the carriers with the most recent filings and say which you chose.
EOF
```

Then save the agent with those instructions. Pick a model from `GET /api/v2/agents/models`.

```bash theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
jq --null-input --rawfile instructions instructions.md '{
  name: "Boatowners rating plan researcher",
  description: "Researches how insurers rate boatowners coverage from their rate and rule filings.",
  model: "claude-sonnet-5-5",
  inheritWorkspaceTools: true,
  instructions: $instructions
}' | curl --request POST \
  --url "https://api.canary.effectiveai.app/api/v2/agents" \
  --header "Authorization: Bearer $EFFECTIVE_API_KEY" \
  --header 'Content-Type: application/json' \
  --data @-
```

`inheritWorkspaceTools: true` gives the agent the same tools as Effective's own agent, within the access of whoever starts a session, so it can search filings and read their rate pages. The API returns `201 Created`. Copy the agent's `id` and `version`. Abbreviated response:

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{
  "id": "agent_a73193f8-de15-457e-8ee9-7c9086f3ef6c",
  "name": "Boatowners rating plan researcher",
  "model": "claude-sonnet-5-5",
  "inheritWorkspaceTools": true,
  "tools": [],
  "projectId": null,
  "version": "1"
}
```

To research another line, keep the shape and change what to report. For pet insurance, ask about breed and age factors and reimbursement options. For motorcycle, ask about engine size, riding experience and seasonal lay-up. Keep the closing rules: they make replies easy to check, and they let the agent decide small things on its own instead of stopping to ask.

## Ask it a question

Start a session with the agent's `id` and `version` and your question. Use a new `Idempotency-Key` for each session, and the same key if you retry the request after a network error, so a retry does not start a second session. Any UUID works, for example from `uuidgen` or `openssl rand -hex 16`.

```bash theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
curl --request POST \
  --url "https://api.canary.effectiveai.app/api/v2/sessions" \
  --header "Authorization: Bearer $EFFECTIVE_API_KEY" \
  --header "Idempotency-Key: $(uuidgen)" \
  --header 'Content-Type: application/json' \
  --data '{
    "agentId": "agent_a73193f8-de15-457e-8ee9-7c9086f3ef6c",
    "agentVersion": "1",
    "title": "Florida boatowners rating plans",
    "message": "Compare how two carriers rate boatowners coverage in Florida in their most recent rate filings. Which factors move the premium most, and how do their named-storm deductibles differ?"
  }'
```

The response gives the session `id` and the `message.id` of your question:

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{
  "id": "01a2397f-531c-762b-b8f1-356c90109f63",
  "status": "running",
  "message": { "id": "01a2397f-5f45-77f9-af22-df6374e4a27a", "status": "queued" }
}
```

## Wait for the reply

Research across several filings takes a few minutes. Read the message until its `status` is no longer `queued` or `running`. This loop checks every 20 seconds and prints the reply:

```bash theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
SESSION=01a2397f-531c-762b-b8f1-356c90109f63
MESSAGE=01a2397f-5f45-77f9-af22-df6374e4a27a
while true; do
  RESULT=$(curl --request GET \
    --url "https://api.canary.effectiveai.app/api/v2/sessions/$SESSION/messages/$MESSAGE" \
    --header "Authorization: Bearer $EFFECTIVE_API_KEY")
  STATUS=$(echo "$RESULT" | jq -r .status)
  case "$STATUS" in queued|running) sleep 20 ;; *) break ;; esac
done
echo "$STATUS"; echo "$RESULT" | jq -r .reply
```

When `status` is `succeeded`, `reply` holds the Markdown comparison shown at the top of this page. It is the agent's final answer: what the agent wrote about its work along the way is left out. Abbreviated response:

```json theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
{
  "id": "01a2397f-5f45-77f9-af22-df6374e4a27a",
  "status": "succeeded",
  "reply": "**Bottom line:** The two carriers with Florida boatowners rate filings that include rate pages are American Modern ...",
  "finishedAt": "2026-12-03T01:27:02.976Z",
  "failure": null
}
```

The other statuses:

* `needs_input`: the agent asked you something. See [Answer the agent's questions](https://docs.canary.effectiveai.app/guides/agents/answer-questions.md).
* `failed`: `failure.error` says what went wrong.

To stop a reply, call `POST /api/v2/sessions/{id}/messages/{messageId}/cancel`. The message then ends as `failed`, with `cancellationStatus` `cancelled`.

To ask a follow-up, such as another state or a third carrier, send it to `POST /api/v2/sessions/{id}/messages` and wait for its reply the same way. To be told when a reply is ready instead of polling, subscribe a [webhook](https://docs.canary.effectiveai.app/guides/webhooks.md) to `session.message.completed`.

## Run it from an AI assistant

An assistant [connected to Effective](https://docs.canary.effectiveai.app/getting-started/using-with-agents.md) can save and run the same agent. Ask it in plain language:

```text Prompt theme={"languages":{"custom":["languages/rsl.tmLanguage.json"]}}
Save an Effective agent named "Boatowners rating plan researcher" that inherits workspace tools, with these instructions: <paste the instructions above>. Then ask it to compare how two carriers rate boatowners coverage in Florida, and show me its reply.
```

The assistant saves the agent with the `mutate` tool and runs it with the `agent` tool. It waits for the reply, and if the agent asks a question, it shows you the question and sends your answer back.

## Next steps

* [Answer the agent's questions](https://docs.canary.effectiveai.app/guides/agents/answer-questions.md) when a reply stops at `needs_input`.
* [Manage agents](https://docs.canary.effectiveai.app/guides/agents/manage.md): change the instructions and keep each version, share an agent in a project, choose its tools, and delete it.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.