Skip to main content

Custom AI agents

Assign tasks to any custom agent that you can access through an API

Updated yesterday

One powerful use case of AI agents in Dart is creating a custom agent to connect to any other service you use or build.

Custom agent setup example

One way to set up an agent is to use a service like n8n to handle sending data from Dart (such as the title and description of a task that you assigned to the agent) into the 3rd party agent. You can then take the deliverables and send them back into Dart for retrieval. There are many possible ways you can set this up.

In the following example, we will show how you can use Dart custom agents and n8n to integrate with Magic Patterns and build a personal design agent that can quickly generate prototypes of websites, frontends, or UIs.

magic patterns n8n workflow

Note that this is just an example of how to use the custom agents because Dart now has a built-in integrated Magic Patterns design agent that can be accessed much more easily instead.

Setup video

Watch the following video to see step-by-step instructions on setting up the Magic Patterns AI agent with n8n in Dart:

Step-by-step instructions

  1. First have accounts created on n8n and Magic Patterns

  2. Create an example task in Dart to use for testing

  3. Create a webhook node in n8n

    1. Copy the Test URL

    2. Set the HTTP Method to POST

  4. Create an agent in Dart

    1. Name it and upload a profile picture as desired

    2. Click add workflow and paste in the URL in the To field. Leave When as "a task is assigned to your agent" and Then as "send a POST request"

    3. Use Header: Content-Type and Value: application/json

    4. Use Body: {{data}}

  5. In n8n click "Listen for test event", and then in Dart assign the example task to your new agent

    1. Check that data appears in the output panel in n8n

    2. Click the pin button in the top right corner to keep the data for further steps

  6. Create the design node:

    1. Connect the Webhook node to an HTTP Request node. Use the following:

    2. Method: POST

    3. Authentication: Generic Credential Type

    4. Generic Auth Type: Header Auth

    5. Header Auth: Create new credential

      1. Rename the Header Auth to something like "MP new auth"

      2. Name: x-mp-api-key (from the Magic Patterns API docs)

      3. Value: API key you get from Profile Settings in Magic Patterns

      4. Click to save the new credential

    6. Send Body: toggle on

    7. Body Content Type: Form-Data

    8. Parameter Type: Form Data

    9. Name: prompt

    10. Value: {{ $json.body.task.title }}{{ $json.body.task.description }} (or drag in the task id and description from the schema menu on the left)

    11. test the step to ensure it works

  7. Create the comment finished node

    1. Make another HTTP Request node and attach it after the design node

      1. Name it "Comment finished"

    2. Method: POST

    3. URL: Create comment (This is taken from Dart's API documentation.)

    4. Authentication: Generic Credential Type

    5. Generic Auth Type: Header Auth

    6. Header Auth: Create new credential

      1. Rename the Header Auth to something like "Dart new auth"

      2. Name: Authorization

      3. Value: "bearer " (with a space) followed by the authentication token from your new agent in Dart.

        1. To get the authentication token, in Dart go to settings -> Agents -> click the three dots next to your new agent -> Authentication Token -> Create

        2. It should look something like: bearer dsa_a8ps82...

      4. Click to save the new credential

    7. Send Body: toggle on

    8. Body Content Type: JSON

    9. Specify Body: Using JSON

    10. JSON: grab the task ID from the webhook node and the previewURL from the design node and use them in the following

    11. {
      "item": {
      "taskId": "{{ $('Webhook').item.json.body.task.id }}",
      "text": "Done, [check out the designs here]({{ $json.previewUrl }})!"
      }
      }
    12. Test the step

  8. Create a comment starting node:

    1. Duplicate the existing comment finished node and attach it to the webhook node from the beginning

    2. Rename the node as desired

    3. Use a slightly different message for the JSON, dragging in the task ID:

    4. {
      "item": {
      "taskId": "{{ $json.body.task.id }}",
      "text": "I'm on it!"
      }
      }
    5. Test the step

  9. Save the n8n workflow and mark it as active

  10. Copy the production URL from the Webhook node (instead of the Test URL) and paste it into the Dart agent workflow in the "To" field.

If you have any questions on setting up your own custom agent, feel free to email us at [email protected]

More agent workflows

Here is another example of a custom agent workflow in n8n that uses a webhook to get data into Predis for generating a marketing post. Predis can leave a comment in Dart that the work has begun and send the marketing post draft into a Redis database. Then when it's completed, Predis can put the data into a comment in Dart that links to the finished post. This type of workflow employing databases can be helpful when multiple different requests come in around the same time, before the first work is even finished.

custom agent workflow

If you have questions or ideas on how to set up other AI agents, let us know at [email protected].

Did this answer your question?