Shepherd is a shared platform for ARA implementation. Incorporated ARAs have access to a plethora of shared ARA functionality while retaining the ability to implement their own custom operations.
All Shepherd services are set up as docker containers. You can learn about docker and install here: https://www.docker.com/
The main entrypoint is ./compose.yml and will spin everything up.
- In the root folder, run
docker compose up --build
If you want to add a new operation/worker, add a new service in compose.yml under services.
Each worker is it's own separate docker container. It spins up and begins to watch a central message broker for tasks to work on. Once it gets a task, it can do that task either synchronously, asynchronously, on a separate process etc. based on its individual resource requirements.
Each worker has access to a shared utilities library that aids in db and message broker interaction as well as other functions that are common across ARAs. Check the shared function library before writing a new function that you think other ARAs might also want to use.
Shepherd uses Redis Streams for its message broker. More info on Redis Streams can be found here
Each worker type listens to its own message stream/queue. The shared workers can just use their Translator workflow name for their stream name. For workers that share the same workflow but are for different ARAs need their own custom stream name. The current convention is to use the format {ara_name}.{workflow_name}.
Multiple workers of the same type can be in the same GROUP, and redis will make sure not to give out the same task to more than one worker in that group. The current convention is to call the group consumer.
Creating a brand new ARA is fairly straightforward. Here are the steps to create a basic ARA that performs all the necessary Translator operations:
- Copy the
workers/example_arafolder. This will be the main entrypoint to your new ARA.- Towards the top of that file, replace the
STREAMvariable value with your ARA name. - Within the
example_arafunction in that file, replace theworkflowlist with your ARA's workflow. This could include analyzing themessageto determine a pertinent workflow. - Note: If using operations not in the shared workers, your workflow operation ids need to reflect the
STREAMname of your custom operation workers. This is how the task get passed to your operation worker.
- Towards the top of that file, replace the
- (If needed) Copy the
workers/example_lookupfolder. This will be your ARA's lookup operation.- Towards the top of that file, replace the
STREAMvariable value with{ara_name}.lookup. - Within the
example_lookupfunction in that file, replace the contents with your ARA's lookup logic.
- Towards the top of that file, replace the
- (If needed) Copy the
workers/example_scorefolder. This will be your ARA's score operation.- Towards the top of that file, replace the
STREAMvariable value with{ara_name}.score. - Within the
example_scorefunciton in that file, replace the contents with your ARA's scoring logic.
- Towards the top of that file, replace the
- If you have other custom operations you want to perform that are in your
workflowabove, pick a similar folder to copy and adjust the code inside to fit your needs. - If you want to use shared workers (i.e.
workers/sort_results_score,workers/filter_results_top_n), you don't need to do anything other than include them in your workflow. They will automatically pick up your query and pass it along like your other operations. - Open the
compose.ymlfile in the root directory, and for each ARA folder you created, add aservice(or copy an existing one), and make sure that thecontainer_nameandbuild/dockerfilereflect you worker names and the path to your worker Dockerfile - Run Shepherd with
docker compose up --build
Shepherd uses pytest and tox for local test running and GitHub Actions. To run tests, simply activate your virtual env, run:
pip install toxand then run:tox
This will run all the tests and then also provide code coverage.
If you would like to run local integration tests, run the scripts/test_shepherd.py script to run a query against your ARA. Replace the target argument with your ARA name so the server routes the query to your worker. This script requires that Shepherd be running locally.