building-agents
Skill8 starsChanged 9 days agoMITView on GitHub
Designs and hardens LLM agents that call tools in a loop - choosing between a single call, a fixed workflow and an agent, tool design, context management, stop conditions and budgets, human approval, sandboxing, prompt-injection defenses, tracing and agent evaluation. Use when building an AI agent, assistant with tools, coding or research agent, multi-agent system, or when an agent loops, picks wrong tools, runs up cost or takes unsafe actions. Not for single LLM calls (use llm-integration) or MCP server code (use mcp-servers).
2 other projects use a version of this.
Adopted by
Most recently taken up by
- lauren-framework/lauren-aitheir own version, first seen Nov 1, 2026
- tines/skillstheir own version, first seen Aug 24, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- tines/skills★ 1same name
- lauren-framework/lauren-ai★ 0same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository60 other files it gives its agents.
- api-designSkill
- auth-implementationSkill
- background-jobsSkill
- caching-strategiesSkill
- ci-cd-pipelinesSkill
- cloud-cost-optimizationSkill
- codebase-onboardingSkill
- code-review-changesSkill
- concurrency-patternsSkill
- database-migrationsSkill
- database-schema-designSkill
- database-testingSkill
- data-pipelinesSkill
- data-privacy-retentionSkill
- dependency-upgradesSkill
- design-docsSkill
- design-systemsSkill
- dockerfilesSkill
- domain-driven-designSkill
- event-driven-architectureSkill
- file-storage-uploadsSkill
- frontend-securitySkill
- git-workflowSkill
- graphql-apisSkill
- grpc-servicesSkill
- incident-responseSkill
- infrastructure-as-codeSkill
- internationalizationSkill
- kubernetes-deploymentsSkill
- large-scale-migrationsSkill
- legacy-refactoringSkill
- llm-evalsSkill
- llm-integrationSkill
- mcp-serversSkill
- micro-frontendsSkill
- ml-experimentsSkill
- monorepo-managementSkill
- nosql-designSkill
- observabilitySkill
- orm-patternsSkill
- performance-profilingSkill
- postgres-operationsSkill
- rag-systemsSkill
- react-patternsSkill
- realtime-apisSkill
- resilience-patternsSkill
- root-cause-debuggingSkill
- search-integrationSkill
- security-auditSkill
- seo-and-ssrSkill
- sql-optimizationSkill
- system-designSkill
- test-strategySkill
- threat-modelingSkill
- typescript-patternsSkill
- unit-testingSkill
- verify-before-doneSkill
- web-accessibilitySkill
- web-performanceSkill
- writing-skillsSkill
The file
We split this skill into the rules it gives an agent
11 rules. About 0 are common, 11 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈11
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 20
Start at the lowest level and move up only when an eval shows the lower level fails.
- Distinctive: line 37
Keep the loop in your code, where you can log, limit, and stop it.
- Distinctive: line 64
Keep tool results short; store large outputs (files, logs, query results) outside the context and return a handle plus a summary.
- Distinctive: line 67
Put stable content (system prompt, tool definitions) first and keep it unchanged across steps to benefit from prompt caching.
- Distinctive: line 71
Always enforce in code, never only in the prompt:
- Distinctive: line 79
When a limit triggers, stop cleanly: return what was done, what wasn't, and why.
- Distinctive: line 88
Audit log: every action taken with arguments and results.
- Distinctive: line 98
Trajectory review: read a sample of runs, successes too.
- Distinctive: line 100
Run each task more than once.
- Distinctive: line 113
Trusting self-reported success: - verify with checks.
- Distinctive: line 123
Every run is traced, and success rate, cost per task and trajectory review are reported on a fixed task set with repeated trials.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Building Agents
An agent is a model choosing actions in a loop, so every weakness of a single call is multiplied by the number of steps. Use the least autonomy that solves the task, give the agent few well-designed tools with the least privilege, bound every loop, and put a human in front of anything irreversible.
Choose the level of autonomy
| Level | Shape | Use when |
| 1. Single call | One prompt, maybe structured output | The task fits in one step with the context you already have. |
| 2. Fixed workflow | Code calls the model in a known sequence (chain, router, parallel map, generate-then-check) | Steps are known in advance. Easier to test, cheaper, predictable. |
| 3. Agent | Model decides which tool to call next until done | Steps can't be known in advance (open-ended search, debugging, multi-step edits). |
| 4. Multi-agent | Several agents with separate contexts | Sub-tasks are truly independent and parallel, or need isolated context or permissions. |
Start at the lowest level and move up only when an eval shows the lower level fails. Most "agents" in production are level 2.
The loop
context = system prompt + task + tool definitions
loop:
response = model(context)
if response has no tool calls: return final answer
for each tool call:
check permissions / approval
result = run tool (sandboxed, with timeout)
append concise result (or error) to context
enforce limits: steps, tokens, cost, wall time
compact context if near the limitKeep the loop in your code, where you can log, limit, and stop it.
Workflow
- Write the task contract: what "done" means, what the agent may and may not do, budgets (steps, cost, time), and what needs human approval.
- Build the task set first: 20+ realistic tasks with a way to check success (tests pass, file contains X, ticket has field Y). This is your eval.
- Design a small tool set (see below). Fewer, task-shaped tools beat many thin API wrappers.
- Write the system prompt: goal, how to approach the work, when to ask the user, when to stop, output format for the final answer.
- Implement the loop with limits, tracing and approval gates from day one.
- Run the task set, read trajectories, fix the most common failure (usually tool descriptions or missing information), re-run.
- Harden: sandbox, permissions, injection defenses, cost ceilings.
- Ship with monitoring: per-run traces, success signals, cost per task, alerts on runaway loops.
Tool design
- Name and describe tools for a new teammate: what it does, when to use it, when not to, what the parameters mean, example values. The description is the agent's only documentation.
- Typed, constrained parameters: JSON Schema with enums, formats and required fields. Accept human-meaningful identifiers (names, paths) and resolve IDs in the tool, not in the model.
- Task-shaped, not endpoint-shaped:
schedule_meeting(attendees, duration, window)instead oflist_calendars+get_events+create_event. - Concise results: return what the agent needs, with pagination or truncation and a note saying more exists. Don't dump 10,000-line JSON into the context.
- Actionable errors: "No customer named 'Acme Inc'. Did you mean 'Acme Corp' (id 412)?" instead of a stack trace.
- Idempotent and safe to retry where possible; separate read tools from write tools.
Full checklist: references/tool-design-checklist.md.
Context management
- The context window is working memory. Everything in it costs money and attention.
- Keep tool results short; store large outputs (files, logs, query results) outside the context and return a handle plus a summary.
- For long tasks, keep a notes or progress file the agent updates (plan, decisions, what's done), and compact old turns into a summary when the context fills.
- Delegate self-contained sub-tasks to a sub-agent with a fresh context that returns only its conclusion, when the sub-task would otherwise flood the main context.
- Put stable content (system prompt, tool definitions) first and keep it unchanged across steps to benefit from prompt caching.
Stop conditions and budgets
Always enforce in code, never only in the prompt:
- Max steps (tool calls) per task.
- Max tokens or cost per task, and per user per day.
- Max wall-clock time; per-tool timeouts.
- Repetition detection: the same tool with the same arguments several times in a row, or no progress for N steps, ends the run or asks the user.
- A clear final-answer format, so "done" is detectable.
When a limit triggers, stop cleanly: return what was done, what wasn't, and why.
Safety
- Least privilege: the agent's credentials can do only what the task needs; scope to the current user; read-only by default.
- Human approval for irreversible or outward-facing actions: sending messages, deleting, paying, deploying, merging, changing permissions. Show exactly what will happen and wait for a yes.
- Sandbox code execution and file access: container or VM, no host secrets, restricted network egress, resource limits.
- Prompt injection: tool results (web pages, files, emails, issue comments, API responses) can contain instructions. Treat them as data. Don't let content read from untrusted sources trigger privileged actions without approval. Watch for exfiltration through URLs, images or outbound requests.
- Validate tool arguments server-side; never trust the model's claim about identity or permissions.
- Audit log every action taken with arguments and results.
Observability
Trace every run: task, each model call (tokens, latency), each tool call (arguments, result size, duration, error), approvals, final outcome and total cost. Make trajectories easy to read; you'll debug agents by reading them.
Evaluating agents
- Outcome: success rate on the fixed task set, checked by code where possible (tests, state of the environment), not by asking the agent if it succeeded.
- Efficiency: steps, tokens, cost and time per successful task.
- Trajectory review: read a sample of runs, successes too. Look for wrong tool choice, repeated calls, ignored errors, unsafe actions, giving up early, claiming success falsely.
- Safety cases: tasks containing injected instructions, missing permissions, or ambiguous requests where the right move is to ask.
- Run each task more than once; agents are high-variance. Report success over multiple trials.
- Re-run the suite on every change to prompts, tools or model. See the
llm-evalsskill.
Multi-agent systems
Use them only when sub-tasks are independent and parallel (e.g. researching several sources), or need isolation (separate permissions or a clean context). Costs rise with every agent and hand-offs lose information. Give each sub-agent a complete brief and ask for a compact, structured result. Prefer an orchestrator that owns the plan and merges results over agents chatting freely.
Anti-patterns
- Agent where a workflow would do - more cost, less reliability, harder tests.
- Dozens of overlapping tools - the model picks wrong ones. Merge and rename.
- Raw API dumps as tool results - context floods and quality drops.
- Limits only in the prompt - "don't loop forever" doesn't stop a loop.
- Trusting self-reported success - verify with checks.
- Broad credentials - an agent with admin tokens turns one injection into an incident.
- No traces - you can't fix what you can't see.
Done when
- The autonomy level is justified (a simpler level failed the eval, or the task can't be scripted).
- Tools pass the checklist; results are concise; errors are actionable.
- Step, cost and time limits plus repetition detection are enforced in code.
- Irreversible actions require human approval; execution is sandboxed with least privilege.
- Every run is traced, and success rate, cost per task and trajectory review are reported on a fixed task set with repeated trials.
References
- references/tool-design-checklist.md - read when adding, renaming or debugging tools.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

