TuBrief
구독 채널
비디오
커뮤니티

How to Split Huge Prompts and Reduce Agent Token Waste

TuBrief 편집팀
2026년 3월 14일
0
Computing/Software

원본 영상을 바탕으로 AI의 도움을 받아 작성했습니다. 원본 영상이 기준입니다.

English한국어Español中文العربيةहिन्दीDeutschFrançaisPortuguêsРусскийBahasa Indonesia日本語

관련 영상

▲ Community Session: How to create and publish skills1:03:28

▲ Community Session: How to create and publish skills

Vercel

커뮤니티의 다른 글

사내 시스템에 llm api 붙일 때 마주하는 현실적인 한계와 대응법

2026년 9월 13일

레거시 백엔드에 GPT-6 Astra 붙일 때 예산 승인과 보안 통과를 먼저 끝내는 법이 있습니다

2026년 9월 13일

에이전트끼리 대화하다 6천만 원 청구서가 나오는 이유

2026년 9월 13일

사내 RAG 벡터 검색에 Okta 권한 필터를 직접 거는 방법

2026년 9월 13일

브라우저 에이전트에게 내 구글 계정을 통째로 넘기면 안 되는 이유

2026년 9월 12일

Apple Won the AI Race

2026년 9월 12일

댓글 (0)

Log in to leave a comment

아직 작성된 글이 없습니다

© 2026 . All rights reserved.

TuBrief
구독 채널
비디오
커뮤니티
로그인

How to Split Huge Prompts and Reduce Agent Token Waste

Monolithic structures that cram all sorts of guidelines and tools into a single system prompt quickly show their limits. Even with a slightly longer conversation, the agent forgets instructions written in the middle of the prompt. Inference costs skyrocket due to repeatedly sending tens of thousands of tokens with every request, and users have to wait a long time for the first token to appear.

In practice, this problem is solved through a step-by-step context loading structure based on the agentskills.io open specification. This approach saves tokens by loading appropriate skills only when needed.

Criteria for Splitting into Independent Markdown Skill Files

Monolithic system prompts should be split based on domain boundaries, tool execution permissions, and execution frequency. To prevent skills from conflicting during embedding similarity search, you should keep the number of simultaneously activated skills in a single session to 3 or fewer.

At the top of the separated skill file, specify a YAML front matter containing an identifier using only hyphens, lowercase English letters, and numbers, along with the operational purpose.

`yaml

name: backend-api-generator
description: Generates Spring Boot REST API controller and service boilerplate code. Use when the user asks to create API endpoints, build REST controllers, or define DTO mappings for backend services.
when_to_use:

  • User requests new REST API endpoint creation
  • User provides database schema and asks for controller layer implementation
  • Do NOT use for: database migration SQL, frontend component generation
    allowed-tools:
  • read_file
  • write_file
  • list_directory
    effort: medium

`

The process of building a step-by-step loading structure is simple.

  • Upon agent initialization, only the YAML front matter metadata of all skills within the directory (approximately 100 tokens per skill) is loaded into the prompt.
  • When a user request comes in, semantic similarity is compared with skill descriptions to dynamically load only the required skill body.
  • During the execution phase, necessary auxiliary scripts are executed according to the body instructions, and only the result values are included in the context.

Replacing a monolithic structure that constantly occupies 15,000 to 30,000 tokens with the SKILL.md lazy-loading structure reduces initial token overhead by over 90%. Based on Anthropic internal test data, the p95 latency can be shortened from 12% to 40% and average token consumption per conversation can be reduced by 29.6%.

Internal Constraints to Prevent Context Pollution

When multiple skills are loaded sequentially, instructions from previous skills often remain in the session and distort subsequent tasks. For high-risk inspections or tasks leaving heavy logs, you should add a sub-context branching (context: fork) setting in the YAML front matter to isolate them at the process level.

`yaml

name: security-vulnerability-auditordescription: Audits backend source code for OWASP top 10 security flaws. Use when auditing code security or checking for SQL injection vulnerabilities.
context: fork
model: claude-sonnet-4-20250514
effort: high

`

Clearly defining input/output data contracts (Data Contracts) is also essential.

  • Declare argument structures and allowed tool lists (allowed-tools) in the YAML metadata to prevent arbitrary Bash executions or reckless network calls.
  • Specify output schema rules in pure JSON format without markdown wrapping inside the body.
  • Restrict instructions to return only the final results to the conversation session.

`markdown

Output Schema Contract

All responses must strictly adhere to the following JSON structure without markdown wrapping:
{
"status": "SUCCESS" | "FAILED",
"generated_files": [
{
"path": "string",
"content": "string"
}
],
"error_message": "string | null"
}

`

Isolating into sub-processes prevents tool-calling logs from flooding into the main session. Since the main conversation session stays clean, the probability of errors when passing data between sub-agents is also reduced.

Designing Defensive Code to Block Infinite Loops

When requirements are ambiguous or tool-calling errors repeat, agents fall into infinite retry loops. This is the moment when dozens of dollars in API costs vanish within minutes. Putting a step-by-step Verification Checklist in the skill file body allows agents to perform self-verification before finishing tasks.

`markdown

Execution & Self-Testing Protocol

Before declaring the task finished, you MUST sequentially execute the following verification checklist:

  1. [Pre-check] Verify that all required input parameters are present. If mandatory arguments are missing, STOP immediately and ask the developer for input.
  2. [Generation] Write the requested implementation code.
  3. [Syntax Verification] Check the written code for missing imports, unresolved symbols, and syntax errors.
  4. [Self-Correction] If a syntax error is identified, attempt correction ONCE. Do not re-run the file write tool more than twice for the same error.

`

Writing a Circuit Breaker that physically breaks loops is also straightforward.

  • Specify the maximum tool call count (MAXIMUM_TOOL_CALL_LIMIT: 3) at the top of the skill.
  • Write constraints to halt additional tool calls if the same error code occurs twice in a row.
  • Instruct the system to immediately halt execution and output a notification format when a stop condition is met.

`markdown
[SKILL EXECUTION HALTED]
Skill Name: backend-api-generator
Failure Reason: [Brief error description]
Attempts Made: [Number of retries]
Suggested Action: [Action required by backend developer]

`

For dangerous tasks like file deletion or database drops, it is safer to apply the disable-model-invocation: true option. This prevents agents from calling them autonomously and restricts execution so that developers must manually type the slash command (/skill-name).

Team Shared Repository Version Control and Deployment

When team members write skills together, following the agentskills.io standard directory architecture prevents struggles with markdown file conflicts. Clearly divide and arrange bodies, CLI scripts, reference documents, and static template assets within parent folders.

Directory and File Path Role Writing Guidelines
skills/api-generator/SKILL.md Required entry point document Contains YAML front matter and core procedural instructions (under 500 lines)
skills/api-generator/scripts/ Executable code folder Location of Python/Bash CLI scripts called by agents when needed
skills/api-generator/references/ Auxiliary reference document folder Houses large API specs, DB schemas, style guide documents
skills/api-generator/assets/ Static resource template folder Stores generated code boilerplates and configuration file samples

When verifying skill quality, utilize the promptfoo evaluation framework.

  • Specify the target SKILL.md path and LLM model in the promptfooconfig.yaml file.
  • Write test cases to verify intent matching and JSON format compliance.
  • Execute the npx promptfoo@latest eval command in the terminal to measure instruction compliance rates.

`yaml
description: "Backend Agent Skills Validation Suite"
prompts:

  • "file://skills/api-generator/SKILL.md"
    providers:
  • id: "anthropic:messages:claude-3-5-sonnet-20241022"
    tests:
  • description: "Test automatic skill activation for REST API generation query"
    vars:
    user_query: "Create a Spring Boot REST Controller for User Management."
    assert:
    • type: icontains
      value: "backend-api-generator"
    • type: javascript
      value: "output.includes('@RestController') && output.includes('ResponseEntity')"

`

When deploying, combine a trunk-based development strategy using short-lived branches with Git tags (v1.2.0). If an agent behaves unexpectedly in production, you can immediately roll back to a previous tag point using the git checkout tags/v1.1.0 -b hotfix/rollback command.