Getting started
ℹ️ This example requires
python >= 3.10
. If you do not have python 3.10, we recommend using, e.g.,pyenv
to manage your python versions.
Here's the steps to follow to run your first task agent. The example agent will modify the priority of each task before passing it along. We also provide multiple task agent examples and editor agent examples.
1. Setup
Create a fresh directory and change to that directory.
Create a new virtual environment.
Now, install encord-agents
.
2. Encord workflow project
If you don't already have a workflow project which includes an agent stage, please create one.
In this example, we use a project workflow that looks like this:
Notice the purple node in the workflow; It's an agent node with name: pre-label
.
Furthermore, is has just one pathway called "annotate."
Copy the Project ID
in the top left of the project page.
Tip
After authenticating, you can check if your existing project has any agent nodes by running this command:
If the project has agent nodes in the workflow, you should see a list similar to this:3. Define your agent
In your freshly created directory, create a python file.
In this example, we'll call it agent.py
.
Copy paste the following template.
from encord.objects import LabelRowV2
from encord_agents.tasks import Runner
runner = Runner(project_hash="<your_project_hash>")
@runner.stage(stage="pre-label")
def my_agent_logic(lr: LabelRowV2) -> str:
# ...
return "annotate"
if __name__ == "__main__":
runner.run()
Notice the my_agent_logic
, it recieves a LabelRowV2
instance.
That label row is associated with a task that is currently sitting in the "pre-label"
agent stage.
Also, the agent is returning the name of the pathway that the task is supposed to follow upon agent completion.
Now, it's our job to define what's supposed to happen with this piece of data.
In this example, we'll keep it simple and assign a priority based on the file name.
If the file name contains "london"
we'll give it high priority otherwise a low priority.
Update the my_agent_logic
to look like this:
@runner.stage(stage="pre-label")
def my_agent_logic(lr: LabelRowV2) -> str:
lr.set_priority(priority=float("london" in lr.data_title))
return "annotate"
Too simple?
If the example is too simple, please see the task examples to find something more useful to your use-case.
4. Running the agent
From agent.py
above, notice the last part.
Run the agent by executing the following command: