> For the complete documentation index, see [llms.txt](https://doc.wearepatchworks.com/product-documentation/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/creating-a-script-with-ai.md).

# Creating a script with AI

### Introduction

You don't have to write scripts yourself. The `build & test` page includes an integrated AI **script assistant** — toggle into `AI` mode, describe what you need in plain language, and a draft script is generated for you:

<div data-with-frame="true"><figure><img src="https://2440044887-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLYNcUBVQwSkOMG6KjZfz%2Fuploads%2FMWYRMTQWSSmlx4K7nYLU%2FScreen%203%20-%20building%20with%20AI.png?alt=media&amp;token=4371069f-4d26-4671-b01d-95a65287503f" alt=""><figcaption></figcaption></figure></div>

The script assistant knows about expected inputs and value types (payload, metadata, variables and flow variables), together with your chosen [script type](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting#script-types) and language — so generated scripts are in a form that's ready to test and use.

{% hint style="info" %}
Scripts can also be created without visiting the script editor at all — see using the implementation agent below.
{% endhint %}

### Need to know

* AI requests draw on the allowance for your company profile — see [subscription tier limits](https://doc.wearepatchworks.com/product-documentation/getting-started/subscription-tier-limits). You can review usage and past requests from your [AI conversation history](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/creating-a-script-with-ai/ai-conversation-history).
* The clearer and more specific your prompt, the better the result. Where possible, include a sample payload — use the attach option in the message box to provide one.

### Using the script assistant

Follow the steps below:

**Step 1**\
[Create your script](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts) as usual, then — on the `build & test` page — select `AI` to open the `build with AI` panel.

**Step 2**\
Enter your prompt, being as clear and specific as possible — for example:

`Create a script to take a XML payload and convert to JSON`

**Step 3**\
The script assistant replies with a summary of its approach and a generated draft script, which you can review in the panel. The draft is created as a version of your script, so it's immediately available in the editor and can be [run against your own test inputs](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/testing-scripts) straight away.

**Step 4**\
Refine the script as needed — you can:

* **Continue the conversation** — describe a change in the message box (e.g. `also uppercase the SKU`) and the assistant updates the script.
* **Edit by hand** — switch to `manual` mode at any time to fine-tune the generated code yourself, then switch back to `AI` if you want more help.
* **Start again** — click `+ new` to begin a fresh conversation.

**Step 5**\
When you're happy with the draft, save it — then [test](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/testing-scripts) and [deploy](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/deploying-scripts-and-managing-versions) as usual.

{% hint style="warning" %}
Always [test](https://doc.wearepatchworks.com/product-documentation/developer-hub/custom-scripting/creating-and-testing-custom-scripts/testing-scripts) AI-generated scripts to ensure that the results are as expected.
{% endhint %}

### Using the implementation agent

The script assistant is built into the script editor, but it isn't the only way to build scripts with AI. The [implementation agent](https://doc.wearepatchworks.com/product-documentation/ai/patchworks-ai-studio/platform-agents/implementation-agent) can create and update custom scripts conversationally — particularly useful when a script is just one part of a wider piece of work, such as building out a process flow.
