Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

fix(backend): Handle manual run attempts for triggered agents (#12298)

Ottoc304a4937a2c
diff --git a/autogpt_platform/backend/backend/data/execution.py b/autogpt_platform/backend/backend/data/execution.py
index 2f9258dc55..45669124d6 100644
--- a/autogpt_platform/backend/backend/data/execution.py
+++ b/autogpt_platform/backend/backend/data/execution.py
@@ -344,7 +344,7 @@ class GraphExecution(GraphExecutionMeta):
),
**{
# input from webhook-triggered block
- "payload": exec.input_data["payload"]
+ "payload": exec.input_data.get("payload")
for exec in complete_node_executions
if (
(block := get_block(exec.block_id))
diff --git a/autogpt_platform/backend/backend/executor/utils.py b/autogpt_platform/backend/backend/executor/utils.py
index cc94ff8b4b..2f7706f932 100644
--- a/autogpt_platform/backend/backend/executor/utils.py
+++ b/autogpt_platform/backend/backend/executor/utils.py
@@ -481,6 +481,22 @@ async def _construct_starting_node_execution_input(
if nodes_input_masks and (node_input_mask := nodes_input_masks.get(node.id)):
input_data.update(node_input_mask)
+ # Webhook-triggered agents cannot be executed directly without payload data.
+ # Legitimate webhook triggers provide payload via nodes_input_masks above.
+ if (
+ block.block_type
+ in (
+ BlockType.WEBHOOK,
+ BlockType.WEBHOOK_MANUAL,
+ )
+ and "payload" not in input_data
+ ):
+ raise ValueError(
+ "This agent is triggered by an external event (webhook) "
+ "and cannot be executed directly. "
+ "Please use the appropriate trigger to run this agent."
+ )
+
input_data, error = validate_exec(node, input_data)
if input_data is None:
raise ValueError(error)