AGENT SKILL

cap-completion-length-and-stop-sequences

Use when model responses run long, cost more than expected, or never terminate cleanly. Set an output token cap and stop sequences, and detect the truncation the cap causes.

License 许可
MIT
最近更新
2026-11-15
Stars
★ 81
Forks
17

01 前言 Front Matter

name
cap-completion-length-and-stop-sequences
description
Use when model responses run long, cost more than expected, or never terminate cleanly. Set an output token cap and stop sequences, and detect the truncation the cap causes.

02 资源文件 3

03 SKILL.md 正文

Cap completion length and stop sequences

Unbounded generation is unbounded cost and a common source of corrupt output. Cap the response, define where it stops, and treat a cap-hit as a signal — not a silent trim.

Procedure

  1. Estimate the legitimate maximum output for the task: a classification is ~5 tokens, an extraction ~200, a summary ~500. Set max_tokens at roughly 1.5x that, not the model's global ceiling.

  2. Pass max_tokens on every call. The default is often large, and a runaway loop then bills for the full ceiling.

  3. Add stop sequences where the shape is known: "\n\n" for a one-paragraph answer, "</output>" for fenced blocks, a sentinel you asked the model to emit.

  4. Detect the cap hit explicitly: check finish_reason == "length" (OpenAI) or stop_reason == "max_tokens" (Anthropic). A truncated response is a failure to handle, not a short success.

if resp.finish_reason == "length":
    raise Truncated(task_id, cap=req.max_tokens)   # retry bigger or split the task
  1. On a cap hit, either raise the cap for that task (if genuinely long) or split the work — do not silently accept a half answer.

  2. Track the fraction of calls hitting the cap; a rising rate means your prompts or inputs grew, or the model changed.

  3. Beware stop sequences that appear inside valid content — a quote containing "\n\n" truncates early. Choose sentinels that cannot occur naturally.

Pitfalls

  • Leaving max_tokens unset, so one bad prompt generates to the full limit and inflates the bill.
  • Setting the cap to the model's maximum "to be safe" — you have not capped anything.
  • Ignoring finish_reason and parsing truncated JSON, producing a decode error far from the cause.
  • A stop sequence the model emits mid-content (}, END) cutting a valid answer short.
  • Splitting long output only after it was truncated, losing the dropped content — split before regenerating.
  • Setting one global cap for all endpoints, so the short classification inherits the long-report budget.
  • Forgetting the cap is per response, not per session; a multi-call task still needs a total budget.

Verification

python3 -c "import json;r=[json.loads(l) for l in open('resp.jsonl')];print(sum(x['fr']=='length' for x in r), len(r))"   # cap-hit fraction; investigate if >2%

Report: "max_tokens=512 with stop='</json>'; cap-hit rate 0.3% over 20k calls, and every hit raises Truncated instead of returning a partial object."

04 同仓库更多 Skills

jiayaoqijia
jiayaoqijia/cryptoskill

troves

Deposit and withdraw from Troves DeFi yield vault strategies on Starknet. View available strategies, check positions, and manage vault deposits. Use this skill when the user mentions Troves, vault, yield vault, DeFi vault, strategy, yield farming, vault deposit, vault withdraw, earning yield through vaults, passive yield strategies, or wants to deposit into or withdraw from a yield strategy — even if they don't say "Troves" explicitly.

★ 81
jiayaoqijia
jiayaoqijia/cryptoskill

trade

Swap tokens on Starknet via Fibrous DEX aggregator. Supports per-provider selection (avnu, ekubo, or auto to race all). Use this skill when the user wants to swap, exchange, trade, convert, buy, or sell one token for another on Starknet. Also use when the user asks about token prices, exchange rates, DEX routing, best swap route, or wants to check how much they would receive for a given amount — even if they don't explicitly say "swap".

★ 81
jiayaoqijia
jiayaoqijia/cryptoskill

staking

Stake, unstake, claim, and compound rewards for STRK, WBTC, tBTC, SolvBTC, and LBTC on Starknet. View validators, pools, and staking positions. Use this skill when the user mentions staking, delegating, validators, staking pools, rewards, compounding, unstaking, earning yield, passive income on crypto, or wants to earn on their STRK or BTC tokens — even if they don't say "stake" explicitly.

★ 81
jiayaoqijia
jiayaoqijia/cryptoskill

send

Send STRK, ETH, or any ERC-20 token to a Starknet address. Supports simulation (dry-run) before execution. Use this skill when the user wants to send, transfer, pay, tip, or move tokens to another wallet address on Starknet. Also trigger when the user mentions sending funds to someone, making a payment, transferring assets, or moving crypto to a specific address — even if they just say "pay 10 STRK to 0x...".

★ 81
jiayaoqijia
jiayaoqijia/cryptoskill

portfolio

View a comprehensive DeFi portfolio dashboard and optimize portfolio allocation via automated rebalancing. Use this skill when the user wants an overview, summary, dashboard, total value, net worth, portfolio rebalancing, target allocation, or wants to see all their DeFi positions across Starknet at once. Also trigger when the user asks "what do I have", "show me everything", "how much am I worth", "my positions", "my investments", "rebalance my portfolio", "I want 50% ETH", "optimize my holdings", or any request for a holistic view of their Starknet holdings — even if they don't explicitly say "portfolio".

★ 81
jiayaoqijia
jiayaoqijia/cryptoskill

multi-swap

Execute multiple token swaps in a single Starknet transaction via Fibrous (default). Supports per-provider selection (avnu, ekubo, or auto to race all). Supports 2-3 swap pairs bundled into one multicall. Use this skill when the user wants to swap multiple token pairs at once, do batch swaps, execute several trades simultaneously, perform parallel swaps, or do bulk trading in one transaction. Also trigger when the user mentions "two swaps", "three swaps", "swap X and Y at the same time", or wants to convert multiple tokens in a single call.

★ 81