483 từ
2 phút đọc
MCP Tools as Prompts: Định nghĩa Tool Điều Khiển Hành Vi Agent

Tools của bạn là prompts.

Mọi MCP server bạn kết nối, mọi function bạn register, mọi tool description bạn viết — tất cả đều nằm trong context window của agent cùng với system prompt và steering file. Agent đọc chúng, suy luận về chúng và quyết định gọi tool nào.

Hầu hết teams dành hàng giờ để viết system prompt nhưng viết tool definitions như việc phụ. Bài này cho thấy tại sao họ sai.


Prompt Ẩn: Tool Definitions#

Khi bạn kết nối MCP server, bước đầu tiên của agent là gọi tools/list. Mỗi tool trả về:

  • Tool namesearch_docs vs search_internal_documentation_v2
  • Description — “Searches docs” vs “Searches knowledge base. Gọi cái này trước khi viết code.”
  • Input schema — Parameters, types, defaults
  • Output format — Structured content blocks hay plain text

Metadata này được inject vào system context của agent. Agent coi nó như instructions về những gì nó có thể làm.


MCP Tool Prompt Spectrum#

Mọi phần của tool definition đều là instruction cho agent:

Tool ElementPrompt FunctionExample
NameIdentifies capabilitysend_email vs send_urgent_email_alert
DescriptionCho agent biết khi nào dùng”For production incidents only”
Input schemaĐịnh nghĩa arguments agent phải gatherRequired fields buộc agent collect data trước khi gọi
Error messagesHướng dẫn recovery”Retry với backoff” vs “Contact support”

Patterns#

Pattern 1: Viết Descriptions như Instructions#

# Dở: chỉ mô tả
"description": "Lấy user data từ database"
# Tốt: mô tả VÀ hướng dẫn
"description": """Lấy user data từ database.
Luôn gọi cái này khi cần user info thay vì đoán.
Returns: user_id, email, role, created_at.
Không bao giờ log email field — nó chứa PII.
Nếu user không tìm thấy, check archive database thay vì báo error."""

Pattern 2: Dùng Tool Names để Routing#

# Trước: generic name, agent confused
"name": "query_production", "description": "Query production DB"
"name": "query_staging", "description": "Query staging DB"
# Agent route chính xác dựa trên context

Pattern 3: Input Schema như Guardrails#

"inputSchema": {
"amount": {
"type": "number",
"description": "Refund amount in cents. Max 50000 ($500). Refunds over $100 cần manager approval."
}
}

Input schema hoạt động như guardrail. Agent đọc description và điều chỉnh behavior — nó sẽ không attempt refund $500+ mà không check.


Case Study#

Before (minimal tool definitions):#

Agent behavior: Không predictable. Thỉnh thoảng search, thỉnh thoảng guess. Hay gọi sai tool.

After (prompt-aware tool definitions):#

Agent behavior: Consistent. Search trước, đọc relevant code, rồi write với testing.


Khi Tool Prompting Không Đủ#

Tool prompts hoạt động cho linear, sequential behavior. Fail khi:

  • Cần conditional branching — “Nếu A làm X, nếu B làm Y”
  • Cần parallel execution — Cần framework như LangGraph
  • Có 50+ tools — Context window đầy
  • Cần precise timing — “Đợi 5 phút rồi gọi”

Dùng layered approach cho những case này.


Production Checklist#

  • Mọi tool description bao gồm “khi nào gọi cái này”
  • Critical tools có post-call instructions
  • Error-prone tools có recovery instructions
  • Tool names phản ánh role của chúng
  • Input schema descriptions quan trọng như tool descriptions

Tiếp Theo#

BàiChủ đề
1System Prompts vs Steering Files vs Agent Instructions
2MCP Tools as Prompts (bài này)
3Structured Prompting
4Prompt Testing & Evaluation
5Production Patterns & Anti-Patterns

Series: Prompt Engineering 2026 — Production Patterns. Bài 2: MCP Tools as Prompts.

Advertisement

MCP Tools as Prompts: Định nghĩa Tool Điều Khiển Hành Vi Agent
https://minixium.com/vi/posts/mcp-tools-as-prompts-shape-agent-behavior-vi/
Tác giả
Minixium
Đăng vào lúc
2026-05-28
Giấy phép bản quyền
CC BY-NC-SA 4.0

Advertisement