# Webhook Calls Reference (Model Selection & Escalation)

This note lists concrete call sites and related configuration for replacing external webhooks with local model logic. Paths include line numbers to jump directly in your editor.

## Model Selection Webhook

- project-queues/active/BZZZ/reasoning/reasoning.go
  - L87–92: `SetModelConfig` stores `models`, `webhookURL`, and default model.
  - L94–151: `selectBestModel(...)` chooses model via webhook; POST occurs at L115.
  - L147–151: `GenerateResponseSmart(...)` uses `selectBestModel` before calling Ollama.

- project-queues/active/BZZZ/main.go
  - L809–860: `selectBestModel(...)` variant (same behavior); POST occurs at L830.
  - L893–896: `reasoning.SetModelConfig(validModels, cfg.Agent.ModelSelectionWebhook, cfg.Agent.DefaultReasoningModel)` wires config into reasoning.

- project-queues/active/BZZZ/pkg/config/config.go
  - L66–68: `AgentConfig` includes `ModelSelectionWebhook` and `DefaultReasoningModel`.
  - L272–274: Default `ModelSelectionWebhook` and `DefaultReasoningModel` values.

## Chat Callback Webhook (N8N Chat Workflow)

- project-queues/active/BZZZ/cmd/chat-api/main.go
  - L331–350: `sendCallback(...)` posts execution results to `webhookURL` via `http.Client.Post` (N8N workflow callback).
  - L171–174: Callback trigger after task execution completes.

## Escalation Webhook (Human Escalation)

- project-queues/active/BZZZ/pkg/config/config.go
  - L91–101: `P2PConfig` includes `EscalationWebhook` and related thresholds.
  - L288–291: Default `EscalationWebhook` and escalation keywords.

- project-queues/active/BZZZ/pkg/config/defaults.go
  - L63, L69, L75: Environment‑specific defaults for `EscalationWebhook`.

- Call sites in Go code
  - No direct HTTP POST to `EscalationWebhook` found. Current escalation flows publish on PubSub and log:
    - project-queues/active/BZZZ/github/integration.go
      - L274–292: On PR creation failure, builds an escalation reason; calls `requestAssistance(...)` (PubSub), not a webhook.
      - L302–317: `requestAssistance(...)` publishes `TaskHelpRequest` to the task topic.
      - L260–300, L319–360: Collaboration handlers; `triggerHumanEscalation(...)` (L340s–L350s region) logs instead of calling a webhook.

## Pointers for Local Replacement

- Replace webhook POSTs:
  - reasoning: swap `http.Post(modelWebhookURL, ...)` at reasoning.go:L115 with direct local model selection (heuristics or local LLM call).
  - main.go: same replacement at L830 if you retain this variant.
  - chat-api: optionally bypass `sendCallback` (L331–350) or point to a local HTTP receiver.
- Escalation: implement a small helper that calls your local model/service and invoke it from `github/integration.go` where escalation reasons are produced (around L280–282), or from `pkg/coordination/meta_coordinator.go` escalation paths (see `escalateSession(...)`).

---

If you want, I can stub a `localselection` package and replace these call sites with a zero‑dependency selector that queries Ollama directly.

