Skip to content

Tutorial 2 — Content Review Workflow

What you'll learn

  • Multi-agent delegation with subagents: frontmatter
  • Both output_schema styles: inline JSON Schema and a Pydantic dotted-path contract
  • Custom tools with @tool
  • Compile-time context injection (context/)
  • Transformer chains declared directly on an agent: PII redaction, JSON extraction, LLM quality gates
  • Free checks (contains, matches, json_schema, python) next to judged says in one test suite

Time: ~15 minutes. No Slack or Jira credentials needed.


1. Create the project

mkdir content-review && cd content-review
abt init --template intermediate --no-handlers

(Handlers are off by default, so the generated files match this walkthrough. The tour trims some descriptions and skips macros/formatting.md, a small Jinja macro file. Add --with-handlers if you want to see the handlers/ lifecycle-hook example too.)

Edit profiles.yaml if you need a different model; the default stub uses Anthropic and reads ANTHROPIC_API_KEY:

# profiles.yaml  (gitignored)
content-review:
  target: dev
  outputs:
    dev:
      model_id: anthropic:claude-haiku-5-5
      max_tokens: 4096
      credentials:
        anthropic:
          api_key: "{{ env_var('ANTHROPIC_API_KEY') }}"

2. Tour the generated files

Data flow

flowchart LR
    Task["prompts/review_task.md"] --> Reviewer
    Reviewer -->|"delegates"| Analyst
    Analyst -->|"facts/summary/confidence/complexity JSON"| Reviewer
    Reviewer -->|"ReviewResult JSON"| Extract["validate_json<br/>(json_extract)"]
    Extract --> PII["redact_pii<br/>(pii_redact)"]
    PII --> Guard["quality_gate<br/>(llm_guard, warn)"]

There are two stages, both declared directly on agents/reviewer.md: the delegation tree (reviewer + analyst, via subagents:) and the transformer chain (post-agent text processing, via transformers:) that runs after the reviewer finishes and before any of its own exposures would dispatch. Transformers run under abt dispatch; abt run skips them. json_extract runs before pii_redact so redaction can't mutate quoted JSON punctuation (for example a redacted email inside a string) and break parsing.

agents/reviewer.md

---
description: >
  Reviews content quality. Delegates fact extraction to the analyst,
  then emits structured JSON via a Pydantic output contract.
tools:
  - word_count
output_schema: review_result.ReviewResult
subagents:
  - analyst
transformers:
  - validate_json
  - redact_pii
  - quality_gate
middleware:
  - run_timeout:
      graceful_timeout_seconds: 120
  - model_call_limit:
      max_model_calls: 5
---

## Style guide

{{ context.local('review/style_guide') }}

## Delegation

When you need extracted facts before judging, involve the `analyst`.

You are reviewing content on behalf of {{ var('reviewer_org') }}.
You are the reviewer. Output JSON only matching your output_schema (score, verdict, issues).
Use the analyst's output and the style guide. If you use word_count, call it at most once.

Key things to notice:

  • output_schema: review_result.ReviewResult — tells abt to validate the agent's final output against the ReviewResult Pydantic model in contracts/review_result.py. Dotted path: module.ClassName.
  • subagents: [analyst] in the frontmatter registers analyst as a delegate the reviewer's LLM may call as a tool — delegation is declared structurally, there is no Jinja body call for it. abt run -s reviewer runs the reviewer plus its full subagents: tree, unbounded; there's no flag to isolate the reviewer alone.
  • transformers: [validate_json, redact_pii, quality_gate] is the reviewer's own post-processing chain — no separate wrapper file. Each transformer name resolves to a standalone transformers/*.yaml catalog file (see below); they run in list order after the reviewer's own turn finishes. The reviewer has no prompts: field — its user message comes from an explicit -p review_task (or any other -p) on abt run.
  • {{ context.local('review/style_guide') }} injects context/review/style_guide.md at compile time — not fetched at runtime.
  • {{ var('reviewer_org') }} is substituted at compile time from abt.yaml → vars: reviewer_org: <your-team-name> (or overridden per run with --vars) — the same {{ var() }} mechanism covered in the Quickstart.
  • run_timeout / model_call_limit middleware — guardrails. abt doctor will warn if a tool-using agent omits these.

agents/analyst.md

---
description: Extract key facts and a one-paragraph summary from the user's document.
tools: []
output_schema:
  title: AnalysisResult
  properties:
    facts:
      type: array
      items:
        type: string
      description: Key factual statements extracted from the document.
    summary:
      type: string
      description: A one-paragraph summary of the document.
    confidence:
      type: number
      description: How confident you are in this analysis, from 0 (low) to 1 (high).
    complexity:
      type: number
      description: >-
        How hard the document was to analyze, from 0 (straightforward) to 1
        (highly complex, no clear answer).
few_shots:
  - analyst_example.yaml
---

You are the analyst. Read the user message (the document to analyze).
Reply with JSON only matching your output_schema (facts, summary, confidence, complexity).

Key things to notice:

  • output_schema: is an inline JSON Schema, not a Python class — the fastest way to see structured output working. Every field's description is part of the contract: the model reads it like an instruction.
  • confidence and complexity aren't extracted from the document — they're the model's own self-assessment. They show what structured output is for beyond "shape the JSON": you can ask the model to grade its own answer on axes you define.
  • few_shots ground the model with a trajectory example — especially useful for structured JSON output.

contracts/review_result.py

# contracts/review_result.py
from pydantic import BaseModel

class ReviewResult(BaseModel):
    score: float
    verdict: str
    issues: list[str]

A plain Pydantic model — no __init__.py needed in contracts/. The analyst doesn't need one: its inline schema above is resolved into a model at compile time without a file on disk. After a successful run, target/run_results/<run_id>/run_results.json includes a structured key with the validated model_dump() dict for both agents.

How output_schema resolves

A dict value (like the analyst's) is built into a Pydantic model directly from the JSON-Schema-like properties:. A string value (review_result.ReviewResult) splits on the last . to get the module path (review_result) and class name (ReviewResult), then loads that module from contracts/review_result.py. Reach for the dotted-path form when you need a custom type, cross-field validation, or a @field_validator — see the structured outputs guide. Either way, validation happens after the stream finishes — a validation failure makes the run ok: false with field-level errors.

context/review/style_guide.md

# Editorial style

- Prefer clear, neutral tone.
- Flag missing citations for quantitative claims.
- Treat contact emails as sensitive in downstream channels (PII).

Context files are resolved at abt compile time and stored in target/manifest.json. If you update them, re-run abt compile to pick up changes. Use {{ context.local('name', max_chars=3000) }} to cap large documents.

Context vs vars vs sources

  • context/ — static reference docs baked in at compile time (runbooks, style guides, API specs)
  • {{ var('x') }} — values that change between runs, passed via --vars or abt.yaml vars:
  • sources/ — live data fetched per run (Slack thread, Jira ticket, webhook payload)

tools/word_count.py

from abt import tool

@tool
def word_count(text: str) -> str:
    """Return the number of whitespace-separated words in text."""
    return str(len(text.split()))

Any Python file in tools/ with a @tool-decorated function is auto-discovered. The tool name is the function name. List it in the agent's tools: frontmatter to make it available.

few_shots/analyst_example.yaml

- human: |
    Document: We shipped v2 on time. No blockers.
- agent: |
    {"facts": ["v2 shipped on time", "no blockers reported"],
     "summary": "Release completed without issues.",
     "confidence": 0.9,
     "complexity": 0.1}

Few-shot files provide input/output trajectory examples for the model. They are especially effective when you need a specific JSON shape reliably.

The reviewer's transformer chain

Each entry in the reviewer's transformers: list resolves to a standalone catalog file:

# transformers/validate_json.yaml
name: validate_json
description: Extract canonical JSON from the reviewer's output (must run before redact_pii).
type: json_extract
# transformers/redact_pii.yaml
name: redact_pii
description: Redact emails and phone numbers from the reviewer's output.
type: pii_redact
config:
  types: [email, phone]
  strategy: redact
# transformers/quality_gate.yaml
name: quality_gate
description: Optional LLM quality gate — warns (does not block) if the review doesn't look structured.
type: llm_guard
config:
  criteria: "The text is JSON (or clearly contains JSON) with numeric score and a verdict field."
  on_fail: warn

Under abt dispatch, transformers run in transformers: list order on the reviewer's own text, after it finishes, before any of the reviewer's own exposures would dispatch. Each step receives the string from the previous step.

  • json_extract — parses JSON from the response (plain, fenced block, or first {...} span) and returns canonical JSON; runs first so downstream steps see a stable shape
  • pii_redact — replaces emails and phone numbers with [REDACTED] in the canonical JSON payload
  • llm_guard — an LLM scores the text against the criteria; on_fail: warn logs a warning instead of blocking dispatch

Declaring transformers as standalone catalog files (rather than inlining their config on the agent) keeps them nameable and reusable: two different agents can both list redact_pii in their own transformers: without duplicating the config.

tests/reviewer.yaml

agents:
  - agent: reviewer
    tests:
      - name: produces_structured_review
        prompt: "Review this text: 'The quick brown fox jumps over the lazy dog.'"
        contains: [score]
        says: ["is JSON (or clearly contains JSON) with score, verdict, and issues"]
        matches: ['"verdict"\s*:\s*"']
        json_schema:
          type: object
          required: [score, verdict, issues]
        python: ['"score" in text and "verdict" in text']

Tests always wire the agent's full subagents: tree, so reviewer's own declared subagents run as part of this test too; --only-agent only narrows which agent's suite runs, not the wiring. This suite mixes free and judged checks:

Key What it checks
contains Substring present
says A judge model answers yes: the response does what the sentence says
matches Regular expression found
json_schema Response validates against a JSON Schema
python Expression is truthy (text is in scope)

3. Run and test

Four commands run without a model call or an ANTHROPIC_API_KEY:

abt compile
abt run -s reviewer -p review_task --dry-run
abt test --dry-run
abt doctor

abt compile ends with:

Compiled 2 agent(s).
Manifest written to: /path/to/content-review/target/manifest.json
Compiled 3 file(s) to: /path/to/content-review/target/compiled/content-review  (agents: 2, prompts: 1)

abt run --dry-run prints the plan: the agents in the reviewer's delegation tree and their output schemas.

● Run target  selector='reviewer'
  Execution order: analyst → reviewer

  ✓ analyst  model=(profile default)  tools=0  skills=0  sys_prompt_chars=164
    output_schema: (inline)

  ✓ reviewer  model=(profile default)  tools=1  skills=0  sys_prompt_chars=508
    subagents: analyst
    output_schema: review_result.ReviewResult

  Prompt stem/raw='review_task'  resolved_chars=223
────────────────────────────────────────────────────────
No LLM calls or test execution performed.

abt test --dry-run lists every case and its checks:

● Test suites

  ✓ analyst  cases=1
    · extracts_facts  checks: 1x contains, 1x json_schema, 1x says  prompt_chars=40
      preview: Document: Revenue is up. No risks noted.

  ✓ reviewer  cases=1
    · produces_structured_review  checks: 1x contains, 1x json_schema, 1x matches, 1x python, 1x says  prompt_chars=64
      preview: Review this text: 'The quick brown fox jumps over the lazy dog.'
────────────────────────────────────────────────────────
No LLM calls or test execution performed.

abt doctor checks the agents statically. The fresh project is clean, and the exit code is 0 (doctor is advisory unless you pass --fail-on):

✓ 2 agents checked: no findings.

 ✓ analyst ✓ reviewer — 2 agents OK

The next commands call the model, so export a real ANTHROPIC_API_KEY first. abt doctor --deep adds an LLM prompt review, which costs tokens too.

abt run -s reviewer -p review_task
abt test
abt doctor --deep

abt run -s reviewer runs the reviewer plus its full subagents: tree: the analyst runs as a delegate when the reviewer's LLM calls it. abt run skips the transformer chain; transformers run under abt dispatch (see Transformers). reviewer is an agent here, not a workflow — abt dispatch only accepts workflow names.

After the run, inspect: - target/run_results/<run_id>/run_results.json — includes structured with the validated ReviewResult dict - target/run_results/<run_id>/run.log — full trace

See Run artifacts for the full layout.


4. Customize

Work through these exercises to internalize the patterns. Each shows the exact code to add.

Add a new specialist agent

Create agents/summarizer.md:

---
description: Produces a one-sentence executive summary.
tools: []
---

You are the summarizer. Given analysis output, produce exactly one sentence that captures
the core finding. No preamble, no quotes — just the sentence.

Wire it into the reviewer:

# In agents/reviewer.md frontmatter — add alongside the analyst entry:
subagents:
  - analyst
  - summarizer

Then re-run abt compile and abt run -s reviewer. Both analyst and summarizer run as delegates.

Add a regex_replace transformer

Strip markdown bold/italic before the quality gate. Add a new catalog file:

# transformers/strip_markdown.yaml
name: strip_markdown
type: regex_replace
config:
  pattern: "[*_`]+"
  replacement: ""

Then insert it into the reviewer's own transformers: list, after validate_json so it operates on the canonical JSON string:

# In agents/reviewer.md frontmatter:
transformers:
  - validate_json
  - strip_markdown
  - redact_pii
  - quality_gate

Add a web search retriever

Install the extra and add a retriever to enrich the review with external sources:

uv pip install "abt-core[web-search]"

Define a new catalog file. Create the folder first with mkdir -p retrievers, then save this as retrievers/background.yaml:

# retrievers/background.yaml
name: background
type: web_search
config:
  max_results: 3

Then reference it from the reviewer's own frontmatter:

# In agents/reviewer.md frontmatter:
retrievers:
  - background

The retriever runs after the task is composed, searches the web using the task text as the query, and appends results inside <retrieved name="background"> before the reviewer runs.

Retrievers fire only on abt dispatch, not abt run, so give the reviewer a workflow and run it. Create the folder with mkdir -p workflows, then save this as workflows/review.yaml:

name: review
edges:
  - [START, review_task]
  - [review_task, reviewer]
  - [reviewer, END]

Then run abt dispatch -s review --debug. Retriever activity is silent at the default log level; --debug shows the [RETRIEVER] lines with the query and the result size.

Write a fuller test for the analyst

abt init already generated a minimal tests/analyst.yaml. Replace it with a stricter suite that checks the JSON shape:

agents:
  - agent: analyst
    tests:
      - name: extracts_facts_and_summary
        prompt: "Document: Revenue is up 20%. No risks noted. Product shipped on time."
        says: ["has a facts array, a summary, and confidence/complexity scores"]
        json_schema:
          type: object
          required: [facts, summary, confidence, complexity]
          properties:
            facts:
              type: array
              items: {type: string}
              minItems: 1
            summary:
              type: string
            confidence:
              type: number
              minimum: 0
              maximum: 1
            complexity:
              type: number
              minimum: 0
              maximum: 1

5. What to explore next