name: wechat-miniprogram-ai-mode description: Use this skill when building, reviewing, or debugging WeChat Mini Program AI Development Mode (beta) integrations based on the official 微信开放文档. Covers AGENTS.md global instruction, app.json agent.skills registration, SKILL.md/mcp.json/index.js structure, wx.modelContext APIs, atomic APIs/components, runtime limits, debugging with WeChat DevTools Nightly, and best practices for writing Mini Program AI SKILLs. alwaysApply: false
When to use this skill
Use this skill when the user is working on 微信小程序 AI 开发模式(beta) rather than ordinary Mini Program pages or wx.cloud.extend.AI.
Typical triggers:
- "接入微信小程序 AI 开发模式"
- "写 SKILL.md / mcp.json"
- "wx.modelContext 是什么"
- "原子接口 / 原子组件怎么写"
- "小程序 AI 调试不了怎么办"
Do not use this skill for:
- Plain Mini Program page/component development with no AI mode
wx.cloud.extend.AItext generation in Mini Program- Node.js or Web CloudBase AI SDK work
If the task is about general Mini Program engineering, pair this skill with miniprogram-development.
Core distinction
This official doc describes Mini Program AI Development Mode, where the developer packages business capabilities into a Mini Program AI SKILL:
AGENTS.md: global instruction for the whole Mini ProgramSKILL.md: detailed business rules for one skillmcp.json: callable atomic API declarationsindex.js: atomic API registration entryapis/: atomic API implementationscomponents/: atomic component implementations
This is not the same as calling an LLM through wx.cloud.extend.AI.
First-pass workflow
When asked to help on this topic, follow this order:
- Confirm the project is targeting 小程序 AI 开发模式(beta).
- Check whether the app has applied for AI Development Mode in 微信公众平台 or 微信开发者助手.
- Inspect
app.jsonforlazyCodeLoading, independent subpackages, andagent.skills. - Inspect
AGENTS.md, eachSKILL.md,mcp.json,index.js,apis/, andcomponents/. - Validate that every declared API in
mcp.jsonis registered inindex.jsand implemented inapis/. - Validate that any UI-bound API uses
_meta.ui.componentPathand that the component path exists. - Check runtime restrictions before suggesting APIs or component behaviors.
- When debugging, target 微信开发者工具 Nightly and the AI compile mode first.
Required app-level setup
app.json should include:
lazyCodeLoading: "requiredComponents"subPackageswith an independent package for AI skillsagent.skillsdeclarations- Optional
agent.instructionpointing toAGENTS.md - Optional
agent.pageMetadatafor text-link fallback
Example shape:
{
"lazyCodeLoading": "requiredComponents",
"subPackages": [
{
"root": "skills",
"pages": [],
"independent": true
}
],
"agent": {
"instruction": "AGENTS.md",
"skills": [
{
"name": "drink",
"description": "点单场景",
"path": "skills/drink-skill"
}
]
}
}
Current documented limits:
agent.instructionfile size: max10000bytes- One Mini Program can declare at most
30skills
Required skill package structure
Each Mini Program AI skill should live inside one independent subpackage and include:
path/to/skill/
|- SKILL.md
|- mcp.json
|- index.js
|- apis/
|- components/
Constraints from the official docs:
SKILL.mdis a single file only; do not assume the runtime supports importing other markdown filesSKILL.mdmax size:16000bytesmcp.jsonmax size:24000bytesmcp.jsonsize calculation ignoresoutputSchemaplus whitespace/newlines
What goes where
Use the documented attention hierarchy:
- Atomic API return
content: strongest for immediate next-step guidance mcp.jsondescription: strongest for API selection boundariesmcp.jsoninputSchema.properties.*.description: strongest for argument generationSKILL.md: best for orchestration, routing, cross-API rules
Write content accordingly:
- Put API purpose, trigger conditions, and forbidden cases in
mcp.json.description - Put parameter meaning and hard constraints in
inputSchema - Put workflow, sequencing, intent routing, and shared rules in
SKILL.md - Put actual result plus next-step hint in returned
content
Do not bloat SKILL.md with per-API detail that belongs in mcp.json.
mcp.json authoring rules
Each atomic API entry should include:
name: must match the registered API name inindex.jsdescription: clear business object, trigger condition, and forbidden scenariosinputSchema: JSON Schema objectoutputSchema: recommended- Optional
_meta.ui.componentPathfor component rendering
Strong guidance:
- Use semantic API names such as
searchFlights, not vague names likesearch - First sentence should name the business object, not the parameter list
- Avoid implementation details in descriptions
- Keep API responsibilities non-overlapping
- Put prohibitions early, not buried in the middle
- Use JSON Schema enums/min/max/required aggressively to constrain model arguments
index.js registration rules
Register APIs through wx.modelContext.createSkill(skillPath):
const getWeather = require('./apis/getWeather')
const skill = wx.modelContext.createSkill('skills/weather-skill')
skill.registerAPI('getWeather', getWeather)
Important:
skillPathmust match the declared skill path- Registered API names must match
mcp.json - Use
skill.use(...)middleware for shared login, logging, error handling, or auth reuse
Middleware context includes:
nameskillPatharguments
Atomic API implementation expectations
Atomic APIs are the smallest executable business unit. Treat them as:
- Single-purpose
- Strongly validated
- Structured in input and output
- Safe against hallucinated IDs or parameters
Recommend these patterns:
- Validate all externally supplied IDs against upstream results or storage
- Reuse login/session checks via middleware
- Return structured data for components through
structuredContent - Return explicit next-step hints in
content - Enforce business invariants in code, not just in prompt text
Atomic component rules
Atomic components render GUI cards in the conversation flow.
Supported built-in components currently include:
viewtextwithoutuser-selectmapwith limited interactionbuttonwithoutopen-typeimageusing networkpng/jpgcanvaswith2donlyscroll-viewwith horizontal scroll only
Key constraints:
- Width is fixed by screen width
- Height range is constrained from
4:1to1:1 - Height is determined at initialization and cannot change later
- Only limited events are supported; mainly tap plus image load/error
- No vertical scrolling
- No animation
- Components cannot open the Mini Program directly
Use components[].relatedPage in mcp.json and setRelatedPage({ path, query }) when the card needs a corresponding Mini Program page.
Real-time dynamic components
Default atomic components do not support:
wx.request- Cloud APIs
- timers such as
setTimeout/setInterval
If the scene genuinely requires live updates, declare the component as dynamic in mcp.json and note that this capability needs separate review. Use it sparingly.
Runtime model and context isolation
The execution environment is separate from the normal Mini Program runtime.
Critical implications:
- Atomic APIs, atomic components, and dynamic components run in different JavaScript contexts
- Global variables are not shared across those contexts
- Data must be passed through API return fields such as
content,structuredContent, and_meta - Half-screen pages are closer to normal Mini Program pages, but some capabilities remain restricted
Never suggest using shared global state between atomic APIs and components.
New wx.modelContext APIs
Atomic API side:
wx.modelContext.createSkill(skillPath)skill.registerAPI(name, handler)skill.use(middleware)wx.modelContext.getSessionId()wx.modelContext.expireAllCards({ componentPaths, match })
Atomic component side:
wx.modelContext.getViewContext(this).setRelatedPage({ path, query })wx.modelContext.getContext().sendFollowUpMessage()wx.modelContext.getViewContext(this).openDetailPage({ url })wx.modelContext.getViewContext(this).preloadDetailPage({ url })wx.modelContext.getViewContext(this).expirePreviousCards({ componentPaths, match })wx.modelContext.getViewContext(this).on(NotificationType, callback)
Useful notifications:
InputResultOverflowExpire
Existing API support guidance
Do not assume normal Mini Program APIs all work everywhere.
High-value rules from the docs:
- Atomic APIs support many business APIs, including
wx.login,wx.request,wx.cloud.*, storage APIs, payment APIs, and more - Atomic components support a much narrower set
- Storage APIs are supported in both contexts and are the documented way to reuse login credentials
- Some APIs become available in components only when declared dynamic
When unsure, verify against the official API support table before proposing an implementation.
Login and identity
The user identity is shared with the original Mini Program.
Preferred options:
- Reuse login credentials through storage APIs
- Complete login flows through supported APIs such as
wx.loginandwx.getPhoneNumber - Centralize repeated auth logic in middleware
Debugging requirements
Use the official debugging path first:
- 微信开发者工具 Nightly Electron Build 最新版本
- Compile mode: 小程序 AI 编译
- Base library:
3.16.1
If the entry is missing:
- Re-login or reopen the project window
- Switch base library away from
3.16.1and back to force resource download
Current preview support from the docs:
- Real-device preview requires WeChat
8.0.74+ - Currently iOS only
- Base library on device should be
3.16.1+ - Remote "真机调试" is not supported for this mode
Best-practice rules to enforce
- Let AI handle fuzzy intent, but keep execution through explicit atomic APIs
- Do not skip required intermediate APIs just because the model can guess the next step
- Keep card data inside cards; avoid re-expanding card details as markdown lists in plain text
- Never invent IDs, enum values, or order numbers
- If a constraint is hard, enforce it in code and
inputSchema, not only inSKILL.md - Realtime service progress should update cards rather than relying on static cards
- Use text-links only as fallback; core flows should stay inside AI mode
Common pitfalls
- Confusing this mode with
wx.cloud.extend.AI - Forgetting
lazyCodeLoading: "requiredComponents" - Declaring a skill outside an independent subpackage
mcp.jsonAPI names not matchingindex.js- Omitting related page config for components
- Passing data through globals across contexts
- Using unsupported component APIs or vertical scrolling
- Assuming streaming text replies are supported; the FAQ says they are not
- Assuming arbitrary text/card interleaving is supported; current format is limited
- Missing
wx.modelContextbecauseuni-appreplaced globalwx
If wx.modelContext is undefined in a uni-app based project, inspect @dcloudio/uni-mp-weixin/dist/wx.js and ensure modelContext is preserved.
Review checklist
When reviewing a Mini Program AI skill, check:
app.jsonhas the rightagentand subpackage setupAGENTS.mdscopes the product and routes skills clearlySKILL.mdfocuses on orchestration instead of duplicatingmcp.jsonmcp.jsondescriptions andinputSchemaare concrete and restrictive- All IDs and enums come from real upstream data
- Every declared component path exists
- Related pages and half-screen flows are wired correctly
- Cross-context data passing is explicit
- DevTools/preview prerequisites are documented for the team
Official references
Prefer official WeChat sources:
- Guide:
https://developers.weixin.qq.com/miniprogram/dev/ai/guide.html - Integration:
https://developers.weixin.qq.com/miniprogram/dev/ai/integration.html - Runtime:
https://developers.weixin.qq.com/miniprogram/dev/ai/operating-mechanism.html - Debugging:
https://developers.weixin.qq.com/miniprogram/dev/ai/debugging.html - Best practices:
https://developers.weixin.qq.com/miniprogram/dev/ai/best-practices.html - API support:
https://developers.weixin.qq.com/miniprogram/dev/ai/reference/api.html - FAQ:
https://developers.weixin.qq.com/miniprogram/dev/ai/faq.html - Official demo:
https://github.com/wechat-miniprogram/ai-mode-demo