Skip to main content
POST
JavaScript
This is the endpoint that puts an agent to work. You name an agent, pass the data its prompt templates need, and Cadenya picks a variation, snapshots the configuration, and starts running. The call returns as soon as the objective is created, in STATE_PENDING. Work happens in the background. Read the result by polling the objective, streaming its events, or receiving webhooks.

The shortest call that works

Two fields are required: agentId and systemPromptData. Pass {} for the data when the agent’s prompt has no template slots.
In bash and zsh, brace the variable before a custom method: write "${OBJECTIVE_ID}:cancel", not "$OBJECTIVE_ID:cancel". The shell reads :c as a modifier and eats it, and the request lands on a path that does not exist.

Where the two messages come from

An objective opens with a system prompt and a first user message. Both render from Liquid templates on the selected variation, and both take their data from this request. Pass neither firstUserMessage nor a variation with a firstUserMessageTemplate and the request fails with InvalidArgument. The rendered results come back on the response as the read-only systemPrompt and firstUserMessage fields.

Pick the variation, or let the agent pick

Omit variationId and the agent’s variationSelectionMode chooses: equal odds under VARIATION_SELECTION_MODE_RANDOM, feedback-weighted odds under VARIATION_SELECTION_MODE_WEIGHTED. Name a variationId and it overrides the mode, which is how you smoke-test a new variation before giving it weight.
Whichever variation wins, the response’s configSnapshot freezes the agent and variation as they were at create time. Edit the variation tomorrow and this objective’s record still shows what ran.

Per-run secrets

secrets scope to this one objective and shadow tool set and workspace secrets on a name clash. Resolution runs objective, then tool set, then workspace. That precedence suits short-lived, per-user tokens: the workspace holds the service credential, the objective carries the caller’s.
Reference the name in an adapter header as ${USER_TOKEN} and Cadenya swaps in the value at call time. Secrets never come back on a read: the response lists their names and nothing else. To see which source won for a given key, read resolvedSecrets on a tool call.

Memory

Two independent controls, both optional. memoryCascade layers memory over the baseline the variation already carries. Array order is resolution order, and earlier elements win. Pin a single entry by passing memoryEntryId alongside its memoryLayerId. The total effective cascade, this field plus the variation’s assignments, caps at 10 entries. episodicMemory.key groups objectives that should share what the agent writes about itself. Objectives created with the same key, for the same agent, read and write one system-managed layer that sits at the most specific end of the cascade. The agent must have enableEpisodicMemory set.
See Memory cascade for how the layers resolve.

What comes back, and what happens next

The response is the objective: metadata.id (an obj_ prefixed ULID), the rendered systemPrompt and firstUserMessage, the configSnapshot, and a state that starts at STATE_PENDING. An objective walks through eight states: The agent’s outputDefinition decides whether an objective ever finalizes. With one, Cadenya extracts a result against that schema when the agent stops working, and the objective reaches STATE_FINALIZED with output populated. Without one, the objective parks in STATE_WAITING instead: it has answered, and it is holding the context window open for your next message. It never finalizes on its own. So if you are polling for a terminal state against an agent that has no outputDefinition, you are waiting for something that never happens. Either declare the schema, or treat STATE_WAITING as done. Cancelling interrupts work in flight. The call returns the objective in whatever state it was in, then the state settles to STATE_CANCELLED a moment later, so read it back rather than trusting the response. Cancelling a STATE_WAITING objective does nothing: there is no work to stop, and it stays waiting. To watch the work as it happens, stream the events rather than polling:
A tool that needs approval parks the objective and emits a toolApprovalRequested event. Nothing moves until you approve or deny the call.

Bring your own ID

Set metadata.externalId here and you never have to store the obj_ ID. Every later call takes external_id:your-value in its place.
Labels come along for the ride: filter the objectives list by them to group runs however your system thinks about them.

Authorizations

Authorization
string
header
required

Bearer authentication header of the form Bearer <token>, where <token> is your auth token.

Path Parameters

workspaceId
string
required
Example:

"workspace_01HXKD2E5NQM3T9AYWCF133E3Q"

Body

application/json
agentId
string
required
Example:

"agent_01HXKD2E5NQM3T9AYWCFMGWT9Y"

systemPromptData
object
required

Arbitrary data rendered into the selected variation's system_prompt_template (liquid) to produce the objective's system prompt. If the agent has a system_prompt_data_schema, this must satisfy it.

variationId
string

Optional explicit variation selection. Overrides the agent's variation_selection_mode.

Example:

"agentvar_01HXKD2E5NQM3T9AYWCF32BSPP"

metadata
object

CreateOperationMetadata contains the user-provided fields for creating an operation. Read-only fields (id, account_id, workspace_id, created_at, profile_id) are excluded since they are set by the server.

firstUserMessage
string

Optional explicit first user message for the LLM chat history. When not set, the selected variation's first_user_message_template is rendered with first_user_message_data instead. If neither this field nor a first_user_message_template is present, the request is rejected with InvalidArgument.

secrets
object[]

Secrets that can be used in the headers for tool calls using the secret interpolation format.

memoryCascade
object[]

Memory layers/entries layered over the baseline cascade inherited from the selected variation — element-level rules over inherited styles, in CSS terms.

Array order is resolution order: EARLIER elements are more specific and are consulted first. Entries pinned via memory_entry_id behave as single-entry layers at their position.

System-managed layers (e.g., episodic) cannot be referenced here; they attach themselves automatically based on the episodic key.

Size cap: the TOTAL effective cascade (this field + the variation's memory layer assignments) must not exceed 10 entries. A request that would produce a larger cascade is rejected with InvalidArgument.

firstUserMessageData
object

Arbitrary data rendered into the selected variation's first_user_message_template (liquid) to produce the first user message. Separate from system_prompt_data, which renders the system prompt template.

episodicMemory
object

If the agent variation that is selected has episodic memory enabled, then this key is used to create/update a memory layer specific to the episodic memory. The layer may have a TTL configured by the variation.

tenant
object

Optional tenant assertion — the customer's org/company identifier for the end user this objective serves. Upserts the tenant record in the workspace and associates the objective with it.

subject
object

Optional subject assertion — the person within the tenant this objective serves. Requires tenant; a subject asserted without a tenant is rejected with InvalidArgument.

pinnedParameters
object

Parameters forced onto this objective's tool calls. A pinned parameter is an overlay on a tool's JSON schema: the parameter is removed from what the LLM sees, and its value is always overwritten server-side with the pinned value — the model cannot choose a different value for it.

Response

OK

Objective is the data for an objective. It contains the snapshotted fields for the selected agent and variation. Secrets are returned only with their names, and the output definition is copied from the agent's configuration.

metadata
object
required

Metadata for ephemeral operations and activities (e.g., objectives, executions, runs)

configSnapshot
object
required

The snapshot of the agent and the variation selected (either explicitly or by sampling) will be set here. Cadenya stores the point-in-time snapshot of the configuration used to start an objective and maintains it throughout the entire lifecycle so that changes to agents and variations in the middle of a cycle don't impact the objective itself

state
enum<string>
required
read-only

The current lifecycle state of the objective.

Available options:
STATE_UNSPECIFIED,
STATE_PENDING,
STATE_RUNNING,
STATE_WAITING,
STATE_FAILED,
STATE_CANCELLED,
STATE_FINALIZED,
STATE_TIMED_OUT
systemPrompt
string
required
read-only

system_prompt is read-only, derived from the selected variation's prompt

firstUserMessage
string
required

The first user message in the LLM chat history, either provided explicitly at creation or rendered from the variation's first_user_message_template.

stateMessage
string
read-only

Optional human-readable detail about the current state (e.g. a failure reason).

info
object

Read-only aggregated info about this objective's execution

parentObjectiveId
string
read-only

A parent objective means the objective was spawned off using a separate agent to complete an objective

Example:

"obj_01HXKD2E5NQM3T9AYWCFQAZGFV"

secrets
object[]

Secrets that can be used in the headers for tool calls using the secret interpolation format.

systemPromptData
object
read-only

Arbitrary data rendered into the variation's system_prompt_template

memoryCascade
object[]

Memory layers/entries layered over the baseline cascade inherited from the selected variation — element-level rules over inherited styles, in CSS terms.

Array order is resolution order: EARLIER elements are more specific and are consulted first. Entries pinned via memory_entry_id behave as single-entry layers at their position.

System-managed layers (e.g., episodic) cannot be referenced here; they attach themselves automatically based on the episodic key.

Size cap: the TOTAL effective cascade (this field + the variation's memory layer assignments) must not exceed 10 entries. A request that would produce a larger cascade is rejected with InvalidArgument.

output
object
read-only

The output of the objective, populated when the objective completes. Will match the schema of output_json_schema or output_json_inferred. This will only be set if the state of the objective is set to STATE_FINALIZED

firstUserMessageData
object
read-only

Arbitrary data rendered into the variation's first_user_message_template

episodicMemory
object

If the agent variation that is selected has episodic memory enabled, then this key is used to create/update a memory layer specific to the episodic memory. The layer may have a TTL configured by the variation.

pinnedParameters
object
read-only

Parameters forced onto this objective's tool calls, as provided at creation. See CreateObjectiveRequest.pinned_parameters for semantics.