# Update Knowledge

Refresh a public agent's KNOWLEDGE.md from the current graph, scoped to that agent's knowledge configuration.

## When to Use

The admin asks to update, refresh, or regenerate a public agent's knowledge. Examples: "update the knowledge for the sales agent", "refresh the advisor's KNOWLEDGE.md", "rebuild knowledge for all public agents".

## Knowledge Scope

Each public agent's knowledge comes from two complementary sources, both configured in the agent's `config.json`:

**Direct tags** — graph nodes with the agent's slug in their `agents` array.

**Keyword subscriptions** — the agent's `knowledgeKeywords` array. Nodes matching these keywords are included regardless of whether they are directly tagged.

The union of both result sets (deduplicated) forms the agent's knowledge scope.

## Admin vs Runtime Search

This skill runs at admin time, not at runtime. All `memory-search` queries must use admin permissions — do NOT pass `agentSlug` as a parameter. The `agentSlug` parameter applies runtime enforcement logic (restricts graph traversal to tagged nodes only), which is appropriate for the public agent's MCP server but not for admin-time knowledge discovery.

To find directly-tagged nodes: search with the agent's role or topic as the query term (no `agentSlug`), then identify results where the `agents` property contains the target slug.

To find keyword matches: search with each keyword as the query term (no `agentSlug`). Keyword subscriptions exist to capture content beyond the directly-tagged set.

## Constraints

- If the agent has neither direct tags nor keyword subscriptions configured, there is nothing to refresh. Inform the admin: "This agent has no knowledge scope configured. Tag nodes for the agent or add keyword subscriptions in config.json first."
- If all queries return empty results, do NOT write an empty KNOWLEDGE.md. Warn the admin: "No matching content found for this agent's knowledge scope. KNOWLEDGE.md was not modified." Preserve any existing KNOWLEDGE.md.
- After writing KNOWLEDGE.md, check the context budget. If the total system prompt (IDENTITY.md + SOUL.md + plugins + KNOWLEDGE.md) exceeds 50% of the model's context window, auto-generate KNOWLEDGE-SUMMARY.md and present it via `document-editor` with `filePath: "agents/{slug}/KNOWLEDGE-SUMMARY.md"` for review.
- Present the generated KNOWLEDGE.md via `document-editor` with `filePath: "agents/{slug}/KNOWLEDGE.md"` for admin review before finalising.
- Log the refresh: write a note at the top of KNOWLEDGE.md with the refresh timestamp.

## Querying

Run `memory-search` multiple times with targeted queries to build comprehensive coverage. Do not pass `agentSlug` on any query — all searches use admin permissions.

1. Search with the agent's role or topic as the query term. In the results, identify nodes whose `agents` property contains the target agent's slug — these are the directly-tagged nodes.
2. For each keyword in the agent's `knowledgeKeywords`, search with that keyword as the query term. These capture content by topic regardless of tagging.
3. Merge all results, deduplicate by node content, and organise under clear markdown headings by topic.

Categories to cover (where relevant to the agent's role): services, pricing, FAQs, team, policies, products, location/hours, contact info. Skip categories where no matching content exists.

## Bulk Refresh

When asked to refresh all agents, iterate over each public agent directory under `agents/`, read its `config.json`, and run the refresh for each. Present a summary of results.
