# actions/ai-inference architecture

> Architecture diagram of the GitHub repository actions/ai-inference, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-11-13). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/actions/ai-inference
- Repository: https://github.com/actions/ai-inference

## Overview

This GitHub Action turns inline or file-based prompts into Copilot CLI requests, then exposes the model response as both an action output and a persistent temporary file. The main workflow is orchestrated by `src/main.ts`; prompt parsing and CLI execution are distinct stages, with `src/helpers.ts` providing legacy prompt loading, message assembly, and process-exit support. The README also documents YAML templates, file-backed variables, system prompts, and optional tool permissions. Edges reflect the shown calls and README workflow; unsampled action wiring is not inferred.

Main entry points: [`src/main.ts`](https://github.com/actions/ai-inference/blob/main/src/main.ts) (Action orchestrator), [`src/copilot.ts`](https://github.com/actions/ai-inference/blob/main/src/copilot.ts) (Copilot CLI adapter), [`src/index.ts`](https://github.com/actions/ai-inference/blob/main/src/index.ts) (Action entrypoint), [`src/prompt.ts`](https://github.com/actions/ai-inference/blob/main/src/prompt.ts) (Prompt YAML parser)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_action["Action workflow"]
  node_entrypoint["Action entrypoint<br/>[index.ts]"]
  node_orchestrator["Action orchestrator<br/>[main.ts]"]
  node_action_contract["Action inputs and outputs<br/>[action.yml]"]
  node_action_outputs["Action outputs<br/>[main.ts]"]
  node_response_file["Response temp file<br/>[main.ts]"]
end

subgraph group_prompt["Prompt preparation"]
  node_prompt_config["Prompt YAML parser<br/>[prompt.ts]"]
  node_prompt_variables["Template variables<br/>[prompt.ts]"]
  node_legacy_helpers["Legacy prompt helpers<br/>[helpers.ts]"]
  node_message_builder["Message assembly<br/>[helpers.ts]"]
end

subgraph group_inference["Copilot inference"]
  node_copilot_adapter["Copilot CLI adapter<br/>[copilot.ts]"]
  node_copilot_cli["Copilot CLI"]
end

node_workflow_user(("Workflow author"))
node_runner(("GitHub Actions runner"))

node_workflow_user -->|"configures"| node_action_contract
node_runner -->|"runs"| node_entrypoint
node_entrypoint -->|"starts"| node_orchestrator
node_orchestrator -->|"loads YAML"| node_prompt_config
node_orchestrator -->|"parses variables"| node_prompt_variables
node_prompt_config -->|"substitutes"| node_prompt_variables
node_orchestrator -->|"loads legacy inputs"| node_legacy_helpers
node_orchestrator -->|"builds messages"| node_message_builder
node_orchestrator -->|"requests inference"| node_copilot_adapter
node_copilot_adapter -->|"spawns"| node_copilot_cli
node_copilot_adapter -->|"returns response"| node_orchestrator
node_orchestrator -->|"sets response"| node_action_outputs
node_orchestrator -->|"writes response"| node_response_file
node_action_outputs -->|"exposes outputs"| node_runner

click node_entrypoint "https://github.com/actions/ai-inference/blob/main/src/index.ts"
click node_orchestrator "https://github.com/actions/ai-inference/blob/main/src/main.ts"
click node_action_contract "https://github.com/actions/ai-inference/blob/main/action.yml"
click node_prompt_config "https://github.com/actions/ai-inference/blob/main/src/prompt.ts"
click node_prompt_variables "https://github.com/actions/ai-inference/blob/main/src/prompt.ts"
click node_legacy_helpers "https://github.com/actions/ai-inference/blob/main/src/helpers.ts"
click node_message_builder "https://github.com/actions/ai-inference/blob/main/src/helpers.ts"
click node_copilot_adapter "https://github.com/actions/ai-inference/blob/main/src/copilot.ts"
click node_action_outputs "https://github.com/actions/ai-inference/blob/main/src/main.ts"
click node_response_file "https://github.com/actions/ai-inference/blob/main/src/main.ts"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_entrypoint,node_orchestrator,node_action_contract,node_action_outputs,node_response_file toneBlue
class node_prompt_config,node_prompt_variables,node_legacy_helpers,node_message_builder toneAmber
class node_copilot_adapter,node_copilot_cli toneMint
class node_workflow_user,node_runner toneIndigo
```

## Components

### Action workflow

- [Action entrypoint](https://github.com/actions/ai-inference/blob/main/src/index.ts): `src/index.ts`
- [Action orchestrator](https://github.com/actions/ai-inference/blob/main/src/main.ts): `src/main.ts`
- [Action inputs and outputs](https://github.com/actions/ai-inference/blob/main/action.yml): `action.yml`
- [Action outputs](https://github.com/actions/ai-inference/blob/main/src/main.ts): `src/main.ts`
- [Response temp file](https://github.com/actions/ai-inference/blob/main/src/main.ts): `src/main.ts`

### Prompt preparation

- [Prompt YAML parser](https://github.com/actions/ai-inference/blob/main/src/prompt.ts): `src/prompt.ts`
- [Template variables](https://github.com/actions/ai-inference/blob/main/src/prompt.ts): `src/prompt.ts`
- [Legacy prompt helpers](https://github.com/actions/ai-inference/blob/main/src/helpers.ts): `src/helpers.ts`
- [Message assembly](https://github.com/actions/ai-inference/blob/main/src/helpers.ts): `src/helpers.ts`

### Copilot inference

- [Copilot CLI adapter](https://github.com/actions/ai-inference/blob/main/src/copilot.ts): `src/copilot.ts`
- **Copilot CLI**

### Other components

- **Workflow author**
- **GitHub Actions runner**

## Connections

- Workflow author → Action inputs and outputs: configures (evidence: `README.md`)
- GitHub Actions runner → Action entrypoint: runs (evidence: `src/index.ts`)
- Action entrypoint → Action orchestrator: starts (evidence: `src/index.ts`)
- Action orchestrator → Prompt YAML parser: loads YAML (evidence: `src/main.ts`)
- Action orchestrator → Template variables: parses variables (evidence: `src/main.ts`)
- Prompt YAML parser → Template variables: substitutes (evidence: `src/prompt.ts`)
- Action orchestrator → Legacy prompt helpers: loads legacy inputs (evidence: `src/main.ts`)
- Action orchestrator → Message assembly: builds messages (evidence: `src/main.ts`)
- Action orchestrator → Copilot CLI adapter: requests inference (evidence: `src/main.ts`)
- Copilot CLI adapter → Copilot CLI: spawns (evidence: `src/copilot.ts`)
- Copilot CLI adapter → Action orchestrator: returns response (evidence: `src/main.ts`)
- Action orchestrator → Action outputs: sets response (evidence: `src/main.ts`)
- Action orchestrator → Response temp file: writes response (evidence: `src/main.ts`)
- Action outputs → GitHub Actions runner: exposes outputs (evidence: `README.md`)
