Skip to content

Workflows

This page follows the important paths through the code. Function names refer to the modules.

1. Uploading documents and the first plan

An upload is stored synchronously; reading it and planning happen in a background session turn. Turns of one session never overlap (jobs.submit_session_task).

%%{init: {"sequence": {"wrap": true, "width": 170, "actorMargin": 40, "messageMargin": 32, "noteMargin": 12, "mirrorActors": false}}}%%
sequenceDiagram
    participant UI as Web UI
    participant R as Router
    participant S as SessionService
    participant J as Job lane
    participant T as Turn graph
    participant P as Parsers
    participant L as LLM
    UI->>R: POST documents
    R->>S: add_document()
    Note over S: store file,<br/>classify role
    S--)UI: document_added
    R->>J: submit run_turn
    R-->>UI: 202
    J->>T: ingest
    Note over T: skip unchanged<br/>documents
    T->>P: inspect_source()
    P-->>T: operations, schemas
    alt no plan yet
        T->>L: plan_from_prompt
        Note over T: extract_plan:<br/>document facts win
        T->>S: save_plan → v1
    else plan exists
        T->>S: refresh_catalog
    end
    S--)UI: plan_updated
    T->>S: say(assistant)
    S--)UI: message

extract_plan (services/planning.py) merges three sources in order:

  1. the LLM's JSON reply: project name, protocols, output type, rationale;
  2. facts from the documents (parsers/inspect.inspect_source), which override the LLM: source protocol, document type, SOAP version, namespace, the operation catalog. A WSDL source defaults to a SOAP target unless the prompt asks for REST;
  3. explicit values (CLI options), which override both.

PDF and Word specifications are not parsed into operations; their text is passed to planning as requirements.

2. A chat message

%%{init: {"sequence": {"wrap": true, "width": 170, "actorMargin": 40, "messageMargin": 32, "noteMargin": 12, "mirrorActors": false}}}%%
sequenceDiagram
    participant UI as Web UI
    participant S as SessionService
    participant T as Turn graph
    participant L as LLM
    participant O as plan_ops
    UI->>S: POST message
    S--)UI: message (user)
    S->>T: run_turn
    T->>L: interpret message
    opt reply invalid
        T->>L: repair once
    end
    L-->>T: intent, plan operations
    alt edit the plan
        opt grouping in words
            T->>L: propose groups
        end
        T->>O: apply_patch → new version
    else approve or generate
        T->>O: apply edits first
        T->>S: approve / start_run
    else cancel, status, repository
        T->>S: matching action
    end
    T->>S: reply, changes, open items
    S--)UI: message (assistant)

The interpretation is a JSON-schema reply (TurnInterpretation): an intent, structured plan operations, an optional grouping request, a reply and a question. A grouping described in words is proposed by the LLM and validated against the operation catalog. Edits sent with an approval are applied first; an edit that fails skips the approval.

If the LLM's reply is still invalid after the repair round, or the LLM is unreachable, the agent says so and points to the Service Designer. The designer and PATCH /plan call the same SessionService.edit_plan without the LLM.

3. Approval and generation

%%{init: {"sequence": {"wrap": true, "width": 170, "actorMargin": 40, "messageMargin": 32, "noteMargin": 12, "mirrorActors": false}}}%%
sequenceDiagram
    participant UI as Web UI
    participant S as SessionService
    participant B as ProgressBroker
    participant J as Run pool
    participant G as Generation graph
    UI->>S: POST approve
    Note over S: blocking issues<br/>→ 409
    S--)UI: plan_approved
    S->>B: prepare_run
    S--)UI: run_started
    S->>J: submit_generation
    S-->>UI: 200 run_id
    J->>G: execute_graph
    loop each node
        G->>B: node progress
        B--)UI: run_progress
    end
    G-->>J: final state
    J->>B: run_completed
    B--)UI: run_finished, outcome message

On approval the current version becomes the approved version, and the previous completed run of the session becomes the source of reusable units. run_progress events are transient; run_finished and the outcome message are persisted session events.

The generation graph

%%{init: {"flowchart": {"nodeSpacing": 35, "rankSpacing": 45}}}%%
flowchart TD
    start([START]) --> parse["parse_document<br/>layout, fingerprints"]
    parse --> validate["validate_document"]
    validate -->|missing schemas| review["human_review<br/>(interrupt)"]
    review --> parse
    validate -->|dotnet| stub[stub_dotnet]
    validate -->|openapi, wsdl| docsgen[generate_documents]
    validate -->|osb| bs[generate_business_service]
    bs --> pl[generate_pipeline]
    pl --> px[generate_proxy_service]
    px --> xs[generate_xslts]
    xs --> write[write_output]
    docsgen --> write
    write --> final["final_validate<br/>cross-references"]
    final --> docs["generate_documentation<br/>ICD, guides, OpenAPI,<br/>design, Postman, SoapUI"]
    docs --> refine[refine]
    stub --> refine
    refine --> done([END])

route_after_validate also sets the run's checklist for the branch it takes, so the progress shown always matches the steps that run.

What parse_document does:

  1. reuses the plan's parsed metadata or parses the documents again;
  2. keeps only the selected operations;
  3. resolves the layout (resolve_layout): routes per proxy and the schema contract of each operation (composition rules). An invalid plan fails here with LayoutError, a second safety net after the approval check;
  4. computes the fingerprint of every unit (run_units);
  5. loads the units of the previous run.

4. Producing one artifact

Every WSDL, XSD, WADL and XSLT goes through LLMXmlGenerator._produce (generators/llm_xml.py):

%%{init: {"flowchart": {"nodeSpacing": 35, "rankSpacing": 45}}}%%
flowchart TD
    a[choose_strategy] -->|templates| t["TemplateRenderer<br/>proxy, pipeline,<br/>business service"]
    a -->|builders| b["build_wsdl, build_xsd,<br/>build_wadl, build_xslt"]
    b --> v{valid?}
    v -->|yes| ok[keep builder output]
    v -->|no| l["LLM critique loop"]
    l --> e{complete?}
    e -->|yes| llmok[keep LLM output]
    e -->|retry| l
    e -->|gave up| fb[keep builder output]

validate_artifact checks well-formedness, content (operations, namespaces, elements) and protocol (SOAP binding version, WADL methods and paths). The LLM receives the issues as a critique and an example file from example/OSB/TravelService. It gives up after LLM_MAX_RETRIES, after two truncated replies, or when it repeats itself.

Each attempt must change the prompt; identical prompts and identical outputs stop the loop. Every produced artifact is recorded as a GenerationTrace (strategy, attempts, validation) in the run's graph state.

5. Incremental re-generation

%%{init: {"flowchart": {"nodeSpacing": 30, "rankSpacing": 45}}}%%
flowchart LR
    plan[Approved plan] --> layout[resolve_layout]
    layout --> units["planned_units<br/>id + fingerprint"]
    prev[("Previous run")] --> runner
    units --> runner[UnitRunner]
    runner -->|same| reuse[Copy files]
    runner -->|changed| gen[Generate]

Units: shared (base pipeline), business_service:{Name}, pipeline:{Proxy}, proxy:{Proxy}, xslt:{Operation} (shared XSLT files, generated once by the operation's home proxy), xslt:{Proxy}:{Operation} (XSLT files of a reduced contract) and docs.

A unit's fingerprint hashes everything that shapes its files, plus GENERATOR_VERSION:

  • the unit's slice of the plan and of the operation metadata;
  • the SOAP version;
  • the template digest;
  • the common namespace.

The documentation unit depends on the fingerprints of all other units. GET /sessions/{id}/runs/preview computes the same fingerprints through the same run_units function, so the preview and the run always agree.

6. Pause, resume and restarts

Missing schemas. If validate_document finds unresolved schemaLocation references, the graph interrupts in human_review:

  1. The run becomes awaiting_human and the session needs_input.
  2. The agent asks for the files.
  3. When the user uploads XSDs, the next session turn calls _resume_paused_run.
  4. That submits resume_run with the schemas, which resumes the graph from its checkpoint (Command(resume=…)); parse_document then runs again with the new files.

Restarts. On startup (api/app.py lifespan), runs still queued or running are marked interrupted. Resume (POST /runs/{id}/resume) calls continue_interrupted_run:

  • If the SQLite checkpoint has a next node, the graph continues from it.
  • Otherwise the approved plan stored in the run context runs again.

Cancellation. POST /sessions/{id}/runs/cancel sets a flag in the broker. UnitRunner.run checks it before every unit and raises RunCancelled, so the run stops between units and is reported as cancelled. Files are written only after all units are produced (write_output), so a cancelled run leaves no partial project.

7. Repository write-back

%%{init: {"sequence": {"wrap": true, "width": 170, "actorMargin": 40, "messageMargin": 32, "noteMargin": 12, "mirrorActors": false}}}%%
sequenceDiagram
    participant UI as Web UI
    participant R as RepositoryService
    participant G as git
    participant P as ADO / GitHub API
    UI->>R: preview(run, repo)
    R->>G: fetch, worktree add
    Note over R: classify files<br/>vs manifest
    R-->>UI: files and counts
    UI->>R: apply(overwrite, skip)
    Note over R: copy files,<br/>update manifest
    R->>G: commit, push branch
    R->>P: create pull request
    R->>G: worktree remove
    R-->>UI: result and PR link

The cache is cloned once (clone --no-checkout into workspaces/{repo}/cache) and fetched on each preview. The worktree branch is forge/{project}-{run8}. Each file is classified against .forge/manifest.json as create, update, unchanged or conflict, and re-classified on apply.

Rules:

  • What counts as a conflict: a file that exists but is not in the manifest, or whose content changed since Middleware Forge wrote it. It is written only when the user chooses Overwrite.
  • Stale files (in the manifest but no longer generated) are reported and never deleted.
  • Nothing to write: if nothing changed, there is no commit and the status is no_changes.
  • Paths and credentials: paths are always checked to stay inside the worktree. Tokens reach git only through the GIT_ASKPASS environment of each command, and are removed from error messages.
  • local provider: files are written into the mounted folder, without git and without a pull request.

8. Technical documentation

For OSB output with documentation enabled, generate_documentation runs after final_validate:

  1. build_solution_model parses the generated proxies, pipelines (including routing-table cases), business services, WSDLs, WADLs and XSDs back into a model. The documentation therefore describes what was actually produced.
  2. docx_writer.build_docx writes the technical design document (ten sections, styles of FORGE_DOCX_TEMPLATE when set). postman and soapui write the Postman collection and the SoapUI project.
  3. For each proxy, consumer.proxy_facts combines the model with the source metadata (header parameters, security schemes, field descriptions). icd.build_icd fills the ICD template, icd.build_consumer_examples writes the consumer guide, and consumer.proxy_openapi writes the OpenAPI specification of REST proxies.
  4. The files go to {Project}/Docs/ (list). The output is byte-identical for identical input on the same day (the ICD carries the generation date).

If documentation fails, the OSB project is kept and a DOCUMENTATION_FAILED issue is reported.

9. Retention

services/retention.purge_expired_data runs at startup and then every FORGE_RETENTION_INTERVAL_SECONDS. It removes:

  • tmp/ entries older than a day;
  • finished runs not updated for FORGE_RETENTION_DAYS, with their output folders and checkpoints;
  • sessions idle for that long, with their uploads;
  • upload folders that belong to no session.

FORGE_RETENTION_DAYS=0 turns it off (only tmp/ is cleaned).