GCP Cloud Functions
The following example shows the general structure of how to build a GCP cloud function. For concrete implementations of agents with specific abilities, see the examples section.
STEP 1: Create a Project
- Create a new Encord Project:
- Create and source a new virtual environment.
- Create a requirements file.
- Install dependencies.
STEP 2: Define the Agent
Create a main.py
file using the following template:
Complete the my_agent
function with the logic you want to execute when the agent is triggered.
You can inject multiple different dependencies into the function if necessary.
You can find multiple examples of what can be done with editor agents here.
STEP 3: Test the Agent
Trigger the agent by running it locally.
This means starting an API at localhost:8080/my_agent
that expects a POST request with JSON
data with the following format:
To test the agent endpoint, open the Label Editor in your browser on a frame where you want to run the agent. Then, copy the URL.
Open a new terminal in the my_project
directory and run:
Notice the single quotes around <the_pasted_url>
. They are important and should be there because you might copy a url with, e.g., an &
character that have a special meaning if it is not within a string (or escaped).
Refresh the Label Editor in your browser to see the effect.
STEP 4: Deployment
To go from development to production, you must deploy your agent on the Google infrastructure.
The following example shows how you can deploy the agent to the cloud. Notice how secrets (the SSH key that the agent should use) are set.
See the official Google run function deploy docs for more information.
There are a couple of things that you need to pay attention to:
- You must make sure to authenticate
gcloud
and select the appropriate project first - You should configure a secret with the ssh_key content. See Google Secrets docs