Getting it into your agent
One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.
npx skills add simbajigege/book2skills --skill query-loop-implementationgit clone --depth 1 https://github.com/simbajigege/book2skillsWrote this? Show the measurements
A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.
[](https://agentmods.dev/skills/simbajigege/book2skills/query-loop-implementation)<a href="https://agentmods.dev/skills/simbajigege/book2skills/query-loop-implementation"><img src="https://agentmods.dev/badge/skills/simbajigege/book2skills/query-loop-implementation/github.svg" alt="Measured on agentmods" height="20"></a>Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.
<a href="https://agentmods.dev/skills/simbajigege/book2skills/query-loop-implementation"><img src="https://agentmods.dev/badge/skills/simbajigege/book2skills/query-loop-implementation.svg" alt="Reviewed on agentmods" width="80" height="20"></a>- NVIDIA SkillSpector pass
What it costs to keep this loaded
Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.
| Model | Per session | Once invoked |
|---|---|---|
| Fable 5.1 | $0.00075 | $0.01241 |
| Opus 5.5 | $0.00030 | $0.00496 |
| Sonnet 5.5 | $0.00015 | $0.00248 |
| Haiku 4.5 | $0.00007 | $0.00124 |
Grade A, and why
query-loop-implementation scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 1mo ago.
A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.
Nothing flagged
None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.
How it starts
The opening of the file, as written. The whole thing — 171 lines — stays where its author put it; the contents beside it link to each section on GitHub.
Query Loop Implementation
Core Idea
Build the loop as product infrastructure, not prompt glue:
ConversationManager -> QueryLoop -> ToolRuntime
ConversationManagerowns durable state: session id, messages, user settings, budget, persistence.QueryLoopowns one task turn: call model, detect tool calls, execute tools, append tool results, repeat.ToolRuntimeowns registered tools: schemas, permission checks, execution, error formatting.
Use ReAct as the mental model:
Thought -> Action -> Observation -> Thought -> Answer
Implement it as structured API traffic:
model thinking/text -> tool_call -> tool_result -> next model call -> final text
Implementation Workflow
-
Inspect the user's stack and current LLM call site. Find where messages are built, where the model is called, and whether tool/function calling is already configured.
-
Introduce a minimal query loop. Keep the first version narrow: one model call function, one tool registry, explicit exit conditions.
-
Normalize message shapes. Use the provider's structured tool-call format when available. Avoid parsing free-form
Action:text unless the provider has no function/tool-calling API. -
Add tool execution safety. Validate tool input against a schema, apply permission checks for risky tools, wrap failures as tool results, and log every call.
-
Add exit and budget guards before expanding features. Always include
maxTurns, timeout/cancel support, token/cost budget checks, and a fatal-error path. -
Keep context-window strategy outside this skill. Accept
messagesas loop input and return updatedmessages, but leave trimming, retrieval, summarization, and compaction to a separate context-management layer.
Minimal Loop
Adapt this shape to the user's language and SDK:
async function runQueryLoop({
initialMessages,
model,
tools,
maxTurns = 10,
signal,
}: {
initialMessages: Message[]
model: ModelClient
tools: ToolRegistry
maxTurns?: number
signal?: AbortSignal
}) {
let messages = [...initialMessages]
for (let turn = 1; turn <= maxTurns; turn++) {
if (signal?.aborted) return { status: "aborted", messages }
const response = await model.generate({
messages,
tools: tools.definitions(),
signal,
})
messages.push(response.message)
const toolCalls = extractToolCalls(response.message)
if (toolCalls.length === 0) {
return {
status: "completed",
finalMessage: response.message,
messages,
}
}
for (const call of toolCalls) {
const result = await tools.execute(call, { signal, messages })
messages.push(makeToolResultMessage(call.id, result))
}
}
return { status: "max_turns", messages }
}
What ships with it
5 files beside SKILL.md in the same directory: the scripts, references and assets a skill reads on demand. Not counted in the per-session cost; read them before you install if any of them is executable.
What this file has done since we first saw it
Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.
- 1mo ago First seen · 171 lines · 75 tokens per session scan A cf6555ee5332
query-loop-implementation is a skill published in the GitHub repository simbajigege/book2skills (194 stars, last pushed 2mo ago), licensed MIT. It adds 75 tokens to every session and 1,241 once invoked, about $0.0003 per session on Opus 5.5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.
Other skills, from other repositories
marketing-strategy-pmm
Product marketing, positioning, GTM strategy, and competitive intelligence. Includes ICP definition, April Dunford positioning methodology, launch playbooks, competitive battlecards, and international market entry guides. Use when developing positioning, planning product launches, creating messaging, analyzing…
loki-mode
Multi-agent autonomous startup system for Claude Code. Triggers on "Loki Mode". Orchestrates 100+ specialized agents across engineering, QA, DevOps, security, data/ML, business operations, marketing, HR, and customer success. Takes PRD to fully deployed, revenue-generating product with zero human intervention.…
qa-test-planner
Generate comprehensive test plans, manual test cases, regression test suites, and bug reports for QA engineers. Includes Figma MCP integration for design validation.
email-sequence
When the user wants to create or optimize an email sequence, drip campaign, automated email flow, or lifecycle email program. Also use when the user mentions "email sequence," "drip campaign," "nurture sequence," "onboarding emails," "welcome sequence," "re-engagement emails," "email automation," or "lifecycle…
emerging-techniques-long-context
Extend context windows of transformer models using RoPE, YaRN, ALiBi, and position interpolation techniques. Use when processing long documents (32k-128k+ tokens), extending pre-trained models beyond original context limits, or implementing efficient positional encodings. Covers rotary embeddings, attention biases…
prompt-engineering-guidance
Control LLM output with regex and grammars, guarantee valid JSON/XML/code generation, enforce structured formats, and build multi-step workflows with Guidance - Microsoft Research's constrained generation framework.