Skip to main content
An agent sits still until you give it an objective: a message and some data. The agent then works the problem, calling tools and looping until it answers or gets stuck. This page is the objective lifecycle end to end: create, watch, continue, rate.

What you need

  • Your API key in CADENYA_API_KEY and a workspace ID in CADENYA_WORKSPACE_ID.
  • A published agent. The agents guide ships one in five calls. A draft agent refuses objectives with a 400.

Create and watch

Creating an objective returns immediately, in STATE_PENDING. The work happens in the background. The cleanest way to follow it is the event stream, which pushes each message and tool call the moment it lands.
ObjectiveEvent.data is a discriminated union. The switch narrows data to the interface for that event type, so each case exposes only its matching payload.
The stream does not close when the objective finishes. Break on a terminal event type (finalized, cancelled, timedOut, error), never on end-of-stream. A loop with no break holds the connection until the load balancer cuts it at ten minutes. A single connection lives at most ten minutes by design, so a long objective needs the Last-Event-ID reconnect loop.

The states, and the one that traps people

An objective moves through seven states. Four are terminal. STATE_WAITING is the trap. It is not terminal. An agent that answers your message and expects a reply parks in WAITING, and the stream stays open, so a loop that only breaks on terminal events waits forever. When you are driving a conversation, break on the assistant’s message and check for STATE_WAITING; when you expect a structured result, wait for STATE_FINALIZED. An agent with no outputDefinition never finalizes, so it always ends in WAITING.

Continue the conversation

A WAITING objective is a live conversation. Send the next turn with continue, and the agent picks up with everything it already knows.
continue only works on a WAITING objective; on a running one it is a 400 ("objective must be in waiting state to continue"). After it, stream again, or read the event log, to see what the agent did next.
The stream strips tool result bodies to a bare toolCallId so a megabyte of JSON is not pushed through every connection. When you need what a tool returned, read the toolResult event from List objective events, or Get a tool call, which returns the full result.

Rate the result

After an objective ends, score it. Feedback is a number from -1.0 to 1.0 with an optional note, and it feeds the variation’s selection: variations that score well get picked more often under weighted selection.
Feedback appends, it does not overwrite, so one objective can carry several scores from several reviewers. Each one moves the serving variation’s score toward the evidence. This is the loop that lets you run two variations and let the better one win: create objectives, rate them, and weighted selection does the rest.

Cancel a runaway

If an objective is going nowhere, cancel it. Cancellation is asynchronous; the objective settles into STATE_CANCELLED a moment later.

Streaming or webhooks

Both carry the same events. Reach for the stream when a human is watching, a chat UI or a live log, and for a webhook when a machine reacts: deliveries retry and record their status, so a job kicked off by a finalized event is not lost if your handler blips. Use both on one objective when a person watches the work while a system records it.

Use your own IDs

Tag an objective with a ticket number at creation and fetch it back by that, so you never store a Cadenya ID:

Next steps

Get structured output

Give the agent an output schema and read a typed result off the finalized event.

Approve a tool call

Put a human between the agent and a dangerous action.

Delegate to sub-agents

Let an objective spawn child objectives and wait on their results.

Stream objective events

Every event type, the reconnect loop, and what the stream strips.