Define a task
This guide describes best practices for authoring custom task definitions for use in Lattice. Custom task definitions allow you to extend Lattice’s tasking capabilities with your own specialized workflows.
Before you begin
- Familiarize yourself with tasks in Lattice.
- To create tasks, set up your Lattice environment.
- Review the Protobuf files and packages guide to understand Protobuf fundamentals.
Authoring tasks
A custom task is a Protobuf message type that contains the information your asset requires to execute a task autonomously. The complexity of your task definition depends on your integration’s requirements. For example:
- Simple tasks: A sensor may define an on/off toggle message
- Entity-targeted tasks: A tracking system may define a message containing an
entity_idto track - Complex tasks: An autonomous vehicle may define multiple parameters including waypoints, speed limits, sensor configurations, and priority levels
Custom tasks give you the flexibility to model domain-specific workflows while maintaining type safety and compatibility across your Lattice deployment.
Create a package
Define your tasks as Protobuf messages as part of a package. A package should contain all relevant message types to compose tasks that express an integration’s capabilities. Naming your package clearly and precisely is crucial to avoid potential naming conflicts.
Use a consistent package naming pattern: org.repository.package.version
Where:
- org: Your organization name in the Schema Registry.
- repository: Your repository name in the Schema Registry.
- package: A descriptive name for your task domain, for example,
surveillance,navigation, orsensor. - version: The API version, for example,
v1,v2v1alphaorv2test.
During early development, mark your package as unstable by appending a stability marker (alpha, beta, or test) to the version.
The Schema Registry enforces breaking change detection on all packages, regardless of the stability market. If you need to make a breaking
change, you must cut a new version (i.e. v1alpha -> v2alpha).
Fully qualified names
The fully qualified name of a message is the package name with the message name:
For the example above, this would create the fully qualified name: company.isr.imaging.v1test.AerialSurveillance.
All protobuf type URLs are prefixed with type.googleapis.com. You will always reference your task definition by its type URL, for example: type.googleapis.com/company.isr.imaging.v1test.AerialSurveillance.
Globally unique names: Each fully qualified message name must be globally unique within the Schema Registry. This prevents naming conflicts when multiple organizations publish schemas.
For more information about Protobuf packages and naming, see Protobuf files and packages in the Buf documentation.
Breaking change protection
The Schema Registry enforces breaking change detection for all packages. This ensures backward compatibility for consumers of your schemas. You can deprecate old fields, or if necessary, release a new version of your package.
Common breaking changes that are prevented:
- Removing or renaming fields
- Changing field types
- Changing field numbers
- Removing enumerated values
Non-breaking changes that are allowed:
- Adding new fields
- Adding new enumerated values
- Adding new messages
- Deprecating fields (using the
deprecatedoption)
For a complete guide on breaking changes, see the Buf breaking change detector documentation.
Define a custom schema
Protobuf’s Any type enables creating flexible, extensible schemas. It allows you to embed arbitrary serialized protocol buffer messages in an existing schema:
The Lattice SDK uses the Any type as an entrypoint for custom task specifications. Create a new file called surveillance.proto with the following contents:
Best practices
- Use descriptive comments: Document each field and enum value to help other developers understand your schema
- Use wrapper types: For optional numeric fields, use
google.protobuf.*Valuewrapper types instead of primitive types - Start with stability markers: Use
v1alphaorv1betaduring development to allow breaking changes - Reserved field 0: Always reserve enum value
0for anINVALIDorUNSPECIFIEDvariant
Common patterns
On / Off Tasks
Track Entity
Mission Parameters
What’s next?
- Publish your schema to the Schema Registry to make it available for use
- Use your custom definition to create tasks in Lattice
- Configure your agents to listen for tasks assigned to them
- Update task status as your agents make progress on assigned tasks