(USER OPTIONS)                    GPTEL-SEND                   (HOOKS) 
             ║                                │                           ║    
             v                                v                           v    
╭───────────────────────────╮    ╭────────────┴─────────────╮                  
│      (Org mode only)      │    │       Copy region        │                  
│ gptel-org-ignore-elements │    │ (or buffer above cursor) │
│gptel-org-branching-context├───>┤   to a temporary buffer  │
╰───────────────────────────╯    ╰────────────┬─────────────╯
╭──────────────────────────╮                  │·╶─╴·╶─╴·╶─╴· gptel-prompt-filter-hook
│  gptel-track-response    ├──╮               v
╰──────────────────────────╯  │  ╭────────────┴──────────────╮
╭───────────────────────────╮ │  │  Create messages array,   │
│ Add base64-encoded media  │ ├─>┤ Assign user and LLM roles │
│        from links         ├─╯  │       to messages         │
│     gptel-track-media     │    ╰────────────┬──────────────╯
╰───────────────────────────╯                 │
 ╭─────────────────────────╮                  │
 │     Collect context     │                  │
 │(regions, buffers, files)├──╮               v
 │    gptel-use-context    │  │     ╭─────────┴──────────╮
 ╰─────────────────────────╯  │     │                    │
 ╭─────────────────────────╮  ├────>│   Create payload   │
 │      Prepare tools      │  │     │                    │
 │     gptel-use-tools     ├──┤     ╰─────────┬──────────╯
 │       gptel-tools       │  │               v
 ╰─────────────────────────╯  │     ╔═════════╧══════════╗
 ╭─────────────────────────╮  │     ║    Send request    ║
 │  Run and add directive  │  │     ╚═════════╤══════════╝
 │    gptel-directives     ├──┤               │·╶─╴·╶─╴·╶─╴· gptel-post-request-hook
 │  gptel--system-message  │  │               │                                            
 ╰─────────────────────────╯  │               v                                            
 ╭─────────────────────────╮  │            ╶──┴──╴                                         
 │    Backend parameters   │  │          ╭ ─ ─ ─ ─ ─╮                                      
 │      gptel-backend      ├──┤           ASYNC WAIT                                       
 ╰─────────────────────────╯  │          ╰ ─ ─ ─ ─  ╯                                      
 ╭─────────────────────────╮  │            ╶──┬──╴                                         
 │      gptel-model        ├──╯               v                                            
 ╰─────────────────────────╯                  ├·╶─╴·╶─╴·╶─╴· gptel-pre-response-hook       
╭──────────────────────────╮      ╭───────────────────────╮                                
│    Handle "Reasoning"    ├─────>┤                       │                                
│ gptel-include-reasoning  │  ╭─<─┤ Parse partial response│                                
╰──────────────────────────╯  │╭<─┤                       │<╮                              
                              ││  ╰───────────────────────╯ │                              
                              ││                            ├ gptel-post-stream-hook       
                              ││  ╭───────────────────────╮ │                              
                              │╰──┤ Insert response chunk ├─o                              
                              │   ╰───────────────────────╯ │                              
╭──────────────────────────╮  │   ╭───────────────────────╮ │                              
│ gptel-confirm-tool-calls ├─>o──>┤  Confirm tool calls   │ v                              
╰──────────────────────────╯  │   ╰───────────────────────╯ │                              
╭──────────────────────────╮  │   ╭───────────────────────╮ │                              
│gptel-include-tool-results├─>┴──>┤  Insert tool results  │ │                              
╰──────────────────────────╯      ╰───────────┬───────────╯ │                              
                                              ├─────────────╯                              
                                              v·╶─╴·╶─╴·╶─╴· gptel-post-response-functions 
                                           ╶──┴──╴