Editor Agents Reference¶
AWS Lambda¶
encord_agents.aws.editor_agent
¶
editor_agent(*, label_row_metadata_include_args: LabelRowMetadataIncludeArgs | None = None, label_row_initialise_labels_args: LabelRowInitialiseLabelsArgs | None = None) -> Callable[[AgentFunction], Callable[[Dict[str, Any], Any], Dict[str, Any]]]
Wrapper to make resources available for AWS Lambda editor agents.
Source code in encord_agents/aws/wrappers.py
encord_agents.aws.dependencies
¶
DAssetPath
module-attribute
¶
Get a local file path to data asset temporarily stored till end of agent execution.
DEncordClient
module-attribute
¶
Get an authenticated user client.
DObjectCrops
module-attribute
¶
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.
DObjectsInstances
module-attribute
¶
Get all object instances that the agent was triggered on. No pixels, just the annotation.
DSingleFrame
module-attribute
¶
Get the single frame that the agent was triggered on.
DStorageItem
module-attribute
¶
Get the storage item associated with the underlying agent task to, for example, read/write client metadata or read data properties.
DVideoIterator
module-attribute
¶
Get a video frame iterator for doing things over many frames.
dep_asset
¶
Returns a local file path to the data asset, temporarily stored for the duration of the agent's execution.
This dependency fetches the underlying data asset using a signed URL.
The asset is temporarily stored on disk for the duration of the task and is automatically removed once the task completes.
Example:
from encord_agents.gcp import editor_agent
from encord_agents.gcp.dependencies import dep_asset
...
runner = Runner(project_hash="<project_hash_a>")
@editor_agent()
def my_agent(
asset: Annotated[Path, Depends(dep_asset)]
) -> None:
asset.stat() # read file stats
...
Returns:
-
None
–The path to the asset.
Raises:
-
ValueError
–if the underlying assets are not videos, images, or audio.
-
EncordException
–if data type not supported by SDK yet.
Source code in encord_agents/core/dependencies/serverless.py
dep_client
¶
Dependency to provide an authenticated user client.
Example:
from encord.user_client import EncordUserClient
from encord_agents.gcp import editor_agent
from encord_agents.gcp.dependencies import dep_client
...
@editor_agent()
def (
client: Annotated[EncordUserClient, Depends(dep_client)]
):
# Client will authenticated and ready to use.
client.get_dataset("")
Source code in encord_agents/core/dependencies/serverless.py
dep_object_crops
¶
dep_object_crops(filter_ontology_objects: list[Object | str] | None = None) -> Callable[[FrameData, LabelRowV2, NDArray[np.uint8]], list[InstanceCrop]]
Returns a list of object instances and frame crops associated with each object.
One example use-case is to run each crop against a model.
Example:
@editor_agent
def my_agent(crops: Annotated[list[InstanceCrop], Depends[dep_object_crops(filter_ontology_objects=["eBw/75bg"])]]):
for crop in crops:
crop.content # <- this is raw numpy rgb values
crop.frame # <- this is the frame number in video
crop.instance # <- this is the object instance from the label row
crop.b64_encoding() # <- a base64 encoding of the image content
...
Parameters:
-
filter_ontology_objects
(list[Object | str] | None
, default:None
) –Specify a list of ontology objects to include. If provided, only instances of these object types are included. Strings are matched against
feature_node_hashes
.
Returns: The dependency to be injected into the cloud function.
Source code in encord_agents/core/dependencies/serverless.py
dep_single_frame
¶
Dependency to inject the first frame of the underlying asset.
The downloaded asset will be named lr.data_hash.{suffix}
.
When the function has finished running, the downloaded file is removed from the file system.
Example:
from encord_agents import FrameData
from encord_agents.gcp import editor_agent
from encord_agents.gcp.dependencies import dep_single_frame
...
@editor_agent()
def my_agent(
frame: Annotated[NDArray[np.uint8], Depends(dep_single_frame)]
):
assert frame.ndim == 3, "Will work"
Parameters:
-
storage_item
(StorageItem
) –The Storage item. Automatically injected (see example above).
Returns:
-
NDArray[uint8]
–Numpy array of shape [h, w, 3] RGB colors.
Source code in encord_agents/core/dependencies/serverless.py
dep_storage_item
¶
Get the storage item associated with the underlying agent task.
The StorageItem
is useful for multiple things like
- Updating client metadata
- Reading file properties like storage location, fps, duration, DICOM tags, etc.
Example
from typing_extensions import Annotated
from encord.storage import StorageItem
from encord_agents.gcp import editor_agent, Depends
from encord_agents.gcp.dependencies import dep_storage_item
@editor_agent()
def my_agent(storage_item: Annotated[StorageItem, Depends(dep_storage_item)]):
print("uuid", storage_item.uuid)
print("client_metadata", storage_item.client_metadata)
...
Source code in encord_agents/core/dependencies/serverless.py
dep_video_iterator
¶
Dependency to inject a video frame iterator for performing operations over many frames.
Example:
from encord_agents import FrameData
from encord_agents.gcp import editor_agent
from encord_agents.gcp.dependencies import dep_video_iterator
...
@editor_agent()
def my_agent(
video_frames: Annotated[Iterator[Frame], Depends(dep_video_iterator)]
):
for frame in video_frames:
print(frame.frame, frame.content.shape)
Parameters:
-
storage_item
(StorageItem
) –Automatically injected storage item dependency.
Raises:
-
NotImplementedError
–Fails for data types other than video.
Yields:
-
Iterator[Frame]
–An iterator.
Source code in encord_agents/core/dependencies/serverless.py
encord_agents.aws.wrappers
¶
editor_agent
¶
editor_agent(*, label_row_metadata_include_args: LabelRowMetadataIncludeArgs | None = None, label_row_initialise_labels_args: LabelRowInitialiseLabelsArgs | None = None) -> Callable[[AgentFunction], Callable[[Dict[str, Any], Any], Dict[str, Any]]]
Wrapper to make resources available for AWS Lambda editor agents.
Source code in encord_agents/aws/wrappers.py
FastAPI¶
encord_agents.fastapi.dep_client
¶
Dependency to provide an authenticated user client.
Example:
from encord.user_client import EncordUserClient
from encord_agents.fastapi.dependencies import dep_client
...
@app.post("/my-route")
def my_route(
client: Annotated[EncordUserClient, Depends(dep_client)]
):
# Client will authenticated and ready to use.
Source code in encord_agents/fastapi/dependencies.py
encord_agents.fastapi.dep_label_row
¶
Dependency to provide an initialized label row.
Example:
from encord_agents.fastapi.dependencies import dep_label_row
...
@app.post("/my-route")
def my_route(
lr: Annotated[LabelRowV2, Depends(dep_label_row)]
):
assert lr.is_labelling_initialised # will work
Parameters:
-
frame_data
(FrameData
) –the frame data from the route. This parameter is automatically injected if it's a part of your route (see example above)
Returns:
-
LabelRowV2
–The initialized label row.
Source code in encord_agents/fastapi/dependencies.py
encord_agents.fastapi.dep_single_frame
¶
dep_single_frame(storage_item: Annotated[StorageItem, Depends(dep_storage_item)], frame_data: FrameData) -> NDArray[np.uint8]
Dependency to inject the underlying asset of the frame data.
The downloaded asset will be named lr.data_hash.{suffix}
.
When the function has finished, the downloaded file will be removed from the file system.
Example:
from encord_agents.fastapi.dependencies import dep_single_frame
...
@app.post("/my-route")
def my_route(
frame: Annotated[NDArray[np.uint8], Depends(dep_single_frame)]
):
assert arr.ndim == 3, "Will work"
Parameters:
-
storage_item
(Annotated[StorageItem, Depends(dep_storage_item)]
) –The label row. Automatically injected (see example above).
-
frame_data
(FrameData
) –the frame data from the route. This parameter is automatically injected if it's a part of your route (see example above).
Returns: Numpy array of shape [h, w, 3] RGB colors.
Source code in encord_agents/fastapi/dependencies.py
encord_agents.fastapi.get_encord_app
¶
Get a FastAPI app with the Encord middleware.
Parameters:
-
custom_cors_regex
(str | None
, default:None
) –A regex to use for the CORS middleware. Only necessary if you are not using the default Encord domain.
Returns:
-
FastAPI
(FastAPI
) –A FastAPI app with the Encord middleware.
Source code in encord_agents/fastapi/cors.py
encord_agents.fastapi.verify_auth
¶
FastAPI lifecycle start hook to fail early if ssh key is missing.
Example:
This will make the server fail early if auth is not set up.
Source code in encord_agents/fastapi/utils.py
encord_agents.fastapi.cors
¶
Convenience method to easily extend FastAPI servers with the appropriate CORS Middleware to allow interactions from the Encord platform.
EncordCORSMiddleware
¶
Bases: CORSMiddleware
Like a regular fastapi.middleware.cors.CORSMiddleware
but matches against
the Encord origin by default and handles X-Encord-Editor-Agent test header
Example:
from fastapi import FastAPI
from encord_agents.fastapi.cors import EncordCORSMiddleware
app = FastAPI()
app.add_middleware(EncordCORSMiddleware)
The CORS middleware will allow POST requests from the Encord domain.
Source code in encord_agents/fastapi/cors.py
EncordTestHeaderMiddleware
¶
Bases: BaseHTTPMiddleware
Source code in encord_agents/fastapi/cors.py
dispatch
async
¶
Middleware to handle the X-Encord-Editor-Agent test header.
Parameters:
-
request
(Request
) – -
call_next
(RequestResponseEndpoint
) –
Returns:
-
Response
–Response
Source code in encord_agents/fastapi/cors.py
get_encord_app
¶
Get a FastAPI app with the Encord middleware.
Parameters:
-
custom_cors_regex
(str | None
, default:None
) –A regex to use for the CORS middleware. Only necessary if you are not using the default Encord domain.
Returns:
-
FastAPI
(FastAPI
) –A FastAPI app with the Encord middleware.
Source code in encord_agents/fastapi/cors.py
encord_agents.fastapi.dependencies
¶
Dependencies for injection in FastAPI servers.
This module contains dependencies that you can inject within your api routes. Dependencies that depend on others don't need to be used together. They'll work just fine alone.
Note that you can also use the function parameter:
from typing_extensions import Annotated
from fastapi import Form
from encord_agents import FrameData
...
@app.post("/my-agent-route")
def my_agent(
frame_data: FrameData,
):
...
FrameData
is automatically injected via the api request body.
dep_asset
¶
dep_asset(storage_item: Annotated[StorageItem, Depends(dep_storage_item)]) -> Generator[Path, None, None]
Get a local file path to data asset temporarily stored till end of agent execution.
This dependency will fetch the underlying data asset based on a signed url. It will temporarily store the data on disk. Once the task is completed, the asset will be removed from disk again.
Example:
from encord_agents.fastapi.dependencies import dep_asset
...
runner = Runner(project_hash="<project_hash_a>")
@app.post("/my-route")
def my_agent(
asset: Annotated[Path, Depends(dep_asset)],
) -> str | None:
asset.stat() # read file stats
...
Returns:
-
None
–The path to the asset.
Raises:
-
ValueError
–if the underlying assets are not videos, images, or audio.
-
EncordException
–if data type not supported by SDK yet.
Source code in encord_agents/fastapi/dependencies.py
dep_client
¶
Dependency to provide an authenticated user client.
Example:
from encord.user_client import EncordUserClient
from encord_agents.fastapi.dependencies import dep_client
...
@app.post("/my-route")
def my_route(
client: Annotated[EncordUserClient, Depends(dep_client)]
):
# Client will authenticated and ready to use.
Source code in encord_agents/fastapi/dependencies.py
dep_data_lookup
¶
Get a lookup to easily retrieve data rows and storage items associated with the given task.
Deprecated
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:
# Old way (deprecated)
from encord_agents.fastapi.dependencies import dep_data_lookup, DataLookup
@app.post("/my-agent")
def my_agent(
frame_data: FrameData,
lookup: Annotated[DataLookup, Depends(dep_data_lookup)]
):
storage_item = lookup.get_storage_item(frame_data.data_hash)
print(storage_item.client_metadata)
# New way (recommended)
from encord_agents.fastapi.dependencies import dep_storage_item
@app.post("/my-agent")
def my_agent(
frame_data: FrameData,
storage_item: Annotated[StorageItem, Depends(dep_storage_item)]
):
# storage_item is directly available
print(storage_item.client_metadata)
Parameters:
-
lookup
(Annotated[DataLookup, Depends(_lookup_adapter)]
) –The object that you can use to lookup data rows and storage items. Automatically injected.
Returns:
-
DataLookup
–The (shared) lookup object.
Source code in encord_agents/fastapi/dependencies.py
dep_label_row
¶
Dependency to provide an initialized label row.
Example:
from encord_agents.fastapi.dependencies import dep_label_row
...
@app.post("/my-route")
def my_route(
lr: Annotated[LabelRowV2, Depends(dep_label_row)]
):
assert lr.is_labelling_initialised # will work
Parameters:
-
frame_data
(FrameData
) –the frame data from the route. This parameter is automatically injected if it's a part of your route (see example above)
Returns:
-
LabelRowV2
–The initialized label row.
Source code in encord_agents/fastapi/dependencies.py
dep_label_row_with_args
¶
dep_label_row_with_args(label_row_metadata_include_args: LabelRowMetadataIncludeArgs | None = None, label_row_initialise_labels_args: LabelRowInitialiseLabelsArgs | None = None) -> Callable[[FrameData], LabelRowV2]
Dependency to provide an initialized label row.
Example:
from encord_agents.core.data_model import LabelRowMetadataIncludeArgs, LabelRowInitialiseLabelsArgs
from encord_agents.fastapi.dependencies import dep_label_row_with_args
...
include_args = LabelRowMetadataIncludeArgs(
include_client_metadata=True,
include_workflow_graph_node=True,
)
init_args = LabelRowInitialiseLabelsArgs(
include_signed_url=True,
)
@app.post("/my-route")
def my_route(
lr: Annotated[LabelRowV2, Depends(dep_label_row_with_args(include_args, init_args))]
):
assert lr.is_labelling_initialised # will work
assert lr.client_metadata # will be available if set already
Parameters:
-
label_row_metadata_include_args
(LabelRowMetadataIncludeArgs | None
, default:None
) –What arguments to include on the metadata front
-
label_row_initialise_labels_args
(LabelRowInitialiseLabelsArgs | None
, default:None
) –How and whether to initialise the label rows
Returns:
-
Callable[[FrameData], LabelRowV2]
–The initialized label row.
Source code in encord_agents/fastapi/dependencies.py
dep_object_crops
¶
dep_object_crops(filter_ontology_objects: list[Object | str] | None = None) -> Callable[[FrameData, LabelRowV2, NDArray[np.uint8]], list[InstanceCrop]]
Create a dependency that provides crops of object instances.
Useful, e.g., to be able to run each crop against a model.
Example:
@app.post("/object_classification")
async def classify_objects(
crops: Annotated[
list[InstanceCrop],
Depends(dep_object_crops(filter_ontology_objects=[generic_ont_obj])),
],
):
for crop in crops:
crop.content # <- this is raw numpy rgb values
crop.frame # <- this is the frame number in video
crop.instance # <- this is the object instance from the label row
crop.b64_encoding() # <- a base64 encoding of the image content
...
Parameters:
-
filter_ontology_objects
(list[Object | str] | None
, default:None
) –Optional list of ontology objects to filter by. If provided, only instances of these object types will be included. Strings are matched against
feature_node_hashes
.
Returns:
-
Callable[[FrameData, LabelRowV2, NDArray[uint8]], list[InstanceCrop]]
–A FastAPI dependency function that yields a list of InstanceCrop.
Source code in encord_agents/fastapi/dependencies.py
dep_project
¶
dep_project(frame_data: FrameData, client: Annotated[EncordUserClient, Depends(dep_client)]) -> Project
Dependency to provide an instantiated Project.
Example:
from encord.project import Project
from encord_agents.fastapi.dependencies import dep_project
...
@app.post("/my-route")
def my_route(
project: Annotated[Project, Depends(dep_project)]
):
# Project will authenticated and ready to use.
print(project.title)
Parameters:
-
frame_data
(FrameData
) – -
client
(Annotated[EncordUserClient, Depends(dep_client)]
) –
Returns:
Source code in encord_agents/fastapi/dependencies.py
dep_single_frame
¶
dep_single_frame(storage_item: Annotated[StorageItem, Depends(dep_storage_item)], frame_data: FrameData) -> NDArray[np.uint8]
Dependency to inject the underlying asset of the frame data.
The downloaded asset will be named lr.data_hash.{suffix}
.
When the function has finished, the downloaded file will be removed from the file system.
Example:
from encord_agents.fastapi.dependencies import dep_single_frame
...
@app.post("/my-route")
def my_route(
frame: Annotated[NDArray[np.uint8], Depends(dep_single_frame)]
):
assert arr.ndim == 3, "Will work"
Parameters:
-
storage_item
(Annotated[StorageItem, Depends(dep_storage_item)]
) –The label row. Automatically injected (see example above).
-
frame_data
(FrameData
) –the frame data from the route. This parameter is automatically injected if it's a part of your route (see example above).
Returns: Numpy array of shape [h, w, 3] RGB colors.
Source code in encord_agents/fastapi/dependencies.py
dep_storage_item
¶
dep_storage_item(label_row: Annotated[LabelRowV2, Depends(dep_label_row)], user_client: Annotated[EncordUserClient, Depends(dep_client)]) -> StorageItem
Get the storage item associated with the underlying agent task.
The StorageItem
is useful for multiple things like
- Updating client metadata
- Reading file properties like storage location, fps, duration, DICOM tags, etc.
Example
from encord.storage import StorageItem
from encord_agents.fastapi.dependencies import dep_storage_item
@app.post("/my-agent")
def my_agent(
storage_item: Annotated[StorageItem, Depends(dep_storage_item)]
):
# Client will authenticated and ready to use.
print(storage_item.dicom_study_uid)
print(storage_item.client_metadata)
Source code in encord_agents/fastapi/dependencies.py
dep_video_iterator
¶
dep_video_iterator(storage_item: Annotated[StorageItem, Depends(dep_storage_item)]) -> Generator[Iterator[Frame], None, None]
Dependency to inject a video frame iterator for doing things over many frames.
Example:
from encord_agents.fastapi.dependencies import dep_video_iterator, Frame
...
@app.post("/my-route")
def my_route(
video_frames: Annotated[Iterator[Frame], Depends(dep_video_iterator)]
):
for frame in video_frames:
print(frame.frame, frame.content.shape)
Parameters:
-
storage_item
(Annotated[StorageItem, Depends(dep_storage_item)]
) –Automatically injected storage item dependency.
Raises:
-
NotImplementedError
–Will fail for other data types than video.
Yields:
-
Iterator[Frame]
–An iterator.
Source code in encord_agents/fastapi/dependencies.py
encord_agents.fastapi.utils
¶
verify_auth
¶
FastAPI lifecycle start hook to fail early if ssh key is missing.
Example:
This will make the server fail early if auth is not set up.
Source code in encord_agents/fastapi/utils.py
GCP¶
encord_agents.gcp.editor_agent
¶
editor_agent(*, label_row_metadata_include_args: LabelRowMetadataIncludeArgs | None = None, label_row_initialise_labels_args: LabelRowInitialiseLabelsArgs | None = None, custom_cors_regex: str | None = None) -> Callable[[AgentFunction], Callable[[Request], Response]]
Wrapper to make resources available for gcp editor agents.
The editor agents are intended to be used via dependency injections. You can learn more via out documentation.
Parameters:
-
label_row_metadata_include_args
(LabelRowMetadataIncludeArgs | None
, default:None
) –arguments to overwrite default arguments on
project.list_label_rows_v2()
. -
label_row_initialise_labels_args
(LabelRowInitialiseLabelsArgs | None
, default:None
) –Arguments to overwrite default arguments on
label_row.initialise_labels(...)
-
custom_cors_regex
(str | None
, default:None
) –A regex to use for the CORS settings. If not provided, the default regex will be used. Only required if the agent is not deployed on Encord's platform.
Returns:
-
Callable[[AgentFunction], Callable[[Request], Response]]
–A wrapped function suitable for gcp functions.
Source code in encord_agents/gcp/wrappers.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|
encord_agents.gcp.dependencies
¶
DAssetPath
module-attribute
¶
Get a local file path to data asset temporarily stored till end of agent execution.
DEncordClient
module-attribute
¶
Get an authenticated user client.
DObjectCrops
module-attribute
¶
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.
DObjectsInstances
module-attribute
¶
Get all object instances that the agent was triggered on. No pixels, just the annotation.
DSingleFrame
module-attribute
¶
Get the single frame that the agent was triggered on.
DStorageItem
module-attribute
¶
Get the storage item associated with the underlying agent task to, for example, read/write client metadata or read data properties.
DVideoIterator
module-attribute
¶
Get a video frame iterator for doing things over many frames.
dep_asset
¶
Returns a local file path to the data asset, temporarily stored for the duration of the agent's execution.
This dependency fetches the underlying data asset using a signed URL.
The asset is temporarily stored on disk for the duration of the task and is automatically removed once the task completes.
Example:
from encord_agents.gcp import editor_agent
from encord_agents.gcp.dependencies import dep_asset
...
runner = Runner(project_hash="<project_hash_a>")
@editor_agent()
def my_agent(
asset: Annotated[Path, Depends(dep_asset)]
) -> None:
asset.stat() # read file stats
...
Returns:
-
None
–The path to the asset.
Raises:
-
ValueError
–if the underlying assets are not videos, images, or audio.
-
EncordException
–if data type not supported by SDK yet.
Source code in encord_agents/core/dependencies/serverless.py
dep_client
¶
Dependency to provide an authenticated user client.
Example:
from encord.user_client import EncordUserClient
from encord_agents.gcp import editor_agent
from encord_agents.gcp.dependencies import dep_client
...
@editor_agent()
def (
client: Annotated[EncordUserClient, Depends(dep_client)]
):
# Client will authenticated and ready to use.
client.get_dataset("")
Source code in encord_agents/core/dependencies/serverless.py
dep_object_crops
¶
dep_object_crops(filter_ontology_objects: list[Object | str] | None = None) -> Callable[[FrameData, LabelRowV2, NDArray[np.uint8]], list[InstanceCrop]]
Returns a list of object instances and frame crops associated with each object.
One example use-case is to run each crop against a model.
Example:
@editor_agent
def my_agent(crops: Annotated[list[InstanceCrop], Depends[dep_object_crops(filter_ontology_objects=["eBw/75bg"])]]):
for crop in crops:
crop.content # <- this is raw numpy rgb values
crop.frame # <- this is the frame number in video
crop.instance # <- this is the object instance from the label row
crop.b64_encoding() # <- a base64 encoding of the image content
...
Parameters:
-
filter_ontology_objects
(list[Object | str] | None
, default:None
) –Specify a list of ontology objects to include. If provided, only instances of these object types are included. Strings are matched against
feature_node_hashes
.
Returns: The dependency to be injected into the cloud function.
Source code in encord_agents/core/dependencies/serverless.py
dep_single_frame
¶
Dependency to inject the first frame of the underlying asset.
The downloaded asset will be named lr.data_hash.{suffix}
.
When the function has finished running, the downloaded file is removed from the file system.
Example:
from encord_agents import FrameData
from encord_agents.gcp import editor_agent
from encord_agents.gcp.dependencies import dep_single_frame
...
@editor_agent()
def my_agent(
frame: Annotated[NDArray[np.uint8], Depends(dep_single_frame)]
):
assert frame.ndim == 3, "Will work"
Parameters:
-
storage_item
(StorageItem
) –The Storage item. Automatically injected (see example above).
Returns:
-
NDArray[uint8]
–Numpy array of shape [h, w, 3] RGB colors.
Source code in encord_agents/core/dependencies/serverless.py
dep_storage_item
¶
Get the storage item associated with the underlying agent task.
The StorageItem
is useful for multiple things like
- Updating client metadata
- Reading file properties like storage location, fps, duration, DICOM tags, etc.
Example
from typing_extensions import Annotated
from encord.storage import StorageItem
from encord_agents.gcp import editor_agent, Depends
from encord_agents.gcp.dependencies import dep_storage_item
@editor_agent()
def my_agent(storage_item: Annotated[StorageItem, Depends(dep_storage_item)]):
print("uuid", storage_item.uuid)
print("client_metadata", storage_item.client_metadata)
...
Source code in encord_agents/core/dependencies/serverless.py
dep_video_iterator
¶
Dependency to inject a video frame iterator for performing operations over many frames.
Example:
from encord_agents import FrameData
from encord_agents.gcp import editor_agent
from encord_agents.gcp.dependencies import dep_video_iterator
...
@editor_agent()
def my_agent(
video_frames: Annotated[Iterator[Frame], Depends(dep_video_iterator)]
):
for frame in video_frames:
print(frame.frame, frame.content.shape)
Parameters:
-
storage_item
(StorageItem
) –Automatically injected storage item dependency.
Raises:
-
NotImplementedError
–Fails for data types other than video.
Yields:
-
Iterator[Frame]
–An iterator.
Source code in encord_agents/core/dependencies/serverless.py
encord_agents.gcp.wrappers
¶
editor_agent
¶
editor_agent(*, label_row_metadata_include_args: LabelRowMetadataIncludeArgs | None = None, label_row_initialise_labels_args: LabelRowInitialiseLabelsArgs | None = None, custom_cors_regex: str | None = None) -> Callable[[AgentFunction], Callable[[Request], Response]]
Wrapper to make resources available for gcp editor agents.
The editor agents are intended to be used via dependency injections. You can learn more via out documentation.
Parameters:
-
label_row_metadata_include_args
(LabelRowMetadataIncludeArgs | None
, default:None
) –arguments to overwrite default arguments on
project.list_label_rows_v2()
. -
label_row_initialise_labels_args
(LabelRowInitialiseLabelsArgs | None
, default:None
) –Arguments to overwrite default arguments on
label_row.initialise_labels(...)
-
custom_cors_regex
(str | None
, default:None
) –A regex to use for the CORS settings. If not provided, the default regex will be used. Only required if the agent is not deployed on Encord's platform.
Returns:
-
Callable[[AgentFunction], Callable[[Request], Response]]
–A wrapped function suitable for gcp functions.
Source code in encord_agents/gcp/wrappers.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
|