跳到正文
DEV Community· Jimmy fa·· 1 天前AI 評分56

Claude Agent 循環與 MCP 工具的可靠架構設計:CCAR-F 備考筆記

Architecting Reliable Claude Agent Loops & MCP Tools (CCAR-F Study Notes)

AI 導讀

這份 CCAR-F 備考筆記指出,Claude 生產工作流的失效多出現在架構邊界,並整理 Agent 循環、MCP 伺服器、提示詞快取及 CI 自動化的工程做法。

正文

Jimmy fa

When designing production workflows with Claude—especially multi-step agent loops, Claude Code automation, and Model Context Protocol (MCP) servers—most failures happen at architectural boundaries rather than prompt wording.

While reviewing the Claude Certified Architect — Foundations (CCAR-F) domain blueprint, several patterns stood out as useful engineering checklists for anyone shipping agentic systems.

1. Orchestrator-Worker vs. Subagent Context Isolation

A common mistake in multi-agent systems is passing the entire parent conversation history into every worker subagent.

  • Why it fails: Irrelevant tool outputs and intermediate reasoning dilute attention and inflate token costs.
  • Better pattern: Keep a central orchestrator that delegates scoped tasks with explicit input contracts and max_turns / token-budget stop conditions. Subagents should return concise structured summaries rather than raw logs.

2. MCP Primitives: Tools vs. Resources vs. Prompts

When building an MCP server, separating primitives cleanly prevents unnecessary model round-trips:

  • Tools (Model-controlled): Actions with side effects or dynamic queries (run_sql, create_issue). Always design idempotent behavior and return structured isError: true payloads with actionable recovery hints.
  • Resources (Application-controlled): Read-only context (schemas, config files, docs) that the client can attach deterministically without burning a tool-call turn.
  • Prompts (User-controlled): Reusable slash-command templates for repeatable team workflows.

3. Prompt Caching Prefix Hygiene

Prompt caching only works when the prefix is byte-identical across requests:

  1. Place static system instructions, tool schemas, and large reference documents at the very top.
  2. Push dynamic metadata (timestamps, request IDs, user-specific state) to the end of the prompt or into the latest user turn.

4. CLAUDE.md & Headless CI Guardrails

For repository automation (claude -p), keep root CLAUDE.md files concise and scoped. Use --allowedTools to restrict write/network capabilities in CI, and enforce deterministic validation (linters, schema checks) via pre/post-tool hooks rather than relying solely on natural-language instructions.


Self-Assessment & Further Reading

If you are preparing for the CCAR-F exam or want to benchmark your understanding across all 5 domains (Agentic Architecture, Claude Code Workflows, Structured Output, MCP Tool Design, and Context Reliability), I found AI Cert Mock useful as a quick, no-login 10-question diagnostic alongside the official Anthropic blueprint.

來源:DEV Community · dev.to