# Build Your First Agent with Rasa Copilot

This guide is for technical users who want a quick way to test out a new custom action from a local development server.

## Prerequisites

This workflow requires that you already have a Rasa CALM project initialized. Please see the [Rasa installation guide](/content/docs/pro/installation/overview/index.html) for more details.

## Step 1: Implement Your Custom Action

Add your custom action by creating or modifying the `actions/actions.py` file. Below is an example of a custom action that validates sufficient funds:

```python
# This file contains your custom actions which can be used to run
# custom Python code.
# See Rasa Tutorial for more details https://rasa.com/docs/pro/tutorial#integrating-an-api-call

from typing import Any, Text, Dict, List
from rasa_sdk import Action, Tracker
from rasa_sdk.executor import CollectingDispatcher
from rasa_sdk.events import SlotSet

class ActionValidateSufficientFunds(Action):

def name(self) -> Text:
        return "action_validate_sufficient_funds"

def run(self, dispatcher: CollectingDispatcher,
            tracker: Tracker,
            domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
        # Hard-coded balance for tutorial purposes. In production,
        # this would be retrieved from a database or an API.
        balance = 1000
        transfer_amount = tracker.get_slot("amount")
        has_sufficient_funds = transfer_amount <= balance
        return [SlotSet("has_sufficient_funds", has_sufficient_funds)]
```

## Step 2: Run the Action Server

Start the action server locally using the Rasa CLI:

```bash
rasa run actions
```

This command launches the action server, which runs on [http://localhost:5055](http://localhost:5055/) by default.

## Step 3: Expose the Action Server

For Rasa Studio to connect to your custom action server during testing, expose your local server to the public internet. You can use a tool like ngrok for this purpose.

Run the following command:

```bash
ngrok http 5055
```

### Optional: Deploy to a Cloud Environment

If you want to avoid using ngrok for repeated testing or need a more robust setup, [see more details on the action server reference](/content/docs/action-server/index.html) to deploy your development action server to a cloud environment of your choice. Ensure the public URL of your deployed action server is accessible and provide it to Rasa Studio for integration.

## Step 4: Connect to Studio

1. Open Rasa Studio and load your assistant project.
2. Navigate to the **Settings** section in Rasa Studio.
3. Go to the **Endpoints** tab and locate the **Action Server URL** field.
4. Enter the URL of your action server:
   - **Option 1 (Using ngrok)**: Paste the public URL generated by the `ngrok http 5055` command (e.g., `https://<your-ngrok-subdomain>.ngrok.io`).
   - **Option 2 (Local Server)**: If you are running the action server locally and testing on the same machine, use `http://localhost:5055`.
5. Click **Save** to apply the configuration.
6. Train your assistant by clicking the **Train** button to ensure the new custom action is included in the training process.
7. Use the **Interactive Learning** or **Conversations** tools to test your assistant and confirm that the custom action is executed as expected.

### Troubleshooting Tips

If the assistant cannot connect to the action server:

- Ensure the action server is running (`rasa run actions`).
- If using `ngrok`, verify the public URL is still active and hasn’t expired.
- Confirm the URL matches what is specified in the **Action Server URL** field.
