# Agent Account Feedback Survey Flow

Source: https://cli.nylas.com/ai-answers/agent-account-feedback-survey-flow.md
Last updated: 2026-06-29
Verified with Nylas CLI 3.1.28.

## Direct Answer

Agent Account Feedback Survey Flow applies when a product needs post-interaction survey messages with a stable app-owned sender instead of a human OAuth mailbox or a send-only SMTP relay. Use a Nylas Agent Account as the grant, attach workspace policy and rules for guardrails, and pass the grant id explicitly from trusted application code.

Gate survey sends on the completed interaction id, recipient consent state, and recent-send history. The agent can draft the wording, but the application should suppress duplicates and route replies back to the owning support or success workflow.

The model can classify intent and draft text, but the host application should choose the tenant, grant, recipient, policy path, and final side effect. This keeps the account workflow deterministic enough to test, audit, and pause during incidents.

## When This Answer Applies

- A survey or feedback message must go out after an interaction is marked complete, not mid-session.
- The sender must be a stable app-owned identity rather than a human OAuth mailbox or send-only SMTP relay.
- Replies need to route back to a support or success workflow and correlate to the original send.
- Opt-out, consent, and one-survey-per-interaction rules must survive model or worker retries.

## Command Recipe

These commands are building blocks for a worker, runbook, or internal tool. Keep API keys and shell execution outside prompt content.

```bash
nylas auth config --api-key $NYLAS_API_KEY --region us
nylas agent status --json
nylas agent account create feedback-survey-flow@yourapp.nylas.email --json

# Gate the send in host code BEFORE drafting:
#   1. Confirm the interaction is marked complete (read completed_interaction_id).
#   2. Check the recipient is not on the opt-out block list (see below).
#   3. Compute dedupe_key from completed_interaction_id + recipient; skip if already sent.
#   4. Check recent-send history so one recipient is not surveyed twice in a window.
# Only after all four pass does the send run:
nylas email send <agent-grant-id> \
  --to customer@example.com \
  --subject "How was your support experience?" \
  --body "Reply to this email to rate your recent support interaction." \
  --yes \
  --json

# Record an opt-out so future surveys suppress this recipient:
curl -s -X POST "https://api.us.nylas.com/v3/lists/$BLOCK_LIST_ID/items" \
  -H "Authorization: Bearer $NYLAS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"email": "customer@example.com"}'

# Pull the survey reply threads over HTTP to correlate replies to the original send:
curl -s "https://api.us.nylas.com/v3/grants/$GRANT_ID/threads?limit=10" \
  -H "Authorization: Bearer $NYLAS_API_KEY"
```

### Python

```python
from nylas import Client

client = Client(api_key=api_key)
threads = client.threads.list(identifier=grant_id, query_params={"limit": 10})
```

### TypeScript

```typescript
import Nylas from "nylas";

const nylas = new Nylas({ apiKey, apiUri: "https://api.us.nylas.com" });
const threads = await nylas.threads.list({ identifier: grantId, queryParams: { limit: 10 } });
```

## Recommended Agent Workflow

1. Create or select one durable Agent Account for this responsibility.
2. Store the grant id with the tenant, environment, and survey template id.
3. Attach workspace policy and rules before increasing autonomy.
4. After a send succeeds, store the returned message id, thread id, and dedupe key.
5. Subscribe a `message.created` webhook so inbound replies arrive as events rather than polled threads, then match each reply's thread id back to the stored send and hand it to the owning support workflow.
6. Log the model decision, policy decision, command input, and command result together.

## Safety And Operations

Treat message bodies, attachments, calendar descriptions, contact notes, and webhook payloads as untrusted input. Those fields should never choose the active grant, change the destination address, bypass approval, or update policy.

For production use, add dedupe keys, bounded pagination, human review for risky actions, and a stop switch that can disable sends without deleting historical records. Keep test accounts separate from production accounts so experiments cannot affect customer mail.

Handle the three common send failures explicitly. On a policy rejection (HTTP 403), do not retry until the policy or recipient changes — log the rejection and stop. On a rate limit (HTTP 429, error type `rate_limit_error`), back off exponentially and retry with the same dedupe key so no duplicate survey goes out. If the grant is revoked mid-flow, the send fails with a grant error; pause the workflow and surface the revoked grant id instead of retrying against it.

## Minimum Data Contract

- tenant_id
- environment
- agent_account_email
- grant_id
- workspace_id
- policy_id
- rule_ids
- completed_interaction_id
- recipient_email
- recipient_consent_state
- survey_template_id
- dedupe_key
- sent_message_id
- source_thread_id
- command_result_id

## Related Full Guides

- [Getting Started with Agent Accounts](https://cli.nylas.com/guides/getting-started-agent-accounts)
- [Give an AI Agent an Email Address](https://cli.nylas.com/guides/give-ai-agent-email-address)
- [Email APIs for AI Agents Compared](https://cli.nylas.com/guides/email-apis-for-ai-agents-compared)

## Related hubs

- [Email agents](https://cli.nylas.com/ai-answers/email-agents.md)
- [Calendar agents](https://cli.nylas.com/ai-answers/calendar-agents.md)
- [Scheduling and availability agents](https://cli.nylas.com/ai-answers/scheduling-agents.md)
- [Contacts agents](https://cli.nylas.com/ai-answers/contacts-agents.md)
- [Notetaker and meeting agents](https://cli.nylas.com/ai-answers/notetaker-agents.md)
- [MCP agents](https://cli.nylas.com/ai-answers/mcp-agents.md)
- [Agent accounts](https://cli.nylas.com/ai-answers/agent-accounts.md)
- [Framework and language email agents](https://cli.nylas.com/ai-answers/framework-email-agents.md)
- [Email and calendar API comparisons](https://cli.nylas.com/ai-answers/ai-agent-email-api-comparisons.md)
- [Email integration and automation recipes](https://cli.nylas.com/ai-answers/email-integration-recipes.md)
- [Agent email workflows](https://cli.nylas.com/ai-answers/agent-email-workflows.md)
- [Security for email and calendar agents](https://cli.nylas.com/ai-answers/security-for-email-agents.md)
- [Operations runbooks for agents](https://cli.nylas.com/ai-answers/operations-for-email-calendar-agents.md)

## Try Nylas CLI

Install the CLI with `curl -fsSL https://cli.nylas.com/install.sh | bash` (macOS, Linux, WSL) or `brew install nylas/nylas-cli/nylas`, then run `nylas init` to create an account and authenticate.

**Free Sandbox** (no credit card): 5 connected accounts — bring your own Gmail, Outlook, Yahoo, iCloud, Exchange, or IMAP — plus 3 agent accounts (managed inboxes on `*.nylas.email`). Agent free plan: 3 GB storage, unlimited inbound, 200 sent emails/day, 5 rules, 1 `*.nylas.email` subdomain, and unlimited custom domains. Production is uncapped and requires a credit card: https://www.nylas.com/pricing/
