Lesson 07 — Second agent, stage, and runbook

You are here: Lesson 7 of 8 · ← Workflow · Hub · Next: Attach runbook →

Goal

Add a specialist agent (aac-researcher), a second stage (research), a second runbook, and order the stages with stage_depends_on.

What you will change

  • New sg_agent.researcher + persona
  • New sg_runbook_sop.research
  • Extend sg_workflow stages and bindings
  • Full root: steps/07-multi-agent/

Why it matters

One agent for every job becomes a muddled persona. Split by outcome: greeter vs researcher, planner vs implementer. Workflows stitch them in order.

ELI5: Two coworkers, two desks. The greeter says hello first; then the researcher looks things up. The workflow is the hallway that sends work in that order.

HCL — second agent and dependent stage

resource "sg_agent" "researcher" {
  name         = "aac-researcher"
  persona      = file("${path.module}/personas/aac-researcher.md")
  model_names  = [sg_llm_model.gpt54.name]  # or local.model_names from the step root
  integrations = [sg_integration.github.name]
  knowledge = {
    memory_enabled = true
  }
}

resource "sg_runbook_sop" "research" {
  name        = "aac-research"
  approve     = true
  description = trimspace(templatefile("${path.module}/templates/research.md", {}))
}

# Inside sg_workflow.tutorial:
stages = [
  { stage_id = "greet",    description = "...", required = true },
  { stage_id = "research", description = "...", required = true },
]

stage_bindings = [
  {
    stage_id     = "greet"
    agent_ref    = sg_agent.tutor.name
    runbook_refs = [sg_runbook_sop.greet.name]
    skill_refs   = ["aac-hello"]
  },
  {
    stage_id         = "research"
    agent_ref        = sg_agent.researcher.name
    stage_depends_on = ["greet"]
    runbook_refs     = [sg_runbook_sop.research.name]
  },
]

Different agents often get different HITL / integration scopes — keep researcher tools narrow.

Apply & verify

cd examples/scenarios/agent-as-code/steps/07-multi-agent
tofu init && tofu apply
tofu output agent_names

Arrange: Both agents visible; workflow shows two stages.

Sample prompt (run aac-tutorial-workflow):

Say hello with the tutorial skill, then summarize what Agent as Code means from project knowledge in one short paragraph.

Assert: Greet stage finishes first; research stage produces a short knowledge-based paragraph (or an honest empty-KB message).

Gotchas

  • Same agent can own multiple stages later; here we use two agents on purpose.
  • Forgetting stage_depends_on can allow parallel execution when you wanted a sequence.
  • Update personas when roles diverge — do not overload one file.

Checkpoint

  • aac-researcher exists
  • Workflow has greet → research
  • One multi-stage run completed in order

Next: Lesson 08 — Attach a runbook