sdk-agent-control
Use this skill when controlling agent behavior in TypeScript Agent SDK platforms — restricting allowed tools, setting budget and turn limits, crafting system prompts that guide agents to specific behaviors, implementing the file pre-creation pattern, augmenting prompts with runtime context, building message loggers, or tracking agent run metadata (cost, duration, iterations).
What this skill does
# Agent Control Patterns for SDK Platforms
## Core Control Levers
Control agents through five primary mechanisms:
1. **`allowedTools`** — what tools the agent can call
2. **`permissionMode`** — whether to bypass permission prompts
3. **`maxTurns`** — hard iteration cap
4. **`maxBudgetUsd`** — hard spend cap
5. **`hooks`** — programmatic allow/deny on every tool call
## Pattern: Minimal Tool Allow-List
Give the agent only the tools it needs. Fewer tools = more predictable behavior:
```typescript
// For a code-writing agent: read and edit only
allowedTools: ["Read", "Write", "Edit", "Glob", "Grep"]
// For a test runner: also needs Bash
allowedTools: ["Read", "Write", "Edit", "Bash", "Glob", "Grep"]
// For a read-only analysis agent
allowedTools: ["Read", "Glob", "Grep"]
```
## Pattern: File Pre-Creation
Pre-create the output file before running the agent. Instruct the agent to use `Edit` instead of `Write`:
```typescript
// 1. Scaffold the file before SDK run
writeFileSync(testFilePath, "// Scaffolded by platform\n", "utf8");
// 2. Augment the prompt with file path instruction
function buildPromptWithFilePath(userPrompt: string, testFilePath: string): string {
return [
userPrompt,
"",
"---",
`IMPORTANT: A file has been pre-created at: ${testFilePath}`,
"Use the Edit tool to modify this file. Do NOT create a new file with Write.",
].join("\n");
}
// 3. Read the file back after SDK completes
const code = readFileSync(testFilePath, "utf8");
```
**Why**: Combining `createFileRestrictionHook(testFilePath)` with pre-creation gives you full control over what the agent writes and where.
## Pattern: Constants File
Never hardcode SDK config inline. Use a dedicated `*.const.ts`:
```typescript
// agent-sdk.const.ts
export const SDK_MODEL = "claude-sonnet-4-5-20250929" as const;
export const SDK_MAX_BUDGET_USD = 2; // $2 hard cap
export const SDK_MAX_TURNS = 50; // 50 iterations max
export const SDK_PERMISSION_MODE = "bypassPermissions" as const;
export const SDK_ALLOWED_TOOLS = ["Read", "Write", "Edit", "Bash", "Glob", "Grep"] as const;
// Per-tool timeouts (used in hooks)
export const ESLINT_TIMEOUT_MS = 30_000;
export const TSC_TIMEOUT_MS = 60_000;
export const LINT_OUTPUT_TRUNCATION_LIMIT = 2_000;
export const TSC_OUTPUT_TRUNCATION_LIMIT = 3_000;
```
## Pattern: System Prompt Engineering
System prompts control agent strategy. Structure them with explicit phases:
```typescript
const systemPrompt = `
You are a test generation agent. Follow these phases strictly:
## Phase 1: Analyze
Read the source file. Identify all exported functions/classes.
## Phase 2: Generate
Write comprehensive tests to the pre-created test file using Edit.
Cover: happy path, edge cases, error cases.
## Phase 3: Verify
Run the tests with Bash. Do NOT run more than 3 times.
## Constraints
- ONLY edit the pre-created test file
- Do NOT install packages
- Do NOT modify source files
`.trim();
```
## Pattern: Conditional Hook Composition
Build the hook list dynamically — some hooks may not be available:
```typescript
const fileRestrictionHook = createFileRestrictionHook(params.testFilePath);
const lintFixHook = createLintFixHook(params.workingDirectory, params.testFilePath);
const typecheckHook = createTypecheckHook(params.workingDirectory, params.testFilePath);
const postEditHooks = [
...(lintFixHook ? [lintFixHook] : []),
...(typecheckHook ? [typecheckHook] : []),
];
const hooks = {
PreToolUse: [
{ matcher: "Write|Edit", hooks: [fileRestrictionHook] },
{ matcher: "Read", hooks: [envProtectionHook] },
],
PostToolUse: [
{ matcher: "Bash", hooks: [testPruneHook] },
...(postEditHooks.length > 0 ? [{ matcher: "Write|Edit", hooks: postEditHooks }] : []),
],
};
```
## Pattern: Run Metadata
Always track and persist run metadata for observability:
```typescript
if (isResultMessage(message)) {
const metadata = {
durationMs: message.duration_ms,
costUsd: message.total_cost_usd,
numTurns: message.num_turns,
modelUsage: message.modelUsage,
subtype: message.subtype, // "success" | "error_max_turns" | "error_during_execution"
};
logger.info("SDK run complete", metadata);
// Prepend to output file as a JSDoc comment
const comment = [
"/**",
` * @generated Agent SDK`,
` * @duration ${(message.duration_ms / 1000).toFixed(1)}s`,
` * @cost $${message.total_cost_usd.toFixed(4)}`,
" */",
"",
].join("\n");
const existing = readFileSync(outputPath, "utf8");
writeFileSync(outputPath, comment + existing, "utf8");
}
```
## Pattern: AbortSignal with Cleanup
Forward cancellation from external sources to the SDK:
```typescript
async run(params: { abortSignal?: AbortSignal }): Promise<Result> {
const abortController = new AbortController();
if (params.abortSignal) {
params.abortSignal.addEventListener("abort", () => abortController.abort());
}
try {
for await (const message of query({ ..., options: { ..., abortController } })) {
if (abortController.signal.aborted) break;
// ...
}
} finally {
// cleanup if needed
}
}
```
## Pattern: Verbose Logging Toggle
Use an env-controlled verbose flag to switch between minimal and debug logging:
```typescript
export const isSdkVerboseLogging = process.env.SDK_VERBOSE === "true";
// In your MessageLogger
logMessage(message: SDKMessage): void {
if (!this.verbose) return; // skip in production
console.log("[SDK]", message.type, ...);
}
```
## Advanced Control Patterns
For more patterns from these references:
- **`references/hook-strategy.md`** — hook strategy matrix, minimum safe set, graduated levels (security→control→quality→guidance), composition best practices, anti-patterns to avoid
- **`references/velocity-control.md`** — velocity governor (rate-limit tool calls per minute), output validator (heuristic placeholder detection), `maxTurns` as circuit breaker, budget guard hook, auto-checkpoint in `finally` block
Example:
- **`examples/complete-runner.ts`** — production-ready runner with Inversify DI, conditional hook composition, null-filtering, augmented prompt, full message iteration, metadata prepend
Related in Backend & APIs
jfrog
IncludedInteract with the JFrog Platform via the JFrog CLI and REST/GraphQL APIs. Use this skill when the user wants to manage Artifactory repositories, upload or download artifacts, manage builds, configure permissions, manage users and groups, work with access tokens, configure JFrog CLI servers, search artifacts, manage properties, set up replication, manage JFrog Projects, run security audits or scans, look up CVE details, query exposures scan results from JFrog Advanced Security, manage release bundles and lifecycle operations, aggregate or export platform data, or perform any JFrog Platform administration task. Also use when the user mentions jf, jfrog, artifactory, xray, distribution, evidence, apptrust, onemodel, graphql, workers, mission control, curation, advanced security, exposures, or any JFrog product name.
cupynumeric-migration-readiness
IncludedPre-migration readiness assessor for porting NumPy to cuPyNumeric. Use BEFORE substantial porting work begins when the user asks whether code will scale on GPU, whether they should migrate to cuPyNumeric, which NumPy patterns transfer cleanly, what must be refactored before porting, or mentions pre-port assessment, scaling analysis, or refactor planning. Inspect the user's source code, look up NumPy usage, cross-reference the cuPyNumeric API support manifest, and distinguish distributed-scaling-friendly patterns from blockers such as unsupported APIs, scalar synchronization, host round-trips, Python/object-heavy control flow, shape/data-dependent branching, and in-place mutation hazards. Produce a verdict of READY, LIGHT REFACTOR, SIGNIFICANT REFACTOR, or NOT RECOMMENDED, with concrete refactor pointers.
alibabacloud-data-agent-skill
IncludedInvoke Alibaba Cloud Apsara Data Agent for Analytics via CLI to perform natural language-driven data analysis on enterprise databases. Data Agent for Analytics is an intelligent data analysis agent developed by Alibaba Cloud Database team for enterprise users. It automatically completes requirement analysis, data understanding, analysis insights, and report generation based on natural language descriptions. This tool supports: discovering data resources (instances/databases/tables) managed in DMS, initiating query or deep analysis sessions, real-time progress tracking, and retrieving analysis conclusions and generated reports. Use this Skill when users need to query databases, analyze data trends, generate data reports, ask questions in natural language, or mention "Data Agent", "data analysis", "database query", "SQL analysis", "data insights".
token-optimizer
IncludedReduce OpenClaw token usage and API costs through smart model routing, heartbeat optimization, budget tracking, and native 2026.2.15 features (session pruning, bootstrap size limits, cache TTL alignment). Use when token costs are high, API rate limits are being hit, or hosting multiple agents at scale. The 4 executable scripts (context_optimizer, model_router, heartbeat_optimizer, token_tracker) are local-only — no network requests, no subprocess calls, no system modifications. Reference files (PROVIDERS.md, config-patches.json) document optional multi-provider strategies that require external API keys and network access if you choose to use them. See SECURITY.md for full breakdown.
resend-cli
IncludedUse this skill when the task is specifically about operating Resend from an AI agent, terminal session, or CI job via the official resend CLI: installing/authenticating the CLI, sending/listing/updating/cancelling emails, batch sends, domains and DNS, webhooks and local listeners, inbound receiving, contacts, topics, segments, broadcasts, templates, API keys, profiles, or debugging Resend CLI/API failures. Trigger on mentions of Resend CLI, `resend`, `resend doctor`, `resend emails send`, `resend domains`, `resend webhooks listen`, `resend emails receiving`, or agent-friendly terminal automation.
alibabacloud-odps-maxframe-coding
IncludedUse this skill for MaxFrame SDK development and documentation navigation on Alibaba Cloud MaxCompute (ODPS). Helps answer MaxFrame API, concept, official example, and supported pandas API questions; create data processing programs; read/write MaxCompute tables; debug jobs (remote or local); and build custom DPE runtime images. Trigger when users mention MaxFrame, MaxCompute with MaxFrame, ODPS table processing, DPE runtime, MaxFrame docs/examples, DataFrame/Tensor operations, or GPU runtime setup. Works for both English and Chinese queries about Alibaba Cloud data processing with MaxFrame.