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.
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
First have accounts created on n8n and Magic Patterns
Create an example task in Dart to use for testing
Create a webhook node in n8n
Copy the Test URL
Set the HTTP Method to POST
Create an agent in Dart
Name it and upload a profile picture as desired
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"
Use Header:
Content-Type
and Value:application/json
Use Body:
{{data}}
In n8n click "Listen for test event", and then in Dart assign the example task to your new agent
Check that data appears in the output panel in n8n
Click the pin button in the top right corner to keep the data for further steps
Create the design node:
Connect the Webhook node to an HTTP Request node. Use the following:
Method: POST
URL: https://api.magicpatterns.com/api/v2/pattern (This is taken from the Magic Patterns API documentation.)
Authentication: Generic Credential Type
Generic Auth Type: Header Auth
Header Auth: Create new credential
Rename the Header Auth to something like "MP new auth"
Name: x-mp-api-key (from the Magic Patterns API docs)
Value: API key you get from Profile Settings in Magic Patterns
Click to save the new credential
Send Body: toggle on
Body Content Type: Form-Data
Parameter Type: Form Data
Name: prompt
Value:
{{ $json.body.task.title }}{{ $json.body.task.description }}
(or drag in the task id and description from the schema menu on the left)test the step to ensure it works
Create the comment finished node
Make another HTTP Request node and attach it after the design node
Name it "Comment finished"
Method: POST
URL: Create comment (This is taken from Dart's API documentation.)
Authentication: Generic Credential Type
Generic Auth Type: Header Auth
Header Auth: Create new credential
Rename the Header Auth to something like "Dart new auth"
Name: Authorization
Value: "bearer " (with a space) followed by the authentication token from your new agent in Dart.
To get the authentication token, in Dart go to settings -> Agents -> click the three dots next to your new agent -> Authentication Token -> Create
It should look something like:
bearer dsa_a8ps82...
Click to save the new credential
Send Body: toggle on
Body Content Type: JSON
Specify Body: Using JSON
JSON: grab the task ID from the webhook node and the previewURL from the design node and use them in the following
{
"item": {
"taskId": "{{ $('Webhook').item.json.body.task.id }}",
"text": "Done, [check out the designs here]({{ $json.previewUrl }})!"
}
}Test the step
Create a comment starting node:
Duplicate the existing comment finished node and attach it to the webhook node from the beginning
Rename the node as desired
Use a slightly different message for the JSON, dragging in the task ID:
{
"item": {
"taskId": "{{ $json.body.task.id }}",
"text": "I'm on it!"
}
}Test the step
Save the n8n workflow and mark it as active
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.
If you have questions or ideas on how to set up other AI agents, let us know at [email protected].