TABLE OF CONTENTS
Overview
Agent instructions allow you to explicitly control your agent's behavior on every interaction, guiding it as it searches and synthesizes information. You add instructions as plain-text directives to a simple text file, then direct your agent to consult the instructions for every command.
Agent instructions can encourage your agent to query Stack Internal Community proactively. With instructions, the agent can take implicit actions: searching before answering, upvoting content you use, flagging open questions, drafting new questions when it finds a gap, and more. This helps developers find and contribute knowledge with less repeated prompting.
Agent instructions template
Below is an agent instructions template you can adapt for clients that support persistent instructions and the required MCP tools. Where you'll place this template depends on the IDE or agent you're using.
Before adding these instructions, connect your supported client to the Stack Internal Community MCP server, sign in, and verify that search works. Available tools depend on your deployment and permissions. Merge the template into your client's existing instructions, enable or reload them as required, and verify that the client has loaded them. Administrators can refer to the MCP configuration guide.
| IDE or agent | Agent instructions file location |
|---|---|
| Cursor | .cursor/rules/*.mdc in your project root (select Always Apply); .cursorrules is legacy |
| VS Code + GitHub Copilot | .github/copilot-instructions.md |
| Claude Code | CLAUDE.md in your project root |
| Codex | AGENTS.md in your project root, or ~/.codex/AGENTS.md for global instructions |
| Custom agents | System prompt or instruction file |
The agent instructions below are a starting point. Customize them for your team, especially the automatic behaviors. Pay close attention to the implicit actions listed below (auto-upvoting, gap detection, divergence detection). You'll want to remove ones that don't fit your workflow, and add additional actions specific to your application. The more closely you align the instructions to your specific workflow, the more value they'll bring.
Agent instruction examples
- A team that uses Stack Internal Community articles to track decisions could add: "When the user makes an architectural decision, offer to create a Stack Internal Community article documenting the rationale".
- Domain-specific search rules "When working in the payments module, always search Stack Internal Community for PCI compliance patterns before implementing".
- Adjust implicit actions "When search yields no results, do not draft a question. Instead, flag the gap and let the user decide whether to post".
- Draft answers for common questions "For questions tagged 'faq', draft an answer using approved content and ask me to review it before posting".
- Find a subject matter expert "If a search does not produce a reliable answer, call
get_existing_tagsto find the relevant existing tag, then pass its numeric tag ID to recommend_SME to identify an expert, and offer to draft a question for my review". - Triage unanswered questions "When I work on a topic, use
get_questions_to_answerto find related questions without an accepted answer. Fetch each candidate withget_questionand review its existing answers before offering to draft an answer grounded in Stack Internal Community content for my review". - Check context before editing "If a question or answer appears outdated, use
get_commentswith the question ID and, for answer comments, the answer ID to read its comments before recommending a change". - Maintain questions I can edit "When a question I authored has an outdated title, body, or tags, fetch the current question with
get_question, preserve any fields that are not changing, and propose anupdate_questionedit for my approval before applying it". - Distinguish the two MCP servers when both are connected "If both services are connected and distinguishable in my client, use the Stack Internal Community connection for Community requests and the Stack Internal connection for Stack Internal requests. Identify each connection by its configured server and available tools".
- Maintain published articles "If
update_articleis available, fetch an article I can edit withget_article, review its comments, and propose an update for my approval. Preserve the existing title, body, tags, and article type wherever they are unchanged". - Find less-common existing tags "If the connected server supports tag filters, use
get_existing_tagswithexactTagNamesorpartialNamewhen the relevant tag is missing from the default discovery results. Use only returned tags and never invent one".
The template below is deliberately broad. Narrow it to match your team's needs.
## Default behavior: use Stack Internal first
Whenever you encounter a question, ambiguity, TODO, or gap in the code, consult the Stack Internal MCP server before reasoning from general knowledge. Treat Stack Internal as the authoritative internal source.
Specifically:
- Before answering a technical question about standards, patterns, or policies, search Stack Internal Community first.
- Before implementing something that requires an internal convention, search Stack Internal Community first.
- When you encounter a TODO, open question, or ambiguity in the code, search Stack Internal Community before reasoning from general knowledge.
## Automatic behaviors (no user prompt required)
These fire whenever the trigger condition is met:
- Before creating any content, call get_existing_tags and only use tags from that result.
- Use get_question or get_article to read the full content before relying on a search result, and cite the posts used.
- When the user accepts Stack Internal Community content and implements it, upvote both the answer and question via vote to reinforce signal for future engineers.
- When search results contain an open question the agent can address, flag it inline and ask if the user can answer it.
- When search yields no relevant results, draft a question via draft_question and propose it to the user for review.
- When implementation diverges from an existing Stack Internal Community answer the user authored and can edit, detect the gap and propose an update via update_answer for approval.
- When code contains a TODO or unexplained gap, search Stack Internal Community before reasoning from general knowledge.
## What requires user confirmation
Before creating or updating content, show me the proposed text and obtain my confirmation. This applies to:
- create_question: new questions require deliberate authorship.
- create_QA / create_article: draft first, user approves before posting.
- submit_user_answer: posting on the user's behalf always requires confirmation.
- Downvoting any content: negative signals require user context.
- update_question / update_answer: show the proposed changes and confirm before applying them.
- update_article (if available): show the proposed changes and confirm before applying them.
## What NOT to do
- Do not answer standards or policy questions without searching Stack Internal Community first.
- Do not create content without calling get_existing_tags first.
- Do not post a new question if search reveals it already exists.
- Do not surface truncated results and wait. Fetch the full content automatically.