feat(core): Expose $agentInfo variable for easy AI workflow (no-changelog) (#14445)

Co-authored-by: Mutasem Aldmour <mutasem@n8n.io>
This commit is contained in:
Charlie Kolb
2025-04-10 13:10:26 +02:00
committed by GitHub
parent d24b684a95
commit 3db47504a2
5 changed files with 466 additions and 18 deletions

View File

@@ -787,4 +787,52 @@ describe('WorkflowDataProxy', () => {
});
});
});
describe('$agentInfo', () => {
const fixture = loadFixture('agentInfo');
const proxy = getProxyFromFixture(fixture.workflow, fixture.run, 'AI Agent');
test('$agentInfo should return undefined for non-agent nodes', () => {
const nonAgentProxy = getProxyFromFixture(fixture.workflow, fixture.run, 'Calculator');
expect(nonAgentProxy.$agentInfo).toBeUndefined();
});
test('$agentInfo should return memoryConnectedToAgent as true if memory is connected', () => {
expect(proxy.$agentInfo.memoryConnectedToAgent).toBe(true);
});
test('$agentInfo should return memoryConnectedToAgent as false if no memory is connected', () => {
const noMemoryProxy = getProxyFromFixture(fixture.workflow, fixture.run, 'Another Agent');
expect(noMemoryProxy.$agentInfo.memoryConnectedToAgent).toBe(false);
});
test('$agentInfo.tools should include connected tools with correct details', () => {
const tools = proxy.$agentInfo.tools;
// don't show tool connected to other agent
expect(tools.length).toEqual(2);
expect(tools[0]).toMatchObject({
connected: true,
name: 'Google Calendar',
type: 'Google Calendar',
resource: 'Event',
operation: 'Create',
hasCredentials: false,
});
expect(tools[1]).toMatchObject({
connected: false,
name: 'Calculator',
type: 'Calculator',
resource: null,
operation: null,
hasCredentials: false,
});
});
test('$agentInfo.tools should correctly identify AI-defined fields', () => {
const tools = proxy.$agentInfo.tools;
expect(tools[0].name).toBe('Google Calendar');
expect(tools[0].aiDefinedFields.length).toBe(1);
expect(tools[0].aiDefinedFields).toEqual(['Start']);
});
});
});