Wetel
Go back

Run a workflow from your own system, then collect the result

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:

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 situationUse
A person is typing and expects a replyA chat session
A clock should start the workA scheduled workflow
Your system decides when, and already holds the factsrunWorkflowTask

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": "[email protected]",
"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: customer

Field by field:

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:

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:

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
end

Poll 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:

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?

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).

To start building, read the headless agents guide.


Share this post:

Next Post
How are API keys scoped, and what can a key do?
Previous Post
Building a front desk agent that delegates to specialists, entirely from the dashboard