本文へ移動
cccskills
無料GitHub で公開

agentforce-cost-optimization

Use when Agentforce run costs are climbing, you need to forecast scale, or you want to reduce tokens per conversation without hurting quality. Covers topic (now subagent) design impact on cost, prompt/template reuse, grounding size discipline, caching, and model-tier selection. Triggers: 'agentforce cost', 'tokens per conversation too high', 'reduce agentforce runs spend', 'forecast agentforce scale cost', 'einstein trust layer tokens'. NOT for capping spend per user with a budget gate and fallback — use agentforce/agent-rate-limit-strategy. NOT for org-wide model-tier and BYOLLM platform strategy — use architect/ai-platform-architecture.

インストール方法を見る

含まれるファイル(7)

  • SKILL.md8.3 KB
  • references/examples.md1.3 KB
  • references/gotchas.md768 B
  • references/llm-anti-patterns.md1.6 KB
  • references/well-architected.md1.2 KB
  • scripts/check_agentforce_cost_optimization.py2.6 KB
  • templates/cost-model.md849 B

SKILL.md(原文)

インストールする前に、エージェントに与えられる指示の中身を確認できます。

Agentforce Cost Optimization

Agentforce cost looks like "we'll just pay per run" right up until volume meets reality. A customer-service agent handling 200,000 conversations/month can consume 10× the tokens of a well-tuned version of the same agent — same quality, same subagents, different token discipline. The cost drivers are predictable: subagent instruction length, prompt template verbosity, grounding payload size, tool-call round-trips, and model tier. None of these are free to change, but they all respond to focused work.

The job is to measure first, then optimize the top three contributors. Most orgs find that subagent instructions and grounding dominate — often 60-80% of tokens per conversation. Once those are disciplined, the remaining optimizations (template reuse, model-tier selection) become viable.

Terminology. This skill leads with subagent because that is the current product term — Salesforce renamed agent topics to subagents in April 2026, with no change to functionality. It deliberately keeps topic in metadata and API names and in search keywords, because those did not change, and readers arriving with the older vocabulary still need to find this skill.


Before Starting

  • Pull 7 days of Agentforce runs; compute average and p95 token counts per conversation.
  • Inventory subagents, prompt templates, and grounding sources.
  • Confirm model tier currently in use and any rate-limit headroom.
  • Confirm business tolerance for quality-vs-cost tradeoffs.

Core Concepts

What Tokens Are You Paying For?

Every conversation pays for:

  1. System prompt — the framework-level Agentforce prompt.
  2. Subagent instructions — active subagent's instructions injected verbatim.
  3. Prompt template — any custom template rendered per turn.
  4. Grounding — retrieved content from Data Cloud, Knowledge, or explicit variables.
  5. Conversation history — full turn history on each call.
  6. Tool output — action results returned into context.

The 80/20 Rule

For most agents, subagent instructions + grounding = 60-80% of token spend. Conversation history grows linearly in long sessions. Tool output is lumpy but occasionally large (SOQL result sets dumped raw into context).

Reducing Subagent Instruction Tokens

  • Delete department-name preamble ("As a customer service agent working for Acme Insurance...").
  • Collapse redundant examples; 2 good examples outperform 10 mediocre ones.
  • Externalize static policy ("always use formal English") into the system prompt instead of per-subagent.

Reducing Grounding Tokens

  • Retrieve k=3, not k=10, unless evaluation shows quality improves.
  • Chunk sizes: 300-500 tokens usually beats 1000-2000.
  • Reranker before final injection when using Data Cloud retrievers.
  • Strip boilerplate (legal footers, headers) from Knowledge articles before indexing.

Conversation History Discipline

Long sessions inflate every turn's token count. Patterns:

  • Summarize older turns ("Summary of first 5 turns: …") rather than sending verbatim.
  • Archive turns beyond a threshold; keep only the last N in active context.

Model Tier Selection

Not every action needs the most capable model. Use tiered routing:

  • Classification / intent detection → smaller model.
  • Reasoning / final response → larger model.
  • Tool-calling / structured output → mid-tier is often enough.

Caching Opportunities

  • Subagent instructions are stable across conversations — framework should cache; you don't need to change anything unless your template is dynamic.
  • Grounding retrieval can cache per query; watch freshness needs.

Common Patterns

Pattern 1: Subagent Instruction Audit And Trim

Per subagent, measure instruction token count. Target 150-300 tokens per subagent instruction. Trim anything above 500 without a compelling reason.

Pattern 2: k-3 Retriever With Reranker

Retrieve 10 candidates; rerank; inject top 3. Cuts grounding tokens 70% vs retrieve-10-inject-10.

Pattern 3: Conversation Summarization Trigger

After N turns or M tokens of history, replace older turns with a one-line summary.

Pattern 4: Tiered Model Routing

Route classification / intent steps to a smaller model; reasoning/response to the capable model.

Pattern 5: Tool Output Projection

When a tool returns a large payload (e.g. SOQL result), project the fields the agent actually needs instead of dumping the full response.


Decision Guidance

SituationRecommended ApproachReason
Token usage high, unknown contributorInstrument and measure firstAvoid guessing
Subagent instructions > 500 tokensTrim (Pattern 1)Biggest win
Grounding k ≥ 5 without evaluationReduce k + rerank (Pattern 2)Second biggest win
Long conversationsSummarize (Pattern 3)Linear savings per turn
Classification step using largest modelSwitch to smaller tier (Pattern 4)Cheap wins
Tool returns wide recordsProject fields (Pattern 5)Eliminates silent waste

Review Checklist

  • Per-conversation token metrics collected and dashboarded.
  • Top 3 token contributors identified per agent.
  • Subagent instruction length audited.
  • Grounding k and chunk size justified.
  • Long-conversation strategy exists.
  • Model tier routing considered.
  • Tool output projection in place.

Recommended Workflow

  1. Measure — 7 days of run data broken down by token source.
  2. Identify top 3 contributors.
  3. Optimize subagent instructions first.
  4. Optimize grounding second.
  5. Add conversation summarization if sessions are long.
  6. Apply tier routing where quality allows.
  7. Re-measure; document cost savings.

Salesforce-Specific Gotchas

  1. Trust Layer adds tokens — masking, citation, guardrails all add context weight.
  2. Grounding sources can include large boilerplate (Knowledge article footers); index selectively.
  3. Tool output is counted even if the agent ignores it.
  4. Managed subagents may have opaque instruction length; audit via runtime logs.
  5. Switching model tier changes quality — do not do this without A/B evaluation.

Proactive Triggers

  • Subagent instruction > 500 tokens → Flag High.
  • Retriever k ≥ 10 without reranker → Flag High.
  • Average conversation > 20 turns with no summarization → Flag Medium.
  • Classification step on flagship model → Flag Medium.
  • Token growth > 15%/month without volume growth → Flag High.

Output Artifacts

ArtifactDescription
Cost modelTokens per conversation by contributor
Optimization planPrioritized trim list with expected savings
Tier routing designStep → model mapping

Related Skills

  • agentforce/agent-topic-design — subagent structure quality.
  • agentforce/prompt-builder-templates — prompt template hygiene.
  • agentforce/data-cloud-grounding-for-agentforce — grounding retrieval.
  • agentforce/agentforce-observability — measurement infrastructure.

レビュー

まだレビューはありません。使ってみた感想をお寄せください。

同じリポジトリのスキル

概要と使いどころ

Use this skill when writing test-first, behavior-driven acceptance criteria in Given/When/Then format for a Salesforce user story. Covers happy path, edge cases, negative paths, permission boundaries, and data-state preconditions so the AC block can drive UAT scripts and Apex test design downstream. Trigger keywords: given when then, gherkin, behavior driven AC, test first acceptance criteria, scenario outline, BDD acceptance criteria. NOT for the user-story format itself (use admin/user-story-writing-for-salesforce). NOT for UAT script writing (use admin/uat-test-case-design). NOT for Apex test method generation (use agents/test-class-generator). NOT for high-level UAT planning (use admin/uat-and-acceptance-criteria). More triggers: acceptance criteria record, ac_id, req_id on a criterion, artefact under test, negative case for a rule-type requirement, no-match fall-through criterion, oracle for a Then clause, test type apex flow manual, criteria linter, check_ac_format.py, --manifest-dir.

日本語の概要は準備中です。原文の説明を表示しています。

PranavNagrecha/AwesomeSalesforceSkills192026年10月4日 更新

Task and Event objects: polymorphic WhatId/WhoId, Activity object model, ActivityHistory vs OpenActivity, activity timeline customization, bulk task creation, Einstein Activity Capture boundaries. NOT for turning on EAC or calendar sync — use admin/einstein-activity-capture-setup. NOT for Email-to-Case — use admin/case-management-setup. Covers ActivitiesSettings metadata, enableActivities, shared Task/Event custom fields and FLS, TaskStatus value sets, Shared Activities and TaskRelation/EventRelation, recurring and child activities, and partial-success bulk DML on Task.

日本語の概要は準備中です。原文の説明を表示しています。

PranavNagrecha/AwesomeSalesforceSkills192026年10月4日 更新

Design Invocable Apex actions that return deterministic, agent-friendly errors instead of surfacing raw exceptions to the LLM. NOT for authoring the action itself — @InvocableMethod schema, labels, security context — use agentforce/custom-agent-actions-apex. NOT for the Apex tests that force each error branch — use agentforce/agent-action-unit-tests.

日本語の概要は準備中です。原文の説明を表示しています。

PranavNagrecha/AwesomeSalesforceSkills192026年10月4日 更新

Use when designing how an Agentforce agent extracts structured input parameters (slots) from a user's natural-language utterance to invoke an action. Triggers: 'agent extract date from user', 'agent action argument extraction', 'agentforce slot filling', 'agent invocable input mapping', 'agent fails to fill required parameter'. NOT for action authoring (use agentforce/agent-actions) or for prompt-template variable binding (use agentforce/prompt-builder-templates).

日本語の概要は準備中です。原文の説明を表示しています。

PranavNagrecha/AwesomeSalesforceSkills192026年10月4日 更新

Apex test patterns for @InvocableMethod agent actions: per-reason-code branch coverage, bulk safety, callout mocking, deterministic assertions. NOT for testing whether the agent routes to the right topic or answers well — use agentforce/agent-testing-and-evaluation. NOT for designing the error envelope the tests assert on — use agentforce/agent-action-error-handling.

日本語の概要は準備中です。原文の説明を表示しています。

PranavNagrecha/AwesomeSalesforceSkills192026年10月4日 更新

Designing or reviewing Agentforce actions: Flow actions, Apex invocable actions, prompt-template actions, action naming, input and output contracts, confirmation requirements, and safe error behavior. Triggers: 'agent actions', 'build an agent that can look up an order', 'make the agent able to check order status', 'give the agent a capability', 'agent that can retrieve a record', 'flow action for agent', 'agent invocable action', 'action schema design'. NOT for writing the Apex class itself — use agentforce/custom-agent-actions-apex. NOT for the reason_code error envelope that stops an agent retry loop — use agentforce/agent-action-error-handling.

日本語の概要は準備中です。原文の説明を表示しています。

PranavNagrecha/AwesomeSalesforceSkills192026年10月4日 更新

PranavNagrecha のスキルをすべて見る

このスキルの問題を報告する