Core
vision
b64_encode_image
img- The image to encode. Expects [RGB] channelsformat- The format of the image.
rich_columns
TaskSpeedColumn Objects
render
data_model
LabelRowMetadataIncludeArgs Objects
dep_storage_item dependencies instead.
LabelRowInitialiseLabelsArgs Objects
LabelRowV2.initialise_labels.
FrameData Objects
project_hash
The identifier of the given project.data_hash
The identifier of the given data asset.frame
The frame number. If single image, it’s default 0.object_hashes
Object hashes if the request was made on particular objects from the AppFrame Objects
frame
The frame number within the videocontent
An [h,w,c] np.array with color channels RGB.b64_encoding
-
image_format- Which type of image encoding to use. -
output_format- Different common formats.raw: the image content as a raw b64 stringurl: url encoded image content. Compatible with, e.g.,<img src="<the_encoding>" />openai: a dict withtypeandimage_urlkeys _anthropic: a dict withmedia_type,type, anddatakeys.
-
Returns- a dict or string depending onoutput_format.
InstanceCrop Objects
instance
The ObjectInstance associated to the crop.EditorAgentResponse Objects
message
A message to be displayed to the user. Purely informational: it never affects routing or labels. Encord truncates messages longer than 256 characters.decision
The name of the workflow pathway that the task should follow. Only honored for workflow-triggered agents. An agent invoked from the Label Editor has no task to route, so Encord ignores the field there. The value must match one of the agent stage’s configured pathway names. An unmatched name fails the execution rather than falling back, and the name is matched verbatim — a pathway UUID is not accepted. When omitted, the stage’s default pathway is used, or its only pathway if it has exactly one.utils
get_user_client
get_initialised_label_row
frame_data- The data pointing to the data asset.
Exception- If theframe_datacannot be matched to a label row
download_asset
In here the file exists
pixel_values = np.asarray(Image.open(asset_path)) Arguments:storage_item- The Storage item for which you want to download the associated asset.frame- The frame that you need. If frame is none for a video, you the video path is returned.
NotImplementedError- If you try to get all frames of an image group.ValueError- If you try to download an unsupported data type (e.g., DICOM).
get_frame_count
batch_iterator
iterator- The source iteratorbatch_size- Size of each batch > 0
ontology
GenericFieldModel Objects
set_answer
FieldType
Field from pydantic can be anything so hard to type. This is supposed to indicate that you should use thepydantic.Field function to construct this var.
OntologyDataModel Objects
__call__
-
answer- The json object as a raw string. -
Returns- a list of classification / object instances that must be added to a label row.
validate_json
-
answer_str- The json object as a raw string. -
Returns- a list of classification / object instances that must be added to a label row.
settings
Settings used throughout the module. Note that central settings are read using environment variables.Settings Objects
ssh_key_file
The path to the private ssh key file to authenticate with Encord. Either this or theENCORD_SSH_KEY needs to be set for most use-cases.
To setup a key with Encord, see
the platform docs.
ssh_key_content
The content of the private ssh key file to authenticate with Encord. Either this or theENCORD_SSH_KEY needs to be set for most use-cases.
To setup a key with Encord, see
the platform docs.
WebhookSettings Objects
Settings: checking that a request came from Encord is
something an endpoint should be able to do before — or without ever — holding
Encord credentials.
webhook_secret
The signing secret this deployment verifies incoming requests with. Encord shows it in the app alongside the endpoint’s configuration; check it again if you change that configuration. Read only when the secret is not passed explicitly. Use this when a single secret covers everything this deployment verifies. Otherwise, pass the secret explicitly. Verifying and reading the requests Encord signs. Encord signs every request it makes to a configured URL: the task-ready notifications an agent stage sends, and the calls it makes to a custom agent endpoint. Those URLs have to be publicly reachable, so the signature is what separates a genuine request from anything else that finds them. Verification needs the signing secret, which Encord shows in the app alongside the endpoint’s configuration. Set it asENCORD_WEBHOOK_SECRET, or pass it explicitly, and
check it again if you change that configuration.
DEFAULT_TIMESTAMP_TOLERANCE_SECONDS
How far the signed timestamp may be from now before a request is refused as a replay.AGENT_STAGE_WORK_AVAILABLE_EVENT
The event Encord sends when tasks are waiting at an agent stage.SUPPORTED_NOTIFICATION_VERSION
The envelope version this module reads. Encord bumps it only for a change that breaks the previous shape; fields and enum values are added without one. So an envelope on this version is safe to read even if it carries things this module has never heard of, and one on another version is not.WebhookVerificationError Objects
UnexpectedEventType Objects
task_submitted_event. Acknowledge those rather than failing on them.
UnsupportedNotificationVersion Objects
encord-agents.
AgentStageWorkReason Objects
BATCH_SIZE_REACHED
The number of queued tasks reached the stage’s minimum batch size.MAX_WAIT_ELAPSED
A task had been queued longer than the stage’s maximum wait.StageWorkAvailable Objects
pending_count
How many tasks were queued when the notification was raised. A hint, not a promise: fetch the queue to find what is actually there now.reason
Which condition fired. A condition added platform-side arrives as a plain string rather than failing validation, since Encord adds those without bumping the envelope version. Compare againstAgentStageWorkReason for the ones known here — and to tell a known one
from a new one, use isinstance(reason, AgentStageWorkReason), since the enum
subclasses str and so is a str either way.
TaskNotification Objects
uid
Identifies this delivery. Not a deduplication key: Encord recomputes the state every cycle and re-notifies with a fresh uid while work remains.verify_signature
body carries a signature only Encord could have produced.
Arguments:
body- The request body exactly as received. Re-serializing it first will notverify- the signature covers the bytes that were sent.signature- TheX-Encord-Signatureheader, if present.timestamp- TheX-Encord-Timestampheader, if present.secret- The signing secret to verify against. Read fromENCORD_WEBHOOK_SECRETwhen not given.tolerance_seconds- How far from now the signed timestamp may be.
WebhookVerificationError- If the headers are missing or malformed, the timestamp is outside the tolerance, or the signature does not match.PrintableError- If no secret was given or configured.
parse_notification
UnexpectedEventType- If the body is a different Encord event.UnsupportedNotificationVersion- If it is that event on a later envelope version.pydantic.ValidationError- If it is that event but does not match the model.
verify_and_parse_notification
WebhookVerificationError- If the request cannot be shown to be from Encord.UnexpectedEventType- If it is genuine but carries a different event.UnsupportedNotificationVersion- If it is on a later envelope version.PrintableError- If no secret was given or configured.
video
get_frame
video_path- The file path to where the video is stored.desired_frame- The frame to extract
Exception- If the video cannot be opened properly or the requested frame could not be retrieved from the video.
write_frame
frame_path- The file path to write the frame to.frame- The frame to write.
iter_video
video_path- The file path to the video you wish to iterate.
Exception- If the video file could not be opened properly.
iter_video_with_indices
video_path- The file path to the video you wish to iterate.frame_indices- The frame indices to iterate over.
dependencies.serverless
This module defines dependencies available for injection within serverless Editor Agents. These dependencies can be used independently, even when reliant on other dependencies. Note: The injection mechanism necessitates the presence of type annotations for the following parameters to ensure proper resolution.FrameDatais automatically injected via the api request body.Projectis automatically loaded based on the frame data.label_row_v2is automatically loaded based on the frame data.
dep_client
dep_single_frame
lr.data_hash.{suffix}.
When the function has finished running, the downloaded file is removed from the file system.
Example:
storage_item- The Storage item. Automatically injected (see example above).
dep_asset
ValueError- if the underlying assets are not videos, images, or audio.EncordException- if data type not supported by SDK yet.
dep_video_iterator
storage_item- Automatically injected storage item dependency.
NotImplementedError- Fails for data types other than video.
dep_data_lookup
dep_data_lookup is deprecated and will be removed in version 0.2.10.
Use dep_storage_item instead for accessing storage items.
Migration Guide:
lookup- The object that you can use to lookup data rows and storage items. Automatically injected.
dep_storage_item
StorageItem
is useful for multiple things like
- Updating client metadata
- Reading file properties like storage location, fps, duration, DICOM tags, etc.
dep_object_crops
-
filter_ontology_objects- Specify a list of ontology objects to include. If provided, only instances of these object types are included. Strings are matched againstfeature_node_hashes. -
Returns- The dependency to be injected into the cloud function.
DEncordClient
Get an authenticated user client.DObjectsInstances
Get all object instances that the agent was triggered on. No pixels, just the annotation.DObjectCrops
Get all object crops that the agent was triggered on. The instance crop contains the object instance, the frame content (pixel values), and the frame.DSingleFrame
Get the single frame that the agent was triggered on.DAssetPath
Get a local file path to data asset temporarily stored till end of agent execution.DVideoIterator
Get a video frame iterator for doing things over many frames.DStorageItem
Get the storage item associated with the underlying agent task to, for example, read/write client metadata or read data properties.dependencies.shares
DataLookup Objects
DataLookup is deprecated and will be removed in version 0.2.10.
Migration Guide:
- For accessing storage items, use
dep_storage_iteminstead:
backing_item_uuids
get_storage_item
dep_storage_item dependency instead.
Arguments:
data_hash- Data hash for the asset for which you need the underlying storage item.dataset_hash- If you didn’t provide the associated dataset hash in the constructor, this is your last chance.sign_url- IfTrue, pre-fetch a signed URLs for the items (otherwise the URLs will be signed on demand).
ValueError- Mainly if underlying data row cannot be found.
get_storage_items
data_hashes- Data hashes for the assets for which you need the underlying storage items.dataset_hash- If you didn’t provided the associated dataset hash in the constructor, this is your last chance.sign_urls- IfTrue, pre-fetch a signed URLs for the items (otherwise the URLs will be signed on demand).
ValueError- Mainly if underlying data row cannot be found.

