用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/tomevault-io/skills-registry --skill ai-agent-design命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
| name | ai-agent-design |
| description | > Use when this capability is needed. |
How to design AI agents that actually work. This skill covers the craft of agent design independent of any specific framework — the principles apply to Mastra and any other agent system.
Note on code examples: The design principles in this skill are stable and framework-agnostic, but any Mastra-specific code examples (model names, constructor params,
maxStepsvalues) are illustrative. Before using them, verify current API signatures via themastraskill's documentation lookup — check embedded docs first (node_modules/@mastra/*/dist/docs/), then fall back to remote docs (https://mastra.ai/llms.txt). Never rely on training data for Mastra API details.
Agent instructions (system prompts) are the single most important factor in agent quality. They define the agent's identity, boundaries, and decision-making process.
Structure instructions from most to least important:
Be specific, not vague:
BAD: "You are a helpful assistant."
GOOD: "You are a customer support agent for an e-commerce platform.
You help users with order tracking, returns, and product questions.
You do NOT handle billing disputes — escalate those to the billing team."
Name your tools and explain when to use them:
BAD: "Use the available tools to help the user."
GOOD: "You have access to these tools:
- orderLookupTool: Use when the user asks about an order status or needs order details. Requires an order ID or customer email.
- returnTool: Use to initiate a return. Only use after confirming the order exists via orderLookupTool.
- faqSearchTool: Use for general product questions before crafting your own answer."
Define behavior at boundaries:
"If the user asks about something outside your scope (pricing changes, account deletion, legal matters):
1. Acknowledge their request
2. Explain you can't help with that specific topic
3. Suggest who can help (billing team, account management, legal@company.com)"
Include examples for ambiguous situations:
"When a user complains about a late delivery:
1. Look up the order first
2. Check the current shipping status
3. If the package is in transit, provide the tracking info and expected date
4. If the package is lost (no updates for 5+ days), offer a replacement or refund
5. Always apologize for the inconvenience regardless of the cause"
Use dynamic instructions (async functions) when:
Do NOT use dynamic instructions when:
Tools are the hands and eyes of an agent. Poorly designed tools cause agents to fail even with perfect instructions.
One tool, one job. A tool should do exactly one thing. If you're tempted to add a "mode" parameter, make two tools instead.
Descriptions are for the LLM. Write the description as if explaining to a smart colleague what this tool does and when to use it. Be specific about inputs and expected outcomes.
Schema fields are self-documenting. Use descriptive names and .describe() on every field:
// BAD
z.object({ q: z.string(), n: z.number() })
// GOOD
z.object({
query: z.string().describe("The search query to execute"),
maxResults: z.number().default(10).describe("Maximum number of results to return (1-100)"),
})
Constrain inputs. Use enums, min/max, regex patterns to prevent invalid inputs:
z.object({
priority: z.enum(["low", "medium", "high"]).describe("Ticket priority level"),
daysBack: z.number().min(1).max(90).describe("Number of days to search back"),
})
Return structured errors. Never let tools throw unhandled exceptions — return error information the agent can reason about:
Too granular: Too coarse:
getUser, getUserEmail, doEverything(action, params)
getUserName, getUserOrders...
Sweet spot:
getUser(userId) → { name, email, role }
getUserOrders(userId, { limit, status }) → Order[]
createOrder(userId, items) → Order
Not everything needs to be a tool. The LLM can:
Use tools for things the LLM can't do: fetch live data, execute code, interact with external systems, perform precise calculations.
| Task characteristics | Recommended tier | Examples |
|---|---|---|
| Simple routing, classification, extraction | Small/fast (gpt-4o-mini, haiku) | Ticket classification, entity extraction |
| General reasoning, tool use, conversation | Mid-tier (gpt-4o, sonnet) | Customer support, research, analysis |
| Complex reasoning, nuanced judgment, coding | Large (o1/o3, opus) | Architecture design, code review, legal analysis |
Tiered model selection: Use cheap models for easy tasks, expensive ones for hard tasks. In agent networks, the routing agent can use a cheaper model while specialist agents use more capable ones.
Minimize context: Don't send the agent's entire conversation history when it only needs the last message. Use lastMessages judiciously.
Limit maxSteps: Set reasonable limits to prevent runaway tool loops. Start with 3-5 and increase only if agents consistently need more.
Cache tool results: If a tool fetches slowly-changing data, cache it rather than re-fetching every turn.
Structured output over parsing: Using schema-based structured output is cheaper and more reliable than asking the model to format JSON in its response.
| Metric | What it tells you | How to measure |
|---|---|---|
| Task completion | Does the agent achieve the goal? | Manual review, automated checks |
| Tool accuracy | Does it call the right tools with right inputs? | Log tool calls, compare to expected |
| Hallucination rate | Does it make things up? | Compare claims against ground truth |
| Latency | How long does a response take? | End-to-end timing |
| Token usage | How much does each interaction cost? | Sum input + output tokens per turn |
| User satisfaction | Do users find it helpful? | Thumbs up/down, follow-up questions |
Input guardrails (before the agent processes):
Output guardrails (before the response reaches the user):
Execution guardrails (during agent processing):
maxSteps to prevent infinite loops / Manual testing \ ← Exploratory, edge cases
/ Integration tests \ ← Full agent + tools + memory
/ Agent eval suites \ ← Automated scoring on test cases
/ Tool unit tests \ ← Inputs → outputs for each tool
/ Schema validation tests \ ← Schema edge cases, types
references/tool-design-patterns.mdreferences/instruction-templates.mdSource: balazsbarta/mastra-claude-plugin — distributed by TomeVault.
execute: async (input) => {
try {
const data = await fetchData(input);
return { success: true, data, error: null };
} catch (e) {
return { success: false, data: null, error: `Failed to fetch: ${e.message}` };
}
}
Minimize output size. Don't return entire database rows when the agent only needs two fields. Large outputs waste tokens and confuse the model.
基于 SOC 职业分类