Dependencies
When writing agents, you often rely on common resources, whether data for running your agent or for recording the output. Encord Agents use dependency injection to declaratively acquire these resources, so you can focus on developing your agent instead of writing boilerplate to set them up manually.What is Dependency Injection?
Dependency injection means your code (in this case, your path operation functions) can declare what it needs to function — its “dependencies.” The system (e.g., FastAPI or encord-agents) then takes care of providing your code with those dependencies (“injecting” them). We follow the same pattern as FastAPI Dependencies, where you can find more examples.Injecting Dependencies
When defining your agents, you can inject essential dependencies, such as the path to the underlying asset or frame iterators. You can also add custom dependencies if needed. To inject dependencies, type-annotate your agent function variables using theDepends class. In the example below, replace {module} with the type of agent you’re building:
Custom Dependencies
To add a custom dependency:dep_video_iterator for an example of this.
Custom Agents Specification
This section defines the interface for Custom Agents. Use it to define agents via the library or when writing your own implementation.Schema
objectHashes field is optional — when present, it’s a list of strings.
Test Payload
When you register your Custom Agent in the platform’s Custom Agents section, you can test it with a test payload.- If you modify the test payload, the platform verifies that your agent has access to the associated project and data.
- If you leave it unmodified, the platform instead sends a distinguished
X-Encord-Agentheader, which automatically triggers an appropriate response.
Webhook Security
Encord provides webhook signing secrets to verify the authenticity of requests sent to your custom agent endpoints. Each custom agent endpoint receives a unique signing secret you can use to validate incoming webhook payloads. To access your signing secret:- Navigate to your Workflow configuration in Encord.
- Select your custom agent node.
- Locate the Signing secret section.
- Use the eye icon to reveal the secret, or the copy icon to copy it to your clipboard.
The signing secret is automatically generated when you configure your custom agent endpoint URL. Save your workflow after changing the URL to update the secret.
Response
The platform displays your agent’s output using the AgentResponse type, making your agents more interactive and informative. For example, if the label state doesn’t meet the Custom Agent’s expectations, or if the agent’s function is to check the validity of current labels, the response type lets you communicate that information to the annotator.Error Handling
Raise anEncordAgentException to handle errors appropriately. For example, if your agent expects polygons but receives a skeleton, use it to return an informative error to the Encord platform.
If an authorization issue occurs with the Encord platform (for example, a request tries to access a project the agent doesn’t have access to), the response body includes the authorization message in an AgentErrorResponse type:

