What you need
- Your API key in
CADENYA_API_KEYand a workspace ID inCADENYA_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, inSTATE_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 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
AWAITING 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.
Cancel a runaway
If an objective is going nowhere, cancel it. Cancellation is asynchronous; the objective settles intoSTATE_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 afinalized 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.