feat(core): transition sub-agents to XML format and improve definitions (#18555)

This commit is contained in:
N. Taylor Mullen
2026-02-08 18:25:04 -08:00
committed by GitHub
parent 375c104b32
commit cb73fbf384
10 changed files with 638 additions and 116 deletions

View File

@@ -19,6 +19,7 @@ describe('GeneralistAgent', () => {
vi.spyOn(config, 'getAgentRegistry').mockReturnValue({
getDirectoryContext: () => 'mock directory context',
getAllAgentNames: () => ['agent-tool'],
getAllDefinitions: () => [],
} as unknown as AgentRegistry);
const agent = GeneralistAgent(config);

View File

@@ -1104,28 +1104,4 @@ describe('AgentRegistry', () => {
expect(getterCalled).toBe(true); // Getter should have been called now
});
});
describe('getDirectoryContext', () => {
it('should return default message when no agents are registered', () => {
expect(registry.getDirectoryContext()).toContain(
'No sub-agents are currently available.',
);
});
it('should return formatted list of agents when agents are available', async () => {
await registry.testRegisterAgent(MOCK_AGENT_V1);
await registry.testRegisterAgent({
...MOCK_AGENT_V2,
name: 'AnotherAgent',
description: 'Another agent description',
});
const description = registry.getDirectoryContext();
expect(description).toContain('Sub-agents are specialized expert agents');
expect(description).toContain('Available Sub-Agents');
expect(description).toContain(`- ${MOCK_AGENT_V1.name}`);
expect(description).toContain(`- AnotherAgent`);
});
});
});

View File

@@ -481,37 +481,4 @@ export class AgentRegistry {
getDiscoveredDefinition(name: string): AgentDefinition | undefined {
return this.allDefinitions.get(name);
}
/**
* Generates a markdown "Phone Book" of available agents and their schemas.
* This MUST be injected into the System Prompt of the parent agent.
*/
getDirectoryContext(): string {
if (this.agents.size === 0) {
return 'No sub-agents are currently available.';
}
let context = '## Available Sub-Agents\n';
context += `Sub-agents are specialized expert agents that you can use to assist you in
the completion of all or part of a task.
Each sub-agent is available as a tool of the same name.
You MUST always delegate tasks to the sub-agent with the
relevant expertise, if one is available.
The following tools can be used to start sub-agents:\n\n`;
for (const [name] of this.agents) {
context += `- ${name}\n`;
}
context += `Remember that the closest relevant sub-agent should still be used even if its expertise is broader than the given task.
For example:
- A license-agent -> Should be used for a range of tasks, including reading, validating, and updating licenses and headers.
- A test-fixing-agent -> Should be used both for fixing tests as well as investigating test failures.`;
return context;
}
}