Skip to content

Agent definition — Reference ​

See Source-generated tool map and embedded/downloadable agent definitions for the shared visual model.

Terse reference for agent definition generation & per-project materialization: how the GitHub Copilot agent file .github/agents/agentweaver.agent.md is generated from the MCP tool source, embedded into the API, and written into every new project.

No HTTP API. This feature adds no new routes, DTOs, or config keys. It is a build-time generator plus a creation-time side effect inside ProjectService. The only "interface" is the gen-docs.mjs CLI and the materialized file on disk.

Generated files ​

One generator, scripts/gen-docs.mjs, produces five targets from the single source of truth apps/Agentweaver.Mcp/Tools/*.cs (the [McpServerTool] / [Description] attributes):

TargetWhat is generatedSource of truth
docs/reference/mcp-tools.mdThe full MCP tool index (every tool + one-line description).apps/Agentweaver.Mcp/Tools/*.cs
.github/agents/agentweaver.agent.mdOnly the Tool map block between the markers (see below). All other prose is hand-written and preserved.Same — Tool map only
apps/Agentweaver.Api/Projects/Templates/agentweaver.agent.mdA byte-identical copy of the agent file above, embedded into the API.The agent file above
docs/public/agents/agentweaver.agent.mdByte-identical anonymous docs download.Generated agent definition
apps/Agentweaver.Web/wwwroot/agents/agentweaver.agent.mdByte-identical same-origin deployment download.Generated agent definition

The marker block ​

Inside .github/agents/agentweaver.agent.md, the generated region is delimited exactly by:

<!-- BEGIN GENERATED:tool-map -->
... generated Tool map grouped by category ...
<!-- END GENERATED:tool-map -->

The generator replaces only the bytes between these markers (applyToolMapBlock in scripts/gen-docs.mjs) and reads the rest of the file back as the template, so frontmatter, mental model, operating principles, and playbooks stay verbatim. Editing the file outside the markers is safe; editing inside them is overwritten on the next regenerate.

Regenerate ​

bash
node scripts/gen-docs.mjs          # rewrite all five generated targets
node scripts/gen-docs.mjs --check  # exit 1 if any committed target is stale (CI)

The script is dependency-free Node (no npm install). Run it after adding, renaming, or re-describing any MCP tool, then commit the changed files.

CI gate ​

The docs-drift workflow runs the generator in --check mode on every pull request. --check re-derives all five targets and compares them to what is committed; a stale file prints DRIFT: ... and the job exits non-zero (.github/workflows/docs-drift.yml:37). This makes a drifted agent file a hard build failure rather than a silent inconsistency.

OK: docs/reference/mcp-tools.md is in sync.
OK: .github/agents/agentweaver.agent.md is in sync.
OK: apps/Agentweaver.Api/Projects/Templates/agentweaver.agent.md is in sync.
OK: docs/public/agents/agentweaver.agent.md is in sync.
OK: apps/Agentweaver.Web/wwwroot/agents/agentweaver.agent.md is in sync.

Materialization behavior ​

On project creation, ProjectService.TryMaterializeAgentDefinition writes the embedded template into the new project. It is called from both CreateBlankAsync (ProjectService.cs:90) and CreateFromGitHubAsync (ProjectService.cs:183).

PropertyBehavior
Destination{project.WorkingDirectory}/.github/agents/agentweaver.agent.md (AgentDefinitionTemplate.RelativeFilePath).
ContentThe embedded EmbeddedResource template, byte-identical to the committed .github file.
Idempotent / non-clobberingSkips the write and returns false when the file already exists — user edits and repo-shipped agent files are never overwritten (AgentDefinitionTemplate.cs:56).
Directory creationCreates the .github/agents/ directories as needed.
Best-effortCatches IOException / UnauthorizedAccessException / SecurityException, logs a warning, and returns; never fails project creation (AgentDefinitionTemplate.cs:63).
Both create pathsApplies to blank projects and GitHub-cloned projects alike.

Where the file lands in a project ​

{project working directory}/
└── .github/
    └── agents/
        └── agentweaver.agent.md   ← materialized here, once, if absent

GitHub Copilot discovers agent files under .github/agents/, so the materialized file becomes a selectable agent ("Agentweaver Driver") for that project with no further setup.

Tests ​

GuardTest
Embedded template == committed .github fileAgentDefinitionTemplateTests.EmbeddedTemplate_MatchesCommittedRepoFile
TryMaterialize writes the fileAgentDefinitionTemplateTests.TryMaterialize_WritesFileIntoProjectDir
Idempotent + non-clobberingAgentDefinitionTemplateTests.TryMaterialize_IsIdempotent_AndDoesNotClobberUserEdits
New project contains the fileProjectServiceCreateTests (PC-11)

See also ​

Diagram details and constraints
ElementContract
titleAgent definition · five generated targets
takeawayOne tool map is regenerated; handwritten prose stays intact and all five outputs are checked.
group-0-titleGENERATOR INPUTS
group-1-titleOUTPUTS + MATERIALIZATION
MCP tool sourcesMCP tool sources
MCP tool sourcesParse and group tool declarations
MCP tool sourcesHandwritten agent template supplies prose
MCP tool sourcesgen-docs.mjs:243–273
scripts/gen-docs.mjsscripts/gen-docs.mjs
scripts/gen-docs.mjsReplace only the tool-map block
scripts/gen-docs.mjs--check compares expected bytes for all five
scripts/gen-docs.mjsgen-docs.mjs:266–300
Tool referenceTool reference
Tool referencedocs/reference/mcp-tools.md
Tool referenceGenerated public tool index
Tool referencegen-docs.mjs:266–273
Repository agentRepository agent
Repository agent.github/agents/agentweaver.agent.md
Repository agentHandwritten text + generated map
Embedded API templateEmbedded API template
Embedded API templateProjects/Templates/agentweaver.agent.md
Embedded API templateEmbedded resource for project initialization
Documentation downloadDocumentation download
Documentation downloaddocs/public/agents/agentweaver.agent.md
Documentation downloadPublished agent-definition download
Web-host downloadWeb-host download
Web-host downloadwwwroot/agents/agentweaver.agent.md
Web-host downloadDeployed static copy; anonymous consumer
New project agent fileNew project agent file
New project agent fileAgentDefinitionTemplate
New project agent fileBest effort; detected existing files are preserved
New project agent fileAgentDefinitionTemplate:33–75
MCP tool sourcescompose
scripts/gen-docs.mjswrite
scopeFive outputs are siblings, not a copy chain. Only the embedded API copy materializes new project files.
groupsGENERATOR INPUTS; OUTPUTS + MATERIALIZATION