How To Call It
Agent is a global table: call its functions with a dot (Agent.<method>(...)), not a colon. Requires Macro Handler 1.0.51 or later.
Runs the approved routine or plan of an enabled Agent block saved in this macro. Uses the same macro-start consent, stop rules and failure behavior as the block, returning a structured result.
Documented for app version 1.0.50Updated:
Agent is a global table: call its functions with a dot (Agent.<method>(...)), not a colon. Requires Macro Handler 1.0.51 or later.
Use this to combine a saved Agent/Routine step with code-editor conditions and loops. This call does not teach or approve a new routine.
Agent.run(blockId): pass the literal string id of an enabled Agent block saved in this macro. Launch admission resolves that id; computed ids or function aliases do not create grants. Returns ok, outcome, taps, detail, kind (routine/plan/none). Settings come from the saved block and approved plan; extra arguments do not override them.
Check outcome as well as ok: completed_unverified and completed_with_skips can also return ok=true. Stop on failure raises AGENT_MACRO_STOP; Continue returns the result table. A user stop also stops the macro. Previews and observed tests do not start Agent actions.
The snippet below is a starter pattern that can be applied directly in runtime flow.
-- Use a literal id from an enabled Agent block saved in this macro.
-- Its routine/plan must be approved; launch consent is still required.
local result = Agent.run("saved_agent_block_id")
if result.ok then
print(result.outcome, result.taps)
else
print(result.outcome, result.detail, result.kind)
endFrom foundation to combined usage, each level is provided as a separate code block so you can copy the level you need and adapt it directly.
-- Use a literal id from an enabled Agent block saved in this macro.
-- Its routine/plan must be approved; launch consent is still required.
local result = Agent.run("saved_agent_block_id")
if result.ok then
print(result.outcome, result.taps)
else
print(result.outcome, result.detail, result.kind)
endlocal stepOk = true
-- Use a literal id from an enabled Agent block saved in this macro.
-- Its routine/plan must be approved; launch consent is still required.
local result = Agent.run("saved_agent_block_id")
if result.ok then
print(result.outcome, result.taps)
else
print(result.outcome, result.detail, result.kind)
end
if stepOk then
wait(200)
endlocal ok, err = pcall(function()
-- Use a literal id from an enabled Agent block saved in this macro.
-- Its routine/plan must be approved; launch consent is still required.
local result = Agent.run("saved_agent_block_id")
if result.ok then
print(result.outcome, result.taps)
else
print(result.outcome, result.detail, result.kind)
end
end)
if not ok then
print("API step failed: Agent.run: " .. tostring(err))
requestStop()
end-- The saved plan, launch consent and run-bound grant are shared with the no-code Agent block.
local function run_run_step()
-- Use a literal id from an enabled Agent block saved in this macro.
-- Its routine/plan must be approved; launch consent is still required.
local result = Agent.run("saved_agent_block_id")
if result.ok then
print(result.outcome, result.taps)
else
print(result.outcome, result.detail, result.kind)
end
end
local ok, err = pcall(run_run_step)
if not ok then
toast("Step failed")
print(err)
end-- Use a literal id from an enabled Agent block saved in this macro.
-- Its routine/plan must be approved; launch consent is still required.
local result = Agent.run("saved_agent_block_id")
if result.ok then
print(result.outcome, result.taps)
else
print(result.outcome, result.detail, result.kind)
end