Most offices have an in-tray. Someone drops a work order in it with everything the job needs written on the form: the reference number, the customer’s email, the attached document. Nobody stands at the desk waiting. Later they come back and collect the finished work, or a note saying why it could not be done.
That is the shape of a workflow task on Wetel. Your own system (a nightly job, a form handler, another service) drops a work order in with runWorkflowTask, and an AI employee runs its published workflow on it. Later your system collects the outcome with workflowTaskOutcome. No person chats with anyone along the way. The workflow itself was built and published by people on your team, in a workspace an owner is responsible for; the task only decides when it runs and with which facts.
This post is for the developer wiring it up. Everything below comes from the workflows API reference and the headless agents page.
When should I use a task instead of a chat or a schedule?
Use a task when your system already has the facts, nobody is waiting on a reply, and you can call from a server. The reference puts it as three conditions that must all be true:
- The values the workflow needs are already resolved on your side (an id you looked up, a URL you already hold), so no language model has to dig them back out of message text.
- There is no end user waiting for a conversational reply.
- You can authenticate server-side with an API key. There is no browser-safe version of this call.
If any of those is false, use a chat session instead (sdkStart and sdkSendMessage). If all you need is “run this every weekday at 9am”, a scheduled workflow does it without your own scheduler, and each fire starts the same kind of run.
| Your situation | Use |
|---|---|
| A person is typing and expects a reply | A chat session |
| A clock should start the work | A scheduled workflow |
| Your system decides when, and already holds the facts | runWorkflowTask |
What does the call look like?
It is one GraphQL mutation, authenticated with your API key only (a dashboard login is not accepted). The workspace comes from the key itself, so the input has no workspace field, and a key can only ever run its own workspace’s agents. You name the agent, never a workflow: the agent’s currently published workflow is what runs, exactly as for a chat turn.
This is the example from the reference, unchanged:
mutation RunWorkflowTask($input: RunWorkflowTaskInput!) { runWorkflowTask(input: $input) { sessionId workflowId agentId turnCount reusedSession accepted }}{ "input": { "agentId": 12, "externalConversationId": "orchestrator:conversation:EXAMPLE-8f3c1a", "variables": { "jobPostingId": 19, "companyId": 20, "candidateEmail": "applicant@example.com", "sourceChannel": "web" }, "attachmentUrl": "https://files.example.com/uploads/EXAMPLE-8f3c1a/resume.pdf", "attachmentFilename": "applicant-resume.pdf", "attachmentMime": "application/pdf", "clientTurnId": "task-EXAMPLE-0001" }}Headers:
X-Api-Key: <your-api-key>x-huat-platform: customerField by field:
agentIdmust be anACTIVEagent with a workflow attached, or the call is refused.externalConversationIdis your own reference for this piece of work (up to 255 characters): an order number, a ticket id. It decides which session the task runs on (more below). It is stored as you send it, so never put anything sensitive in it.variablesare the facts written on the work order.attachmentUrl,attachmentFilenameandattachmentMimepass one file the workflow can fetch; the URL must be reachable by Wetel’s backend. The mime type is optional and is worked out from the filename’s extension, then the URL’s. A newerattachmentslist takes up to 10 files instead; send one form or the other, never both. The changelog has the details.clientTurnIdis an optional token echoed back on any reply event the run publishes. It is not stored.
What can I put in variables?
A flat map of simple values, each of which reaches the run unchanged under a name your steps can read as {{jobPostingId}} in a template or jobPostingId > 0 in a condition. The call checks the shape and nothing more:
- At most 32 keys, each a bare word starting with a letter (
foo-barandfoo.barare not usable names). - Values are scalars only: string, number, boolean or
null. Nested objects and arrays are refused, so flatten structure into separate keys. - Strings are capped at 4,096 characters, and numbers must be finite.
- Reserved names are refused with a
400, not dropped quietly:sessionId,userMessage,attachment,attachmentUrland the others listed in the reference, plus any key starting with_.
Because the call never checks what a value means, the graph has to. Put a condition step in front of any step that writes to another system, and write the gate as someId > 0, never someId != 0. Conditions do not convert types, so the string "0" passes a != 0 test; > 0 handles numbers, numeric strings, empty strings and a variable you never sent.
How do I get the result?
Poll for it, using the sessionId the call returned and the same API key. A successful return from runWorkflowTask means only that the task was validated and queued. accepted: true is not “it worked”, and there is deliberately no error for “the workflow failed”, because the run has not started when the call returns. A graph that fails, or that takes a polite “I can’t do that” branch, still returns accepted: true.
query TaskOutcome($sessionId: Int!) { workflowTaskOutcome(sessionId: $sessionId) { sessionId status runs { id status errorMessage } replies { text } }}How to read it:
statusis the newest run’s status.nullmeans still queued;PENDINGandRUNNINGmean keep polling;COMPLETEDmeans the graph reached its end;FAILED,INTERRUPTEDandAWAITING_INPUTare the other end states.runslists the session’s runs, newest first, at most 20. A failed run carries anerrorMessagewith anything that looks like a credential masked, cut to 300 characters.repliesis what the workflow’sresponsesteps said, oldest first, at most the latest 10.
It never returns the run’s context or its step-by-step trace. Those come from workflowRuns(sessionId), which needs a dashboard login, so that is where a person on your team goes to see why a run failed. Only a session that a task was accepted for can be read this way; any other id answers not found.
sequenceDiagram participant Y as Your system participant W as Wetel Y->>W: runWorkflowTask (API key, agentId, variables) W-->>Y: sessionId, accepted: true Note over W: The run starts from the queue loop Poll with a back-off Y->>W: workflowTaskOutcome(sessionId) W-->>Y: status, runs, replies endPoll with a back-off rather than in a tight loop. Both calls share one rate limit, covered below.
What if I send the same task twice?
It runs twice. The docs describe no de-duplication of repeated calls: each accepted call is a new run. What decides is the session:
- If there is no active session for your workspace, that agent and that
externalConversationId, a new one is created (reusedSession: false,turnCount: 1). - If one is active, the task joins it (
reusedSession: true) andturnCountgoes up. Every task for that reference lands on one timeline.
So a retry with the same reference adds a second run to the same session; it does not replace the first. A second task on the same session does not cut a first one short either. Use one stable reference per piece of work, never the same string for unrelated work (their runs pile onto one session), and remember that a session with no activity for 30 days expires, so a reference you reuse after that starts a fresh session.
If your system retries a call that timed out, it may not know whether the first one was accepted. Design for that: make the workflow safe to run twice, for example by having it check the target system before it writes.
Wetel does keep an invocation record of every call: the agent, the source, your reference, the names of the variables (never their values), and whether the call was accepted or refused with a short code. It is there so support can answer “what did this integration fire?”. There is no customer-facing query for these records yet, so it is not something your code can use to spot duplicates.
What can a task run not do?
Three things, and the graph has to be designed around them.
There is no user message. The run starts with userMessage as an empty string and no conversation history. Anything the steps need comes from your variables, the attachment, or steps that fetch it.
Nobody is waiting. No chat window is listening. A response step’s text is saved and shows up in replies, which your system can read when it polls, but it reaches no person by itself.
Delivery is the graph’s job. If the result should land somewhere (a record updated, a team notified), a step must send it: usually a webhook step or an action step at the end. Wetel cannot push the outcome to a URL you register; outbound webhooks are not built.
What limits and costs apply?
- Rate limit: 60 requests per 60 seconds per client IP address, for
runWorkflowTaskandworkflowTaskOutcometogether, not per key or per workspace. It is looser than the session-start limit because a machine legitimately sends bursts, such as draining a queue. - Input limits: the variable and attachment rules above.
- Spend: the monthly language-model spend cap on your plan is checked before each task starts, and once it is reached new tasks are refused until the month rolls over or the plan changes. It is a check before work starts, not an exact meter: a run already under way can carry spend past it, and speech and tool-call usage do not count toward it. See Pricing & Plans for the cap on each tier.
How do I test it safely?
runWorkflowTask always runs the agent’s published workflow; it has no draft option. So test the graph as a draft first, in a test session, as described in how do I try a workflow safely, then publish. Plan as if every step that calls another system runs for real, in a draft test and in a task alike: point the first tasks at a test agent whose steps call test endpoints, and only then at the agent that writes to production records.
What is live, and what is not built?
Live today: runWorkflowTask with variables and attachments, workflowTaskOutcome with the same API key, session reuse by your own reference, and the invocation record kept for support. The changelog tracks each change as it lands.
Not built yet: Wetel pushing a task’s outcome to your URL, a customer-facing view of invocation records, and starting a workflow because something happened in another system (event triggers, on the roadmap as direction).
Related reference docs
runWorkflowTask: every field, the starting context and the errorsvariablesrules: key names, value types and reserved names- Session reuse: how your reference picks a session
- What Wetel records about each call: the invocation record
workflowTaskOutcome: reading the result with the same API key- Rate Limiting: Workflow tasks: the shared per-IP limit
- Authentication: API keys, and why they never go in a browser
- Response Node: what a
responsestep sends and saves - Observability & Debugging: reading a run’s trace with a dashboard login
- Scheduled workflows: the timer-driven version of the same run
To start building, read the headless agents guide.