Skip to content

Garry's Opinionated OpenClaw/Hermes Agent Brain

TypeScript

feat(mcp): instructions start an account, person or company brief with entity

garrytan51f865d78f75
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 932d041e95..df60525c2a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -84,6 +84,7 @@ Over MCP, the `entity` card adds `referenced_by`, `referenced_by_count` and `cov
- **Schema**: migration v201 adds `page_aliases.origin`, `case_sensitive` and `alias_text` (unique key widened to include `origin`) and the `page_mention_state`, `mention_gazetteer_entries` and `mention_index_status` tables. No existing row is rewritten.
- **Config**: `mentions.auto_link` (default on), `mentions.entity_types`, `mentions.ignore`.
- **Faster private-page filtering for remote callers** (`src/core/search/private-visibility.ts`): the declared-lineage check runs only for pages that carry `derived_from`, so remote reads no longer probe the source's private pages once per candidate row. Results are unchanged.
+- **Server instructions**: wherever `entity` is served, the initialize instructions say: for a brief on an account, person or company, call `entity`, then walk `referenced_by` (or `get_backlinks`, where served) by type. The sentence replaces "several names" guidance on those surfaces; the full contract is 4,607 characters (ceiling 4,628).
- **Tool descriptions**: `entity` and `get_backlinks` describe the new fields within the unchanged schema ceilings; `query` and `search` descriptions are shorter to pay for it.
### For contributors
diff --git a/docs/guides/entity-recall.md b/docs/guides/entity-recall.md
index 4227c9e704..b35f843ceb 100644
--- a/docs/guides/entity-recall.md
+++ b/docs/guides/entity-recall.md
@@ -6,7 +6,9 @@ Example"), by a frontmatter alias, or by a code the page declares (`Account
code: ACMX`). The `entity` card then lists those pages grouped by type, newest
first, with a short preview, and `get_backlinks` pages through the rest. An
agent briefing on an account sees all of its tickets, meetings and mail
-instead of whichever few a search ranks first.
+instead of whichever few a search ranks first. The MCP initialize
+instructions tell agents to start such a brief with `entity` and walk
+`referenced_by` (or `get_backlinks`, where it is served) by type.
**Say to your agent:** *"brief me on the Acme Example account"* —
*"list every open ticket for ACMX"* — *"why isn't this meeting linked to Acme?"*
diff --git a/src/mcp/instructions.ts b/src/mcp/instructions.ts
index 5d01f0a5fb..06c0996877 100644
--- a/src/mcp/instructions.ts
+++ b/src/mcp/instructions.ts
@@ -44,9 +44,12 @@ function contractClauses(c: CallablePredicate): string[] {
} else {
out.push(`Treat gbrain as the user's shared memory.${c('recall') ? ' Use `recall` before external lookup.' : ''} Preserve the current agent's identity and unrelated instructions.`);
}
+ // Entity recall: a brief starts from the entity card's referrers, wherever `entity` is served.
+ const brief = c('entity') ? `For a brief on an account, person or company, call \`entity\`, then walk \`referenced_by\`${c('get_backlinks') ? ' or `get_backlinks`' : ''} by type.` : null;
+ if (brief && !any('search', 'query')) out.push(brief);
if (any('search', 'query')) {
// Cat 40 (#5932): measured answer-completeness guidance; keep its wording.
- out.push(`Answering from the brain: a search returns the best-ranked excerpts, not every relevant page, so keep going until the evidence is complete. Run separate searches for separate parts of a question. People and companies appear under several names (abbreviations, codes, nicknames); when a page lists another name, search for that too. For what is true now, prefer the newest governing source: a later correction, handoff or executed change outranks an older record, and drafts, proposals and agent-written notes do not override records.${c('recall') ? ` Facts saved with remember are read back with recall${c('entity') ? ' (or entity)' : ''}, not search.` : ''}`);
+ out.push(`Answering from the brain: a search returns the best-ranked excerpts, not every relevant page, so keep going until the evidence is complete. Run separate searches for separate parts of a question. ${brief ?? 'People and companies appear under several names (abbreviations, codes, nicknames); when a page lists another name, search for that too.'} For what is true now, prefer the newest governing source: a later correction, handoff or executed change outranks an older record, and drafts, proposals and agent-written notes do not override records.${c('recall') ? ` Facts saved with remember are read back with recall${c('entity') ? ' (or entity)' : ''}, not search.` : ''}`);
}
if (c('list_skills') && c('get_skill')) {
out.push(`When the task calls for a procedure or workflow, discover available skills with list_skills using schema_version:2 when supported. Match descriptions and frontmatter triggers to the task, then read the matching skill in full with get_skill using its qualified_id, revision and schema_version:2.${c('get_skill_asset') ? ' Load approved dependencies from that exact revision with get_skill_asset.' : ''} If an older server explicitly rejects version 2, use its documented legacy discovery; an unavailable catalog is not empty.`);
diff --git a/test/mcp-initialize-instructions.test.ts b/test/mcp-initialize-instructions.test.ts
index 3be1045087..509dea3930 100644
--- a/test/mcp-initialize-instructions.test.ts
+++ b/test/mcp-initialize-instructions.test.ts
@@ -63,6 +63,29 @@ describe('F1 generated instructions', () => {
expect(GBRAIN_MCP_INSTRUCTIONS).toContain('call `volunteer_context` when the conversation shifts topic');
});
+ test('entity recall brief: on every surface serving entity; get_backlinks named only where callable', () => {
+ const brief = 'For a brief on an account, person or company, call `entity`, then walk `referenced_by`';
+ for (const surface of SURFACES) {
+ const listed = new Set(filterOpsForSurface(operations, surface).map(o => o.name));
+ const text = buildMcpInstructions({ tools: { callable: n => listed.has(n) } });
+ expect({ surface, brief: text.includes(brief) }).toEqual({ surface, brief: listed.has('entity') });
+ expect({ surface, backlinks: text.includes('or `get_backlinks` by type.') }).toEqual({ surface, backlinks: listed.has('entity') && listed.has('get_backlinks') });
+ expect(text).not.toContain('appear under several names');
+ }
+ const noEntity = buildMcpInstructions({ tools: { callable: n => n !== 'entity' } });
+ expect(noEntity).not.toContain(brief);
+ expect(noEntity).toContain('People and companies appear under several names');
+ });
+
+ test('recorded tail-free instruction sizes per surface', () => {
+ const recorded = { verbs: 2_243, starter: 4_546, full: 4_607 };
+ for (const surface of SURFACES) {
+ const listed = new Set(filterOpsForSurface(operations, surface).map(o => o.name));
+ const size = buildMcpInstructions({ tools: { callable: n => listed.has(n) } }).length;
+ expect({ surface, fits: size <= recorded[surface] }).toEqual({ surface, fits: true });
+ }
+ });
+
test('readiness tail: top two gaps only, never a by-choice state; budget holds', () => {
const e = (capability: ReadinessEntry['capability'], state: ReadinessEntry['state'], why: string): ReadinessEntry =>
({ capability, state, reason: 'x', why, tier: 'config', http_visible: true });