onTask in managed/agent.ts, which hands them to the harness:
onTask(name, payload, info) overrides the runtime SDK’s onTask(), the fallback for a task whose name is not a method of the class.
- The harness’s task names start with
HARNESS_TASK_PREFIX,__telnyx_agent_harness_, and name no method of the class, so the tasks arrive here. DELIVERY_TASK,__telnyx_acp_deliver, is the next try at a reply the channel refused; Delivery has the window.- Any other task goes to
super.onTask, the runtime’s default, which treats it as delivered.
this.messages.last() is last() on the message log. Runs are dispatched one at a time, so every message past the seq it returns is this run’s.
harness.dispatch({ name, payload }) is dispatch().
nameandpayloadare the task as the harness queued it.- It executes the run’s turn and returns the run’s
HarnessRunas the turn left it.
dispatch, three things happen.
- The model is called with the instructions and the conversation’s message log.
- Tools run, subject to their approvals.
- Each assistant message is appended to the log as it lands.
dispatch returns, noteRun writes the outcome to state, through the runtime SDK:
getState()returns the runs already noted, so a redelivered task does not note a run twice.last()returns the newest message. It is the reply only when itsseqis pastbefore, its role isassistantand it has text.now()is the time a completed or failed outcome records asat.setState()merges the patch. Anullin it deletes a key, as it deletesawaitingApprovalRunIdonce that run ends.
The state stream carries each of these, which is how
invoke ends with a reply, or with a line that says why there is none. With memory on, a completed run’s exchange is pushed to Agent Memory under the run’s id. Delivery is the last step.