Layer LogoWAVS Docs
WAVS builders handbook

AI-powered component creation

The WAVS Foundry Template contains built-in AI rulefiles for creating "one-shot" components with minimal prompting in Cursor or Claude Code.

These rulefiles are an experimental feature and may not work as expected every time. Components created with AI should not be used in production without thorough review and testing.

LLM resources

For more information on AI tools and AI-accessible documentation, visit the LLM resources page.

Claude Code

Cursor

Using AI to create components

  1. Clone the WAVS Foundry Template and follow the system setup requirements in the README.
git clone https://github.com/Lay3rLabs/wavs-foundry-template.git
cd wavs-foundry-template
git checkout main
# Follow the system setup requirements in the README.
  1. Open Claude Code or Cursor in the root of the template.
claude
# or
cursor .
Sandboxed Claude Code

You can run a sandboxed instance of Claude Code in a Docker container that only has access to this project's files by running the following command from the root of the project:

npm run claude-code
# or with no restrictions (--dangerously-skip-permissions)
npm run claude-code:unrestricted
  1. Enter your prompt in the agent chat. You can use the following examples as a starting point, or you can create your own prompt.
Attaching rulefiles

If you are using cursor, always attach component-rules.mdc file to the chat with your prompt.

@component-rules.mdc <your prompt>

Prompt examples

These simple examples are provided to get you started.

API component

You can make a very simple prompt to create a component that can bring API responses verifiably onchain by including the API endpoint:

Let's make a component that takes the input of a zip code, queries the openbrewerydb,
and returns the breweries in the area.
@https://api.openbrewerydb.org/v1/breweries?by_postal=92101&per_page=3

Contract balance component

You can also make components that interact with the blockchain:

I want to build a new component that takes the input of a wallet address,
queries the usdt contract, and returns the balance of that address.

Verifiable AI component

Please make a component that takes a prompt as input, sends an api request to OpenAI,
and returns the response.
Use this api structure:
{
"seed": $SEED,
"model": "gpt-4o",
"messages": [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "<PROMPT>"}
]
}
My api key is WAVS_ENV_OPENAI_KEY in my .env file.

You'll need an OPENAI API account and key to use this prompt. The agent will include your API key in the component as a private variable.

Make sure to include your API key in a .env file:

# copy the .env.example file
cp .env.example .env
# place your key in .env (must be prefixed with WAVS_ENV_)
WAVS_ENV_OPENAI_KEY=your_api_key

This example utilizes the OpenAI API with a seed to make the response more deterministic. Please note that OpenAI models are not guaranteed to be 100% deterministic. This example is for demonstration purposes and should not be used in production.

Component creation process

  1. After receiving the prompt, the agent will start creating your component. Review the agent's work and accept changes carefully. Make sure to double check what the agent is doing and be safe about accepting changes.

  2. The agent will start by planning its component and will create a plan.md file. The agent will then make a new component and files according to this plan.

  3. The agent will test its component for errors by running validation tests using make validate-component COMPONENT=your-component.

  4. The agent may need to make changes after running the Validation tests. After making changes, the agent will build the component using WASI_BUILD_DIR=components/my-component make wasi-build.

  5. After successfully building your component, it's time to test it. The following command can be used to test your component logic without deploying WAVS. Make sure to replace the placeholders with the correct inputs.

# Run this command to build the component:
WASI_BUILD_DIR=components/openai-response make wasi-build
# Once built, test it with:
export COMPONENT_FILENAME=openai_response.wasm
export INPUT_DATA="Only respond with yes or no: Is AI beneficial to the world?"
make wasi-exec

The agent may try to run the make wasi-exec command themselves. You should prompt the agent to give you the command instead, as it can't run the command without permissions.

  1. Your component should execute and return a response. If there are any errors, share them with the agent for troubleshooting.

If you have any questions, join the WAVS DEVS Telegram channel: https://t.me/layer_xyz/818

Tips for working with AI agents

  • While this repo contains rulefiles with enough context for creating simple components, coding agents are unpredictable and may inevitably run into problems.
  • Feel free to update the rulefiles for your specific purposes or if you run into regular errors.
  • Coding agents can sometimes try to over-engineer their fixes for errors. If you feel it is not being productive, it may be beneficial to start fresh. You may need to adjust your prompt.
  • If you are building a complex component, it may be helpful to have the agent build a simple component first and then expand upon it.
  • The agent may try to fix warnings unnecessarily. You can tell the agent to ignore minor warnings and any errors found in bindings.rs (it is auto-generated).

Prompting

This repo is designed to be used with short prompts for simple components. However, often, coding agents will do better with more context.

When creating a prompt, consider the following:

  • Agents work best with short, clear instructions.
  • Provide relevant documentation (preferably as an .md file or other ai-digestible content).
  • Provide endpoints.
  • You may need to provide API response structure if the agent is not understanding responses.
  • Be specific about what you want the agent to build.
  • Agents work systematically to build components. For best results, agent should make a plan before they start building.
  • Be patient. Coding agents are not perfect. They may make mistakes.

Troubleshooting

  • You can ask the agent to fix errors it may not be able to catch when executing components. Make sure to give the agent full context of the error.
  • LLMs can be unpredictable. Minimal prompts provide a lot of room for creativity/error. If the agent is not able to fix an error after trying, sometimes deleting the component, clearing the history, and starting fresh can help.
  • The agent may try to edit the bindings.rs file to "fix" it. The agent never needs to do this, and you should tell the agent to not do this.
  • The agent is supposed to provide you with the make wasi-exec command. Sometimes it will try to run this itself and it will fail. Instead, ask it to give you the command.
  • When copying and pasting the full make wasi-exec command, be careful with line breaks. You may need to reformat long lines to avoid breaking the command.

Edit on GitHub

On this page