Basic Task Agent Example
Before getting started, ensure that you have:
python >= 3.10
. If you do not have Python 3.10, we recommend usingpyenv
to manage your Python versions.- The ability to authenticate with Encord.
- Installed the Encord Agents library.
The following example shows how to create a simple Task Agent to change the priority of each task before moving it to the next stage of the Workflow.
We also provide more detailed Task Agent examples and Editor Agent examples.
1. Create Encord Project
Create a Project in Encord containing the following Workflow with an agent stage.
The purple node in the Workflow is an agent node named pre-label
. It has a single pathway called annotate
that moves tasks to the next stage in the Workflow.
Copy the Project ID
in the top left of the Project page.
Check if your existing Project has any agent nodes by running the following command.
2. Define the Agent
In the directory you created for your agents, create a Python file. In this example we use agent.py
.
Copy paste the following template in to the Python file:
The my_agent_logic
function takes a LabelRowV2
instance belonging to a task currently in the "pre-label"
agent stage. The agent then returns the name of the pathway the task should follow once completed.
We must define how this data is handled. In this example, we keep it simple by assigning priority based on the file name. If the file name contains "london"
, it gets assigned a high priority; otherwise, it gets assigned low priority.
3. Run the Agent
The Agent must be run in order for tasks to be moved on to the next Workflow stage.
Run the agent by executing the following command: