PTENES
MODULE 4.3

⚙️ Orchestration, resumption, and diagrams that sell

The glue that connects the three phases. The orchestrator confirms each step, the state.json lets the Factory resume when the context fills up, and the Mermaid diagrams of the current vs. future state — rendered as PNG — are the slide that closes the sale. In the end, the Factory runs end to end.

6
Topics
~60
Minutes
Advanced
Level
Phase 3
Pipeline
1

🎛️ The pipeline orchestrator

The orchestrator is the conductor: it runs Research → Synthesis → Generation in order, and each stage confirms completion before the next one begins. Nothing moves forward in the dark—if Phase 1 isn’t complete, Phase 2 doesn’t run.

Phase 1 · ResearchPerplexity Phase 2 · SynthesisGemini · 15 prompts Phase 3 · GenerationPPTX/DOCX/PNG ✓ confirms ✓ confirms 💾 state.json — checkpoint by phase ✓✓
1.
Receives inputs. Name + company description (and research depth).
2.
Research, synthesize, generate. The three phases in sequence, each one feeding into the next.
3.
Confirm and package. Renders diagrams, organizes folders, and packages everything for download.

💡 Confirming each step is what saves you

Phase-by-phase confirmation isn’t bureaucracy: it’s what makes the pipeline resumable. Since each stage is marked "complete," a crash midway doesn’t force you to redo (or pay for) what was already finished.

Conductor

triggers the phases

Sequence

1 → 2 → 3

Confirm

before moving on

Auditable

each step recorded

2

💾 Checkpoints and state.json

O state.json is the Factory’s memory. It lives in output/{empresa}/ and stores the current phase, the status of each deliverable, and the total cumulative cost of the session.

// output/stripe/state.json

{
  "company_name": "Stripe",
  "current_phase": "synthesis",
  "phases": {
    "research":   { "status": "complete" },
    "synthesis":  { "status": "in_progress" },
    "generation": { "status": "pending" }
  },
  "deliverables": {
    "01_tech_inventory": { "status": "complete", "path": "..." },
    "06_quick_wins":     { "status": "pending" }
  },
  "total_cost": 0.0773
}

📍 Current Phase

current_phase says exactly where the Factory stopped.

✅ Status by deliverable

Each of the 15+ docs is marked complete / pending / failed.

💵 Cumulative cost

total_cost adds up every call — real-time budget tracking.

💡 No checkpoint, no resuming

O state.json is the foundation for everything that follows. It’s what turns “I hit an error and lost everything” into “I hit an error and can pick up where I left off.” Every deliverable it completes is saved immediately.

Memory

on disk

Phase

where it stopped

Cost

accumulated

Base

of the resumption

3

🔁 Resume When the Context Fills Up

Long Claude Code sessions run out of context—it happened twice in the construction of the original Factory. The solution isn’t to hope it won’t happen; it’s to open a new session and resume from the task list stored in the state.json.

// is the context full? new session, same command

# ver onde parou
python -m strategy_factory.main status "Stripe"

# retomar de onde o state.json marcou
python -m strategy_factory.main resume "Stripe"
# → pula research (complete), continua synthesis, depois generation

✓ With resumption

  • ✓A new session reads the state.json and continues
  • ✓Skip phases already complete — doesn’t pay again
  • ✓Uses the research_cache.json instead of researching again

✗ No resumption

  • ✗Context fills up → start everything from scratch
  • ✗Pay for the research again every time it fails
  • ✗Long sessions become dead ends

💡 Documentation is cheap in tokens

Even on Anthropic’s US$20 plan, you can do a lot—as long as you split up the requests. Building in public means showing the mess: context limits, API errors, the wrong model name in the docs. Picking back up from the task list is the skill that helps you finish even when things get stuck.

Is it full?

new session

summary

continues the state

Divide

smaller requests

Finish

without getting stuck

4

🪢 Mermaid: current state vs. future state

The diagram prompt generates two flowcharts that tell the story of the transformation: the current state (today's stack, with bottlenecks marked) and the future state (the AI-enabled architecture). That’s the “before and after” that sells.

// Mermaid example: current state vs. future state

flowchart TB
  subgraph Atual["Estado Atual"]
    DS1[Planilhas soltas] --> CS1[CRM legado]
    CS1 --> U1[Vendas]
    CS1 -. gargalo .-> X[(Dados em silos)]
  end

  subgraph Futuro["Estado Futuro · IA"]
    DL[Plataforma de Dados Unificada] --> AI1[Copiloto de Vendas]
    DL --> AI2[Previsão de Churn]
    AI1 --> U2[Vendas]
    AI2 --> U3[Sucesso do Cliente]
  end

  Atual ==>|transformação| Futuro

📉 Current State

  • •Data sources and legacy systems
  • •Fragile integration points
  • •Known bottlenecks marked in red

📈 Future State (AI)

  • •Unified data platform
  • •AI/ML services layer
  • •Enhanced applications and automated workflows

💡 The deciding slide

An executive won't read three pages of text, but will understand the "before and after" in five seconds. Marking the bottlenecks in the current state creates tension; showing the future state resolves it. This pair of diagrams is often the slide that gets the project approved.

Current

with bottlenecks

Future

AI-enabled

Contrast

before and after

Sell

the board decides

5

🖼️ Render Mermaid → PNG

Client can't open a file .mmd — it opens an image on the slide. The mermaid_renderer converts the code into an actual PNG for insertion into the PPTX. And if rendering fails, graceful degradation kicks in: skips the image and keeps the markdown.

1

mermaid_renderer (in the pipeline)

Take the code generated by the diagram prompt and export a PNG to mermaid_images/. It’s the Factory’s automatic workflow.

2

Skill beautiful-mermaid

Renders Mermaid as polished SVG and PNG—ideal when you want a polished diagram outside the pipeline.

3

eraser.io

Online editor for manually adjusting the diagram and exporting it—good for a quick touch-up before the meeting.

💡 PNG on the slide, source version-controlled

Save the .mmd in recursos/diagramas/ (versionable) and deliver the PNG in the deck. That way, you can edit the diagram text when the project changes without rebuilding the image from scratch.

Renderer

PNG in the pipeline

beautiful-mermaid

finishing touches

eraser.io

manual touch-up

Failed?

keep the md

6

📦 Package for Download

Phase 3 closes the loop: it organizes everything into folders and packages the complete download. Delivery is half the work—a package well organized is what makes the client feel they paid for something serious.

// output/{empresa-slug}/ — the delivered structure

output/stripe/
├── markdown/          # 15 .md (os entregáveis)
├── presentations/     # 2 .pptx (resumo + achados)
├── documents/         # 2 .docx (relatório + SOW)
├── mermaid_images/    # PNGs dos diagramas
├── research_cache.json
└── state.json
1.
Save the Markdown files. The 15 deliverables in markdown/, internal knowledge.
2.
Generates PPTX and DOCX. Executive deck, complete findings, final report, and SOW — the polished deliverable.
3.
Packages everything. Diagrams rendered together, ready for download in the web app.

💡 Minimal input, maximum output—closed

Two text boxes went in at the beginning; now a folder with 19 professional deliverables comes out for less than US$1. This is the complete Factory cycle—and what you take to Track 5, where it becomes an offer and ends up in the client’s hands.

Folders

organized

19 pieces

md+pptx+docx

Download

one click

< US$1

the entire cycle

✅ Module summary

✓
The orchestrator confirms each step — Research → Synthesis → Generation; nothing moves forward in the dark.
✓
state.json is the memory — phase, status by deliverable, and cumulative cost.
✓
Context full? Summarize — the new session picks up where you left off, without paying again.
✓
Current vs. future Mermaid diagram sells — rendered as PNG, packaged in the final package.

🎯 Mission 4.3 — The end-to-end Factory + diagrams

Run the full pipeline for the company from the previous missions and generate the current-state vs. future-state diagrams.

  1. Ask Claude Code to run the Factory end to end (Research → Synthesis → Generation).
  2. If the context fills up, start a new session and use resume "Empresa" — confirm that it skipped what was already done.
  3. Open the state.json and see all the phases in complete e o total_cost.
  4. Render the diagrams (renderer, beautiful-mermaid or eraser.io) and check the PNGs in mermaid_images/.

Success: the folder output/{empresa}/ with all 19 deliverables and rendered diagrams, for < US$1. What you gained: the Factory running end to end — the engine Track 5 turns into an offering and takes to the client.

Next track:

Track 5 · From the Factory to the Client — package it with your brand, position it, price it, and close the sale (capstone).