⚠️ Experimental — This resource is part of the Guild platform and may change in future releases.
Manages a workflow — a unified playbook that combines stage definitions, agent bindings, triggers, and governance references into a single draft resource.
Set approve to true to promote draft or deprecated versions to approved after apply (Guild only allows one approved version per workflow; approving deprecates the previously approved one).
Create-time 409 adoption after a successful read is controlled by the provider attribute adopt_on_conflict (default true).
# When to use: Multi-stage agent playbook (RCA, remediation, audits). Prefer a
# workflow over a single agent when you need ordered stages, runbook refs,
# evidence checklists, or event-driven triggers.
#
# Prerequisites: agents referenced in stage_bindings (or create them in the same
# stack). Set approve = true so drafts are not left pending in the UI.
#
# Related: sg_agent, sg_runbook_sop (runbook_refs), sg_evidence_checklist,
# sg_remediation_pattern, sg_webhook / sg_agent_schedule (triggers),
# sg_action_type (custom stage actions).
#
# See also: resource_with_triggers.tf and examples/workflow/main.tf.
resource "sg_workflow" "example" {
name = "example-triage"
domain = "incident-response"
approve = true
stages {
stage_id = "triage"
description = "Initial classification and routing."
required = true
}
}
# When to use: Event-matched workflow (PagerDuty/Datadog-style ingress). Pair
# with sg_webhook (HTTP) or an app-managed ingest path. Bind each stage to an
# agent_ref; optional runbook_refs point at sg_runbook_sop names.
#
# stages / stage_bindings: stage_id must match between the stage definition and
# its binding. Keep stage_ids stable — renaming forces rebinding.
resource "sg_agent" "lead" {
name = "workflow-lead"
}
resource "sg_workflow" "event_driven" {
name = "pagerduty-bridge"
domain = "incident-response"
description = "Matches incoming PagerDuty-style events."
approve = true
# Optional: link SOPs / evidence for the whole playbook.
# runbook_refs = ["database-failover"]
# evidence_checklist_ref = "post-incident-review"
triggers {
field = "source"
values = ["pagerduty"]
type = "active"
source = "pagerduty"
}
stages {
stage_id = "ack"
required = true
}
stage_bindings {
stage_id = "ack"
agent_ref = sg_agent.lead.name
note = "Acknowledge and summarize the incident."
}
}
Import an existing sg_workflow using its workflow name or UUID:
terraform import sg_workflow.example 'incident-triage'
A workflow UUID can also be used; the provider resolves it to the unique workflow name via ListWorkflows (there is still no Guild get-by-UUID API).
terraform import sg_workflow.example '11111111-1111-1111-1111-111111111111'
Import accepts a workflow name or UUID. UUID import resolves the name via paginated ListWorkflows (Guild still has no get-by-UUID API); state stores the name for later reads.
domain (String) Business domain (e.g. incident-response or deployment).name (String) Unique workflow name. Changing forces replacement.approve (Boolean) When true, promotes the workflow version after create or update via the Guild approve API (draft or deprecated → approved) so operators do not need the UI. Omit or set to false to leave non-approved versions pending. No-op when the version is already approved; the API returns 400 if approve is called again.description (String) Human-readable intent for this workflow.escalation_policy_ref (String) Escalation policy reference.evidence_checklist_ref (String) Name of an sg_evidence_checklist resource. Applies to the entire workflow (workflow-wide proof-of-work), not to individual stages.example_queries (List of String) Example prompts used to match this workflow.metadata (Attributes) Runtime tuning for workflow execution (planner iteration cap, HalGuard skip list). (see below for nested schema)optional_inputs (List of String) Optional inputs that improve output quality.remediation_pattern_refs (List of String) Linked remediation pattern names.required_inputs (List of String) Inputs required to run this workflow.runbook_refs (List of String) Linked runbook names.stage_bindings (Attributes List) Agent and policy bindings per stage. Supports fan-out/fan-in DAG topologies via stage_depends_on. (see below for nested schema)stages (Attributes List) Stage definitions for this workflow. (see below for nested schema)triggers (Attributes List) Trigger conditions for automatic workflow selection. (see below for nested schema)id (String) Server-assigned identifier.status (String) Draft lifecycle state for the editable workflow.metadataOptional:
halguard_skip_subagent_task_types (String) Comma-separated task_type values for which HalGuard PreCheck is skipped on create_agent sub-agents (e.g. terminal_calling). PostCheck still runs.planner_max_tool_iterations (Number) Raises the stage planner create_agent / note / read_notes iteration cap for heavy workflows.planner_min_tool_calls (Number) Requires at least this many planner tool calls before a zero-tool iteration may end the adaptive loop.tool_middleware (Attributes) Per-workflow tool middleware overrides merged onto the agent config for this run only. (see below for nested schema)metadata.tool_middlewareOptional:
circuit_breaker (Attributes) Circuit breaker overrides for this workflow run. (see below for nested schema)concurrency (Attributes) Concurrency limits applied for the duration of this workflow run. (see below for nested schema)metadata.tool_middleware.circuit_breakerOptional:
enabled (Boolean) Whether circuit breaker overrides are enabled for this workflow run.failure_threshold (Number) Open after this many consecutive tool failures.open_duration (Number) Duration in nanoseconds to stay open.metadata.tool_middleware.concurrencyOptional:
enabled (Boolean) Whether concurrency limiting is enabled for this workflow run.global_limit (Number) Maximum concurrent tool calls across all tools.per_tool_limits (Map of Number) Per-tool concurrent call limits keyed by tool name.stage_bindingsOptional:
action_config (Map of String) Configuration specific to the action_type.action_type (String) When set, this stage executes a deterministic action instead of delegating to an LLM agent.agent_ref (String) Name of the hired agent assigned as the primary lead. When omitted the runtime auto-resolves the best-fit agent.note (String) Operator-authored step note that explains what to expect and why this step is being run. The runtime injects this note into the stage agent prompt context.parallel_agents (List of String) Agents that run concurrently during this stage alongside the primary.runbook_refs (List of String) RunbookSOP names to inject into the agent prompt for this stage.skill_refs (List of String) Per-stage skill names. Guild directs the stage agent to load_skill for each before work (SKILL.md) instead of search_skill discovery.spawn_contracts (Attributes List) Per-stage create_agent contracts applied by Guild stagerunner. (see below for nested schema)stage_depends_on (List of String) Stage IDs that must complete before this stage runs. Set explicitly to model fan-out/fan-in DAG topologies.stage_id (String) Stage identifier (matches WorkflowStage.stage_id).stage_bindings.spawn_contractsRequired:
sub_agent_name (String) Sub-agent name passed to create_agent (retry suffixes match).Optional:
context (String) Optional context prepended for the sub-agent.goal (String) Mandatory goal patched onto create_agent. Supports and placeholders.max_llm_calls (Number) Maximum LLM turns for this sub-agent.max_tool_iterations (Number) Maximum tool iterations for this sub-agent.summarize_output (Boolean) When true (recommended), large sub-agent output is summarized before returning to the stage planner. Guild defaults to true when omitted. Set false only when the parent must retain the full raw child output.task_type (String) Genie task type (terminal_calling, coding, efficiency, planning).timeout_seconds (Number) Sub-agent wall-clock timeout in seconds.tool_names (List of String) Allowlisted tool names for the sub-agent.stagesRequired:
stage_id (String) Unique stage identifier within the workflow.Optional:
description (String) Human-readable description of what this stage does.note (String) Operator note for this step explaining expectations and rationale. This note is injected into the stage agent prompt context during runtime.required (Boolean) Whether this stage must complete for the workflow to succeed.triggersOptional:
field (String) What is being matched (e.g. incident_title_contains).source (String) Event source filter for active triggers (e.g. pagerduty).type (String) passive (vector-search metadata) or active (event-driven).values (List of String) Matching values for the field.