[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M74G5650ZM0112DZJTWN1ARH":3,"skill-same:01M74G5650ZM0112DZJTWN1ARH":50},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":19,"linkOnly":20,"markdownContent":21,"markdownBody":22,"frontMatter":23,"refName":24,"commitSha":25,"skillDirectory":26,"forksCount":14,"repositoryHtmlUrl":27,"repositoryHomepageUrl":6,"ownerHtmlUrl":28,"ownerBlogUrl":6,"ownerDescription":6,"updatedAt":29,"install":30,"resources":43},"01M74G5650ZM0112DZJTWN1ARH","agent-design",null,"Design an LLM agent — architecture (ReAct, plan-execute, reflexion), tool\u002Ffunction-calling contract, memory, multi-agent orchestration, and the stop\u002Fbudget conditions.","MohammadBafkar\u002Fpolymath","MohammadBafkar","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F34940462?v=4","01M74G540TQFZWK6KVAPKFVGNR","Mohammad Bafkar","01M74G541HG19QP9V5DQCJVKYE",0,"MIT","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-ai\u002Fskills\u002Fagent-design\u002FSKILL.md",[],[],"2026-11-11 15:11:14",false,"---\nname: agent-design\ndescription: Design an LLM agent — architecture (ReAct, plan-execute, reflexion), tool\u002Ffunction-calling contract, memory, multi-agent orchestration, and the stop\u002Fbudget conditions.\n---\n\n# agent-design\n\n> An agent is a loop around a model with tools and a stopping rule. Most agent failures are a missing stop condition, a vague tool contract, or unbounded context — design those first.\n\n**Mode:** analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked `[TBD]` or `[VERIFY]`, never filled in.\n\n## When to use\n\n- Building a feature where the model must call tools, take multiple steps, or coordinate sub-agents.\n- An existing agent loops forever, burns tokens, or calls the wrong tool.\n- A workflow invokes `polymath-ai:agent-design`.\n\nNot this when: you are shaping a single prompt's wording and output — that is `polymath-ai:prompt-engineer`. For retrieval design, `polymath-ai:rag-design`. For the eval harness, `polymath-ai:eval-plan`. For the input\u002Foutput safety layer, `polymath-ai:llm-guardrails`.\n\n## Inputs\n\n- The task the agent performs and the tools\u002Factions available.\n- Latency, cost, and autonomy constraints (can it act without confirmation?).\n\n## Procedure\n\n0. **Decide whether it needs to be an agent.** If the steps are known in advance, a deterministic workflow — a prompt chain, a router, parallel calls with a merge, or an evaluator-optimizer loop with a fixed iteration cap — is cheaper, faster, and easier to test. Choose an open-ended agent loop only when the path genuinely depends on what the model discovers along the way, and say which it is.\n1. **Pick the control pattern by task shape**:\n   - *Single-shot + tools* — one model call that may call tools; simplest, use when one round suffices.\n   - *ReAct (reason→act→observe loop)* — interleaved reasoning and tool calls until done; the default for multi-step tool use.\n   - *Plan-then-execute* — plan the steps up front, then execute; better for long tasks where mid-course replanning is costly.\n   - *Reflexion \u002F critic* — a verify step that critiques and retries; add only where correctness justifies the extra calls.\n   - *Multi-agent* (orchestrator + sub-agents) — justify the orchestration cost; a single agent with well-scoped tools is often simpler. Sub-agents earn their place by isolating context: give each a minimal brief and have it return a condensed result, not its transcript.\n2. **Define the tool contract** per tool: name, when to use (and when not), typed inputs\u002Foutputs, side-effect class (read-only vs mutating), idempotency, and failure behavior. Ambiguous tool descriptions are the top cause of wrong tool calls. Keep the toolset small — selection accuracy drops as near-duplicate tools pile up; load rarely used tools on demand.\n3. **Return errors as tool results.** A failed call returns a structured, model-readable error (what failed, whether retrying can help, what to try instead) — not an exception that kills the loop or a silent empty result.\n4. **Design memory** explicitly: what is in the working context each turn, what is summarized, what is retrieved on demand, and the context-window budget. Unbounded transcript growth is a latency\u002Fcost bug waiting to happen (each turn re-sends the history).\n5. **Set hard stop conditions**: max steps, max tokens\u002Fcost, wall-clock, and a \"no-progress\" detector (same tool + same args repeated, no new information). Every loop must terminate by construction.\n6. **Decide autonomy + human-in-the-loop**: which actions run freely (read-only), which require confirmation (mutating\u002Firreversible). Map to a propose-vs-act policy. Mutating tools should be idempotent (accept a request ID) so a retried step can't double-apply.\n7. **Treat tool output as untrusted input.** Web pages, documents, emails, and API responses the agent reads can carry injected instructions; scope each tool's privileges so a hijacked agent can't exceed the user's own authority (design the controls with `polymath-ai:llm-guardrails`).\n8. **Plan failure handling**: tool errors, malformed tool args, and model refusals each get a recovery path (retry, reprompt, escalate, abort).\n9. **Make it observable + evaluable**: trace each step (thought, tool, args, result, tokens). Evaluate trajectories as well as final answers — right tool, right args, no wasted or unsafe steps — and hand the success criteria to `polymath-ai:eval-plan`.\n\n## Output\n\n```text\nAgent design: \u003Cagent name>\n\nShape:      agent loop (path depends on findings) | workflow (steps known)\nPattern:    ReAct, single agent — why: \u003Creason>; rejected: multi-agent (\u003Creason>)\n\nTools:\n  name            when to use              side effect   idempotent   on failure\n  search_orders   look up an order by id   read-only     n\u002Fa          error result: not_found | retryable\n  issue_refund    after user confirmation  mutating      request_id   error result; never auto-retry\n\nMemory:     last 6 turns verbatim + rolling summary; order data fetched on demand\n            context budget: 24k tokens\u002Fturn\nStop:       ≤ 12 steps · ≤ $0.40 · ≤ 90 s · abort on 2 identical consecutive calls\nAutonomy:   reads free; issue_refund requires explicit user confirmation\nUntrusted:  order notes + email bodies → data only; agent cannot email out\nFailures:   malformed args → reprompt once; tool 5xx → retry ×2 with backoff; refusal → escalate\nEvals:      trajectory + outcome suite → polymath-ai:eval-plan\n```\n\n## Quality bar\n\n- The workflow-vs-agent choice is explicit; an agent loop is justified by a path that genuinely can't be known in advance.\n- Every loop has explicit, enumerated stop conditions — no \"until done\".\n- Each tool states its side-effect class, idempotency, and confirmation requirement, and fails with a structured error result.\n- Context growth is bounded (summarize\u002Fretrieve), with a stated token budget.\n- Tool output is treated as untrusted; privileges are scoped so injection can't escalate.\n- Evaluation covers trajectories, not only final answers.\n","# agent-design\n\n> An agent is a loop around a model with tools and a stopping rule. Most agent failures are a missing stop condition, a vague tool contract, or unbounded context — design those first.\n\n**Mode:** analytical — judgment inside a fixed frame. Keep the output shape; every verdict cites its evidence; unknowns are marked `[TBD]` or `[VERIFY]`, never filled in.\n\n## When to use\n\n- Building a feature where the model must call tools, take multiple steps, or coordinate sub-agents.\n- An existing agent loops forever, burns tokens, or calls the wrong tool.\n- A workflow invokes `polymath-ai:agent-design`.\n\nNot this when: you are shaping a single prompt's wording and output — that is `polymath-ai:prompt-engineer`. For retrieval design, `polymath-ai:rag-design`. For the eval harness, `polymath-ai:eval-plan`. For the input\u002Foutput safety layer, `polymath-ai:llm-guardrails`.\n\n## Inputs\n\n- The task the agent performs and the tools\u002Factions available.\n- Latency, cost, and autonomy constraints (can it act without confirmation?).\n\n## Procedure\n\n0. **Decide whether it needs to be an agent.** If the steps are known in advance, a deterministic workflow — a prompt chain, a router, parallel calls with a merge, or an evaluator-optimizer loop with a fixed iteration cap — is cheaper, faster, and easier to test. Choose an open-ended agent loop only when the path genuinely depends on what the model discovers along the way, and say which it is.\n1. **Pick the control pattern by task shape**:\n   - *Single-shot + tools* — one model call that may call tools; simplest, use when one round suffices.\n   - *ReAct (reason→act→observe loop)* — interleaved reasoning and tool calls until done; the default for multi-step tool use.\n   - *Plan-then-execute* — plan the steps up front, then execute; better for long tasks where mid-course replanning is costly.\n   - *Reflexion \u002F critic* — a verify step that critiques and retries; add only where correctness justifies the extra calls.\n   - *Multi-agent* (orchestrator + sub-agents) — justify the orchestration cost; a single agent with well-scoped tools is often simpler. Sub-agents earn their place by isolating context: give each a minimal brief and have it return a condensed result, not its transcript.\n2. **Define the tool contract** per tool: name, when to use (and when not), typed inputs\u002Foutputs, side-effect class (read-only vs mutating), idempotency, and failure behavior. Ambiguous tool descriptions are the top cause of wrong tool calls. Keep the toolset small — selection accuracy drops as near-duplicate tools pile up; load rarely used tools on demand.\n3. **Return errors as tool results.** A failed call returns a structured, model-readable error (what failed, whether retrying can help, what to try instead) — not an exception that kills the loop or a silent empty result.\n4. **Design memory** explicitly: what is in the working context each turn, what is summarized, what is retrieved on demand, and the context-window budget. Unbounded transcript growth is a latency\u002Fcost bug waiting to happen (each turn re-sends the history).\n5. **Set hard stop conditions**: max steps, max tokens\u002Fcost, wall-clock, and a \"no-progress\" detector (same tool + same args repeated, no new information). Every loop must terminate by construction.\n6. **Decide autonomy + human-in-the-loop**: which actions run freely (read-only), which require confirmation (mutating\u002Firreversible). Map to a propose-vs-act policy. Mutating tools should be idempotent (accept a request ID) so a retried step can't double-apply.\n7. **Treat tool output as untrusted input.** Web pages, documents, emails, and API responses the agent reads can carry injected instructions; scope each tool's privileges so a hijacked agent can't exceed the user's own authority (design the controls with `polymath-ai:llm-guardrails`).\n8. **Plan failure handling**: tool errors, malformed tool args, and model refusals each get a recovery path (retry, reprompt, escalate, abort).\n9. **Make it observable + evaluable**: trace each step (thought, tool, args, result, tokens). Evaluate trajectories as well as final answers — right tool, right args, no wasted or unsafe steps — and hand the success criteria to `polymath-ai:eval-plan`.\n\n## Output\n\n```text\nAgent design: \u003Cagent name>\n\nShape:      agent loop (path depends on findings) | workflow (steps known)\nPattern:    ReAct, single agent — why: \u003Creason>; rejected: multi-agent (\u003Creason>)\n\nTools:\n  name            when to use              side effect   idempotent   on failure\n  search_orders   look up an order by id   read-only     n\u002Fa          error result: not_found | retryable\n  issue_refund    after user confirmation  mutating      request_id   error result; never auto-retry\n\nMemory:     last 6 turns verbatim + rolling summary; order data fetched on demand\n            context budget: 24k tokens\u002Fturn\nStop:       ≤ 12 steps · ≤ $0.40 · ≤ 90 s · abort on 2 identical consecutive calls\nAutonomy:   reads free; issue_refund requires explicit user confirmation\nUntrusted:  order notes + email bodies → data only; agent cannot email out\nFailures:   malformed args → reprompt once; tool 5xx → retry ×2 with backoff; refusal → escalate\nEvals:      trajectory + outcome suite → polymath-ai:eval-plan\n```\n\n## Quality bar\n\n- The workflow-vs-agent choice is explicit; an agent loop is justified by a path that genuinely can't be known in advance.\n- Every loop has explicit, enumerated stop conditions — no \"until done\".\n- Each tool states its side-effect class, idempotency, and confirmation requirement, and fails with a structured error result.\n- Context growth is bounded (summarize\u002Fretrieve), with a stated token budget.\n- Tool output is treated as untrusted; privileges are scoped so injection can't escalate.\n- Evaluation covers trajectories, not only final answers.\n",{"name":5,"description":7},"main","23f6e21841a39580c9da2b5ec941f39dda17cd86","plugins\u002Fpolymath-ai\u002Fskills\u002Fagent-design","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath","https:\u002F\u002Fgithub.com\u002FMohammadBafkar","2026-10-29 18:34:59",{"source":8,"skillName":5,"commands":31,"prompt":41,"zipAvailable":42},[32,35,38],{"tool":33,"command":34},"npx","npx skills add MohammadBafkar\u002Fpolymath --skill agent-design",{"tool":36,"command":37},"bunx","bunx skills add MohammadBafkar\u002Fpolymath --skill agent-design",{"tool":39,"command":40},"pnpm","pnpm dlx skills add MohammadBafkar\u002Fpolymath --skill agent-design","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-ai\u002Fskills\u002Fagent-design\u002FSKILL.md",true,[44],{"path":45,"resourceType":46,"resourceTypeDesc":47,"sizeBytes":48,"sourceHtmlUrl":49},"routing.yaml","REFERENCE","参考文档",454,"https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-ai\u002Fskills\u002Fagent-design\u002Frouting.yaml",[51,58,65,72,79,86],{"skillNo":52,"name":53,"nameZh":6,"description":54,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":55,"categories":56,"keywords":57,"publishedAt":19},"01M74GN87EBRHM9N87M7AP1HDD","runbook","Write or refresh an operational runbook for an alert\u002Fsymptom; structured as TL;DR + Pre-checks + Steps + Verification + Rollback + Escalation.","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Frunbook\u002FSKILL.md",[],[],{"skillNo":59,"name":60,"nameZh":6,"description":61,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":62,"categories":63,"keywords":64,"publishedAt":19},"01M74GN5GPKEC1JEKP2DFQNEQJ","rfc","Draft a lightweight design RFC to docs\u002Frfcs\u002F\u003Cslug>.md; Summary, Motivation, Detailed design, Drawbacks, Alternatives, Unresolved questions. A proposal to debate, not a recorded decision (adr).","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Frfc\u002FSKILL.md",[],[],{"skillNo":66,"name":67,"nameZh":6,"description":68,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":69,"categories":70,"keywords":71,"publishedAt":19},"01M74GN2F4CWPMV4X09TG4E304","editorial-pass","Review and tighten prose in a Markdown artifact for a target tone (terse, formal, friendly) without dropping information; preserve quotations and load-bearing constraints.","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Feditorial-pass\u002FSKILL.md",[],[],{"skillNo":73,"name":74,"nameZh":6,"description":75,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":76,"categories":77,"keywords":78,"publishedAt":19},"01M74GMZWGYMZ37C4DYGT6P23G","architecture-review-facilitation","Run an architecture review as a process — entry criteria, reviewer checklist, decision log, and follow-up actions — pairing the design artifact with a red-team pass.","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Farchitecture-review-facilitation\u002FSKILL.md",[],[],{"skillNo":80,"name":81,"nameZh":6,"description":82,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":83,"categories":84,"keywords":85,"publishedAt":19},"01M74GMXVX0YX3ETDXS527XDGM","architecture-doc","Write a C4-style architecture document; System Context + Containers (+ Components when interesting) with mermaid diagrams. Describes structure, not a decision (adr) or proposal (rfc).","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Farchitecture-doc\u002FSKILL.md",[],[],{"skillNo":87,"name":88,"nameZh":6,"description":89,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":90,"categories":91,"keywords":92,"publishedAt":19},"01M74GMVG1WSMCK066S3KE6V5K","adr","Write an Architecture Decision Record (Michael Nygard format) to docs\u002Fadrs\u002FNNNN-\u003Cslug>.md; frontmatter validated by the ADR artifact schema. Records a made decision, not a proposal to debate (rfc).","https:\u002F\u002Fgithub.com\u002FMohammadBafkar\u002Fpolymath\u002Fblob\u002Fmain\u002Fplugins\u002Fpolymath-writing\u002Fskills\u002Fadr\u002FSKILL.md",[],[]]