Agentic Architecture
Agentic Loop
stop_reason = "tool_use"
stop_reason = "end_turn"
Task
calls in a single coordinator response.
Multi-Agent Orchestration
Task Decomposition
--resume <name>
continues a named session.
fork_session
branches from a shared baseline. If tool results are stale, start fresh with
injected summary.
Enforcement vs Prompt-Based
Deterministic. Use when compliance is non-negotiable: identity verification, financial thresholds, policy gates. Zero failure rate.
Probabilistic. Non-zero failure rate. OK for guidance and suggestions. Never rely on this for critical business logic.
Tool Descriptions
- Specific purpose (not generic)
- Expected input formats and example queries
- Edge cases and what it does NOT handle
- When to use it vs similar alternatives
- Overlapping descriptions cause misrouting
- System prompt wording creates unintended associations
- One vague tool instead of 2–3 purpose-specific ones
Structured Error Responses
-
errorCategory: transient / validation / permission / business -
isRetryable: boolean - Human-readable description
-
For business violations:
retriable: false+ customer-friendly message
Needs retry logic. Propagate with structured context so coordinator can decide.
Successful query, no matches. Do NOT treat as an error. Distinguish clearly.
Tool Distribution
tool_choice
options:
-
"auto"— model may return text or call a tool -
"any"— model must call some tool (prevents conversational text) -
{"type":"tool","name":"..."}— forces a specific named tool first
MCP Server Configuration
${ENV_VAR}
expansion for auth tokens — never commit secrets.
- Grep : search file contents (function names, imports, error strings)
-
Glob
: find files by name/extension pattern (
**/*.test.tsx) - Edit : targeted modification using unique text match. If fails → Read then Write
CLAUDE.md Hierarchy
~/.claude/CLAUDE.md
instead of project-level. User-level is invisible to teammates.
Custom Commands & Skills
~/.claude/commands/
and are not shared.
context: fork
— isolated sub-agent context.
allowed-tools
restricts tools.
argument-hint
prompts for required params.
On-demand invocation for task-specific workflows (codebase analysis, brainstorming).
Always-loaded universal standards. Rules that must apply to every single session.
Plan Mode vs Direct Execution
CI/CD Integration
-
-p/--print— non-interactive mode (prevents pipeline hangs) -
--output-format json+--json-schema— machine-parseable output for inline PR comments
Prompt Precision
"Flag comments only when claimed behavior contradicts actual code behavior"
"Be conservative" / "Only report high-confidence findings" — no meaningful improvement in precision.
Few-Shot Prompting
- Detailed instructions alone produce inconsistent output
- Ambiguous scenarios where judgment must be demonstrated
- Reducing hallucination in extraction tasks with varied formats
- Showing model what to accept vs flag (false positive reduction)
- 2–4 targeted examples covering ambiguous cases
- Show reasoning: why this choice over plausible alternatives
- Demonstrate desired output format (location, issue, severity, fix)
- Include varied document structures to enable generalization
Structured Output via Tool Use
tool_use
+ JSON schema = most reliable structured output. Eliminates syntax errors, but
NOT semantic errors (line items not summing, values in wrong fields).
- Make fields optional/nullable when source may not contain that data — prevents fabrication
-
Use
"other" + detailfield pattern for extensible enum categories -
Add
"unclear"enum value for genuinely ambiguous cases
Validation, Retry & Batch
Overnight reports, weekly audits, nightly test generation. 50% cost savings, up to 24h window.
Blocking pre-merge checks. Any workflow requiring fast response. Multi-turn tool calling (not supported).
Context Window Management
Escalation Decision-Making
- Customer explicitly requests a human — honor immediately , no investigation first
- Policy is ambiguous or silent on the specific request
- Unable to make meaningful progress on the case
- Sentiment analysis / frustration detection — doesn't correlate with case complexity
- Self-reported LLM confidence scores — poorly calibrated on hard cases
- "Case complexity" heuristics without explicit criteria
Error Propagation
- Failure type and what was attempted (query, parameters)
- Any partial results obtained
- Potential alternative approaches
Returning empty results as "success" prevents recovery and risks incomplete outputs.
Terminating entire workflow on one subagent failure. Handle locally; propagate with context when not.