Messaging

execute

View as MarkdownOpen in Claude

Call a named section as a subroutine. Execution continues in the called section, then returns to the caller when the section completes (via return or by reaching the end of the section).

The destination must be the name of a section defined in the current document — execute does not accept URLs or inline documents in the messaging context.

Properties

execute
objectRequired

An object that accepts the following properties.

execute.dest
stringRequired

Name of the section to execute. Must reference a section defined in the current document.

execute.params
object

Parameters accessible as params.* in the called section. Replaces (does not merge with) any outer params from the caller.

Variables

After the called section completes, execute exposes the following variable in the caller’s context. Variables that the subroutine itself set via reply or requestreply_result, reply_message_id, request_result, request_response, request_response_code, request_response_body — are also propagated back to the caller automatically; see those methods for details.

return_value
any

The value supplied to return inside the called section. Set only when the subroutine called return with an argument. Absent when the subroutine ran to completion without return.

Examples

Calling a subroutine

1version: 1.0.0
2sections:
3 main:
4 - execute:
5 dest: greet
6 params:
7 name: "%{message.from}"
8 - reply:
9 body: "%{return_value}"
10 greet:
11 - return: "Hello, %{params.name}!"

Branch on the subroutine return value

1version: 1.0.0
2sections:
3 main:
4 - execute:
5 dest: classify
6 params:
7 body: "%{message.body}"
8 - switch:
9 variable: return_value
10 case:
11 opt_out:
12 - reply:
13 body: "You've been unsubscribed."
14 help:
15 - reply:
16 body: "Reply STOP to unsubscribe."
17 default:
18 - reply:
19 body: "Thanks for your message!"
20 classify:
21 - switch:
22 variable: params.body
23 transform: lowercase_trim
24 case:
25 stop:
26 - return: "opt_out"
27 help:
28 - return: "help"
29 default:
30 - return: "other"