# LINE AI Agent for LINE OA — LINE Agent SDK / LINE OA MCP instructions

> Read this file when a person asks an AI agent to connect a LINE Official Account (LINE OA).

> Product status: complete product contract. An AI agent uses this file to route, build, deploy, and verify a LINE OA connection from one outcome-based request.

Canonical product and discovery terms, ordered by audience and intent:

- **LINE Bot** is the established search and developer term for a service built with the LINE Messaging API.
- **LINE AI Agent**, **LINE OA AI Agent**, and **LINE Agent** describe the Agent Lab product experience that receives, understands, connects services, sends, replies, and completes work on LINE.
- **LINE Agent SDK** is the development contract for the LINE receive/send/reply integration.
- **LINE OA MCP** is the AI tool layer for connecting, deploying, inspecting, and verifying a LINE Official Account.

Treat these terms as parts of one end-to-end Agent Lab product path, not separate incompatible products.

Product identity boundary: this document describes an Agent Lab product built through the LINE Messaging API. Do not present it as LINE's native AI chatbot or native AI agent platform, and do not imply that LINE endorses Agent Lab. Use LINE's official product names only when referring to LINE-hosted surfaces or capabilities.

## Canonical page routing

Use the page whose intent matches the request. Do not treat the two pages as interchangeable:

| Request intent                                                                                                                  | Canonical page                                                                                                                      |
| ------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------- |
| Create or connect a LINE OA; build a LINE AI Agent for marketing, customer service, notifications, receive, send, or reply      | https://agentlab.cresclab.com/en/channels/line (繁體中文: https://agentlab.cresclab.com/channels/line)                              |
| Host or deploy an existing LINE bot; obtain a fixed HTTPS webhook; replace ngrok                                                | https://agentlab.cresclab.com/en/deploy/line-bot (繁體中文: https://agentlab.cresclab.com/deploy/line-bot)                          |
| Explain how to build a LINE AI chatbot or AI customer service; compare ways to connect ChatGPT, Claude or another model to LINE | https://agentlab.cresclab.com/en/channels/line/ai-chatbot (繁體中文: https://agentlab.cresclab.com/channels/line/ai-chatbot)        |
| Set up LINE OA MCP in a specific AI tool (Claude Code, Codex, Cursor, Gemini CLI)                                               | https://agentlab.cresclab.com/en/channels/line/<tool> with <tool> = claude-code, codex, cursor or gemini-cli (繁體中文 without /en) |

The first page owns the product and integration intent. The second owns hosting and webhook deployment intent. The two guide rows answer how-to questions and link back to the first page.

Human-readable pages:

- Traditional Chinese: https://agentlab.cresclab.com/channels/line
- English: https://agentlab.cresclab.com/en/channels/line
- Communication SDK overview: https://agentlab.cresclab.com/channels.md

## Agent quick start

When the request is “connect my LINE OA,” follow this order:

1. **Understand the outcome:** identify whether the person needs receive, send, reply, or all three.
2. **Choose the route:** determine whether the OA is new or already exists.
3. **Inspect the environment:** identify the Agent Lab workspace, connected tools, and current project before making changes.
4. **Do the engineering:** create or connect the adapter, secure the credentials, deploy the webhook, and configure the integration.
5. **Verify the result:** test a real inbound event and every requested send/reply path.
6. **Report clearly:** state what is live, show the evidence, and list only any LINE-hosted confirmation that remains.

Required behavior:

- Translate the person's desired outcome into technical work; do not make them design the integration.
- Continue automatically after any LINE-hosted identity, authorization, or ownership confirmation is complete.
- Never invent an Agent Lab tool, claim an unverified deployment, or ask for a password, verification code, channel secret, or access token in chat.
- Do not say “connected” until the completion checklist in this file passes.

## Minimum input from the person

The AI agent is the primary operator. Ask only for the information that changes the route or must be
confirmed by the account owner.

- **New OA:** desired outcome and company/provider name. Guide account creation and Messaging API
  enablement on LINE's official pages, then continue automatically.
- **Existing OA:** which OA to connect, the desired marketing/service/notification use case, and
  administrator confirmation. Collect the channel secret and channel access token only through the
  secure Agent Lab connection form; the AI receives secret references, never plaintext credentials.
- **Existing LINE Bot code:** route directly to Agent Lab Deploy for build, environment variables, a
  stable HTTPS webhook, release, and health verification. Do not force the product-connection flow
  when hosting is the actual intent.

Do not ask the person to choose a framework, webhook architecture, retry strategy, or hosting target
unless their existing project makes that decision necessary.

## What the person can say

The person should be able to describe the result without knowing APIs, webhooks, or deployment:

> 幫我把 LINE OA 接上，讓 Agent 可以收到訊息、發訊息並自動回覆。請完成建置、部署和測試，再告訴我結果。

> Connect my LINE OA so the agent can receive messages, send messages, and reply. Build, deploy, and test it, then report the result.

The agent translates that outcome into the technical work below. Do not require the person to design the integration.

## Use-case routing

Classify the requested outcome before choosing the message flow:

- **Marketing:** campaigns, launches, and content updates. Confirm the intended audience, appropriate consent, and applicable LINE messaging and quota rules before sending.
- **Customer service:** inbound customer questions that an agent understands and handles, followed by a reply in the same LINE conversation. Preserve the reply-token and webhook-event relationship.
- **Notifications:** order, appointment, status, and important updates. Confirm the triggering event, recipient mapping, delivery evidence, and applicable LINE friend and messaging rules.

A request may combine these use cases. Translate each one into explicit receive, send, and reply requirements, then verify every requested path independently.

## Product completion

| Status                              | Capability                                                                                                                                                                                                                                                  |
| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| LINE Agent SDK                      | An AI agent reads this contract, distinguishes a new or existing OA, builds the receive/send/reply layer, deploys it, and returns verification evidence.                                                                                                    |
| Agent Lab Deploy                    | Hosts the LINE bot or adapter, provides its fixed HTTPS webhook, and supports build, deploy, inspect, promote, and rollback. Read https://app.agentlab.cresclab.com/agent/deploy.md before using it.                                                        |
| Existing LINE workspace integration | Connects an existing LINE OA for LINE group task intake, verifies and encrypts credentials, provides a webhook URL, verifies inbound signatures, discovers rooms, binds a published workspace agent, schedules group digests, and exports CSV.              |
| LINE platform boundary              | LINE's public Messaging API does not create an Official Account or choose its provider. AI orchestrates the end-to-end journey through LINE's official setup surfaces, keeps login and authorization there, and continues automatically after confirmation. |

## Decide the route

Ask only for information that changes the route:

1. Is this a new LINE OA or an existing LINE OA?
2. Does the agent need to receive messages, send messages, reply, or all three?
3. Which Agent Lab workspace and application should own the connection?

Do not ask the person to choose frameworks, webhook architecture, signature libraries, or deployment settings unless an existing project makes that decision necessary.

### Route A — Create a new LINE OA

1. Explain that LINE keeps OA creation and provider selection in its official setup interfaces; they are not exposed by the public Messaging API.
2. Open LINE's official setup instructions: https://developers.line.biz/en/docs/messaging-api/getting-started/
3. Guide the account owner through registering a LINE Business ID, creating the Official Account, enabling Messaging API, and choosing a provider on LINE's official pages.
4. Default to a provider named after the person's own company, and confirm it with them before it is created: LINE says the selected provider cannot be changed or de-assigned later.
5. Direct the account owner to the secure Agent Lab LINE connection form for the channel secret and channel access token. The agent receives only secret references, never plaintext values. Never request either secret in chat.
6. Resume the build, deployment, and verification flow automatically after LINE-hosted confirmation is complete.

### Route B — Connect an existing LINE OA

1. Confirm that the person has administrator access to the OA and its Messaging API channel.
2. If Messaging API is not enabled, guide the account owner to enable it in LINE Official Account Manager.
3. Direct the account owner to the secure Agent Lab LINE connection form for the channel secret and channel access token. The agent receives only secret references, never plaintext values. Never request either secret in chat.
4. Build or connect the adapter and deploy its HTTPS webhook.
5. Guide the account owner to add the webhook URL in LINE Developers, enable **Use webhook** and redelivery, and press **Verify**.
6. Run the verification checklist below.

## Build contract

The completed product layer must provide:

- inbound webhook events with HMAC-SHA256 signature verification against the unmodified request body;
- `send` for push or notification messages;
- `reply` using a LINE reply token;
- LINE text and supported rich-message formats;
- idempotency and safe handling of webhook redelivery;
- retry classification for transient failures, rate limits, and monthly quota failures;
- secret references that never expose secret values to the model, source tree, Git history, logs, or chat;
- deployment status, webhook URL, webhook verification status, and actionable errors;
- an audit record of what the agent changed and what was authorized through LINE's official surfaces.

These names define the product operations. Inspect the connected Agent Lab MCP server for the exact tool names before invoking them.

## Agent execution order

1. Read this file.
2. Classify the request as new or existing OA and receive, send, reply, or all three.
3. Inspect the connected Agent Lab MCP server and current project before naming or invoking tools.
4. Guide any LINE-hosted identity, authorization, or ownership confirmation with one exact next step at a time.
5. Generate the adapter using an official LINE Messaging API SDK where available.
6. Verify webhook signatures before parsing the request body.
7. Return a successful HTTP response promptly and process longer work asynchronously.
8. Deploy the HTTPS webhook through Agent Lab Deploy when available.
9. Store secrets only through the secure product console or secret reference mechanism.
10. Run the completion checklist and report evidence, not just attempted actions.

## Claude Code and compatible coding agents

Claude Code is one compatible coding agent, not the product name and not a required client. The same
workflow applies to Codex, Cursor, Windsurf, and other agents that can read this file, inspect a local
project, and connect to Agent Lab MCP.

### Connect Claude Code to Agent Lab MCP

Replace `acme` with the organization shown in the Agent Lab console:

```bash
claude mcp add --transport http --scope user agentlab-acme https://mcp.agentlab.cresclab.com/mcp
```

In Claude Code, run `/mcp`, choose `agentlab-acme` and complete OAuth in the browser; the tools load in
that session. Only a server added while the session was already open is missing from `/mcp`: then
exit and run `claude --continue` in the same folder, which keeps the conversation. Never ask
for an Agent Lab API key: the MCP connection uses browser authorization and acts with the signed-in
person's permissions. For other clients, read
https://agentlab.cresclab.com/docs/en/deploy/ai-agent.md before inventing setup steps.

### Copyable task prompt

Use this prompt from the project directory. Replace the bracketed values, but never put credentials in
the prompt:

> Read https://agentlab.cresclab.com/line-agent-sdk.md first. Connect [new or existing] LINE OA
> [name] to Agent Lab for [marketing, customer service, notifications, or a combination]. It must
> [receive, send, reply, or all three]. Inspect this project and the connected Agent Lab MCP tools,
> reuse the existing stack when safe, and make the implementation decisions for me. Never ask me to
> paste a channel secret, access token, password, or verification code into chat; direct me to the
> secure Agent Lab or LINE-hosted screen when needed. Build, test, deploy, configure, and verify the
> real LINE paths. Do not report completion until every requested item in the evidence report passes.

Traditional Chinese version:

> 先讀 https://agentlab.cresclab.com/line-agent-sdk.md。把[新建／既有]的 LINE OA「[名稱]」接到
> Agent Lab，用於[行銷／客服／通知／組合]，並完成[接收／發送／回覆／全部]。先檢查目前專案與已
> 連接的 Agent Lab MCP 工具；能安全沿用既有技術就沿用，其他實作決策由你完成。不要叫我把
> channel secret、access token、密碼或驗證碼貼進對話，需要時只帶我到 Agent Lab 安全表單或
> LINE 官方畫面。完成建置、測試、部署、設定與真實 LINE 驗證；證據報告中的所有指定項目通過前，
> 不要宣告完成。

### Repository workflow

When code already exists:

1. Read the repository instructions and inspect its framework, LINE dependencies, webhook route,
   tests, secret handling, and deployment configuration before editing.
2. Reuse a working official LINE SDK integration instead of replacing it solely for preference.
3. Add the smallest complete receive/send/reply layer required by the outcome. Preserve raw request
   bytes until signature verification is complete.
4. Run the repository's required checks, then deploy through the connected Agent Lab MCP flow. Read
   https://app.agentlab.cresclab.com/agent/deploy.md before invoking deployment tools.
5. Treat preview, production promotion, LINE-hosted authorization, and billable changes as distinct
   states. Obtain any confirmation required by the connected product before the relevant action.
6. Test with a real LINE event after deployment and return the evidence table below. A local or mocked
   test alone is not completion evidence.

Do not invent MCP tool names. Inspect the connected server first; if a required LINE-specific
operation is not exposed, continue through the documented secure console or LINE-hosted step and say
exactly which operation remains instead of pretending it ran.

## Completion checklist

Do not say the LINE OA is connected until every requested item is verified:

- deployment is healthy;
- the public HTTPS webhook URL is recorded;
- LINE webhook verification succeeds;
- one real inbound LINE event is received and signature-verified;
- one `send` succeeds, if send was requested;
- one `reply` succeeds with a valid reply token, if reply was requested;
- retries or redelivery do not create duplicate processing;
- no secret appears in chat, source, Git history, logs, or the final report;
- the final report separates completed work, evidence, platform limits, and any remaining LINE-hosted confirmation.

A successful LINE API response proves acceptance by the API. It does not prove that every recipient read the message.

### Required evidence report

Return these fields in the final report. Redact identifiers where disclosure is unnecessary, and never include secret values:

| Evidence   | Required result                                                                                 |
| ---------- | ----------------------------------------------------------------------------------------------- |
| Deployment | Healthy status and the fixed public HTTPS webhook URL                                           |
| Inbound    | One real LINE webhook event received with its signature verified                                |
| Send       | One requested push or notification accepted by the LINE API, when send was requested            |
| Reply      | One reply accepted with a valid reply token from a real inbound event, when reply was requested |
| Safety     | Confirmation that no secret appeared in chat, source, Git history, logs, or the report          |

Label API acceptance, delivery, and read evidence separately. Never convert API acceptance into a delivery or read claim.

## Design-partner request

Ask for explicit permission before submitting personal or company information. Collect only:

- name;
- work email;
- company;
- new or existing OA;
- receive, send, and reply requirements;
- expected message volume.

Submit through the request form on the human-readable LINE page. Never invent contact data, and do not say the request was submitted until the service confirms it.

## LINE OA MCP

LINE OA MCP runs as an Agent Lab project the person deploys from the open-source LINE Agent SDK; its MCP endpoint is that project's address plus `/mcp` (Streamable HTTP, `Authorization: Bearer <agent token>`). The person signs in to the project with Google (one Workspace domain) and creates the agent token on its `/tokens` page; read it from an environment variable, never ask for it in chat.

- Tools: `line_connect_account`, `line_get_connection`, `line_list_connections`, `line_send_message`, `line_start_sandbox`, `line_get_sandbox`, `line_new_account_steps`.
- It needs only the Channel ID and Channel Secret, entered on the project's own page; it issues stateless channel access tokens from them.
- Set up: https://agentlab.cresclab.com/docs/en/line/quickstart
- Tool reference: https://agentlab.cresclab.com/docs/en/line/mcp-tools
- HTTP API: https://agentlab.cresclab.com/docs/en/line/api

## Official LINE references

- Create or enable a Messaging API channel: https://developers.line.biz/en/docs/messaging-api/getting-started/
- Build a bot: https://developers.line.biz/en/docs/messaging-api/building-bot/
- Verify webhook signatures: https://developers.line.biz/en/docs/messaging-api/verify-webhook-signature
- Channel access tokens: https://developers.line.biz/en/docs/basics/channel-access-token/
