Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions packages/core/src/agents/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,63 @@ describe('AgentRegistry', () => {
);
});

it('should merge user and agent description when registering a remote agent', async () => {
const remoteAgent: AgentDefinition = {
kind: 'remote',
name: 'RemoteAgentWithDescription',
description: 'User-provided description',
agentCardUrl: 'https://example.com/card',
inputConfig: { inputSchema: { type: 'object' } },
};

const mockAgentCard = {
name: 'RemoteAgentWithDescription',
description: 'Card-provided description',
};

vi.mocked(A2AClientManager.getInstance).mockReturnValue({
loadAgent: vi.fn().mockResolvedValue(mockAgentCard),
clearCache: vi.fn(),
} as unknown as A2AClientManager);

await registry.testRegisterAgent(remoteAgent);

const registered = registry.getDefinition('RemoteAgentWithDescription');
expect(registered?.description).toBe(
'User Description: User-provided description\nAgent Description: Card-provided description',
);
});

it('should handle empty user or agent descriptions during merging', async () => {
const remoteAgent: AgentDefinition = {
kind: 'remote',
name: 'RemoteAgentWithEmptyAgentDescription',
description: 'User-provided description',
agentCardUrl: 'https://example.com/card',
inputConfig: { inputSchema: { type: 'object' } },
};

const mockAgentCard = {
name: 'RemoteAgentWithEmptyAgentDescription',
description: '', // Empty agent description
};

vi.mocked(A2AClientManager.getInstance).mockReturnValue({
loadAgent: vi.fn().mockResolvedValue(mockAgentCard),
clearCache: vi.fn(),
} as unknown as A2AClientManager);

await registry.testRegisterAgent(remoteAgent);

const registered = registry.getDefinition(
'RemoteAgentWithEmptyAgentDescription',
);
// Should only contain user description
expect(registered?.description).toBe(
'User Description: User-provided description',
);
});

it('should handle special characters in agent names', async () => {
const specialAgent = {
...MOCK_AGENT_V1,
Expand Down
22 changes: 15 additions & 7 deletions packages/core/src/agents/registry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,22 @@ export class AgentRegistry {
definition.agentCardUrl,
authHandler,
);
if (agentCard.skills && agentCard.skills.length > 0) {
definition.description = agentCard.skills
.map(
(skill: { name: string; description: string }) =>
`${skill.name}: ${skill.description}`,
)
.join('\n');

const userDescription = definition.description;
const agentDescription = agentCard.description;
const descriptions: string[] = [];

if (userDescription?.trim()) {
descriptions.push(`User Description: ${userDescription.trim()}`);
}
if (agentDescription?.trim()) {
descriptions.push(`Agent Description: ${agentDescription.trim()}`);
}

if (descriptions.length > 0) {
definition.description = descriptions.join('\n');
}

if (this.config.getDebugMode()) {
debugLogger.log(
`[AgentRegistry] Registered remote agent '${definition.name}' with card: ${definition.agentCardUrl}`,
Expand Down
Loading