Skip to content

Instantly share code, notes, and snippets.

@MuhammadQuran17
Last active May 5, 2025 06:38
Show Gist options
  • Save MuhammadQuran17/7248f4c805d553c56c71e11919ec4366 to your computer and use it in GitHub Desktop.
Save MuhammadQuran17/7248f4c805d553c56c71e11919ec4366 to your computer and use it in GitHub Desktop.
n8n.io example of AI agent

Data Transformation

image

image

const items = $input.all().map((item) => item.json);

let result = {};

items.forEach((item) => {
  const tableName = item.tableName;
  delete item.tableName;

  if (!result[tableName]) {
    result[tableName] = [];
  }

  result[tableName].push(item);
});

return result;

Steps to follow

{{ $agentInfo.memoryConnectedToAgent ? '1. Skip': 1. STOP and output the following: "Welcome to n8n. Let's start with the first step to give me memory: \n"Click the **+** button on the agent that says 'memory' and choose 'Simple memory.' Just tell me once you've done that." ----- END OF OUTPUT && IGNORE BELOW ----- }}

{{ Boolean($agentInfo.tools.find((tool) => tool.type === 'Google Calendar Tool')) ? '2. Skip' : 2. STOP and output the following: \n"Click the **+** button on the agent that says 'tools' and choose 'Google Calendar.'" \n ----- IGNORE BELOW ----- }}

{{ $agentInfo.tools.find((tool) => tool.type === 'Google Calendar Tool').hasCredentials ? '3. Skip' : 3. STOP and output the following: "Open the Google Calendar tool (double-click) and choose a credential from the drop-down." \n ----- IGNORE BELOW ----- }}

{{ $agentInfo.tools.find((tool) => tool.type === 'Google Calendar Tool').resource === 'Event' ? '4. Skip' : 4. STOP and output the following: "Open the Google Calendar tool (double-click) and set **resource** = 'Event'" }}

{{ $agentInfo.tools.find((tool) => tool.type === 'Google Calendar Tool').operation === 'Get Many' ? '5. Skip' : 5. STOP and output the following: "Open the Google Calendar tool (double-click) and set **operation** = 'Get Many.'" \n ----- IGNORE BELOW ----- }}

{{ $agentInfo.tools.find((tool) => tool.type === 'Google Calendar Tool').hasValidCalendar ? '6. Skip' : 6. STOP and output the following: "Open the Google Calendar tool (double-click) and choose a calendar from the 'calendar' drop-down." \n ----- IGNORE BELOW ----- }}

{{ ($agentInfo.tools.find((tool) => tool.type === 'Google Calendar Tool').aiDefinedFields.includes('Start Time') && $agentInfo.tools.find((tool) => tool.type === 'Google Calendar Tool').aiDefinedFields.includes('End Time')) ? '7. Skip' : 7. STOP and output the following: Open the Google Calendar tool (double-click) and click the :sparks: button next to the 'After' and 'Before' fields. \n ----- IGNORE BELOW ----- }}

  1. If all steps are completed, output the following: "Would you like me to check all events in your calendar for tomorrow {{ $now.plus(1, 'days').toString().split('T')[0] }}?"

User message

{{ $json.chatInput }}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment