← Back to Pull requests

feat(tools): add "webhook" toolset for outbound notifications #3641

Closed
unknown closed this pull request without merging on Jul 20, 2026 08:24 UTC
View on GitHub
unknown unknown commented on Jul 14, 2026 14:34 UTC
Author

Closes #3640

What this is

A toolset that lets an agent send a notification to a chat service, without knowing the URL or the secret.

The agent gets one tool - send_webhook(message). Where that message goes is decided by config, not by the model:

agents:
  root:
    model: openai/gpt-4o-mini
    description: Runs the nightly build and reports the result.
    instruction: Report the build outcome with send_webhook.
    toolsets:
      - type: webhook
        webhook_config:
          provider: slack
          url: ${env.SLACK_WEBHOOK_URL}

Agent: send_webhook(message: "nightly build passed ✅")
  →  POST https://hooks.slack.com/services/…   {"text": "nightly build passed ✅"}
  →  "Queued delivery to the slack webhook. You will only be notified if it ultimately fails."

The model wrote the message. It never saw the URL.

<img width="1178" height="374" alt="image" src="https://github.com/user-attachments/assets/ade063ed-9c73-48ca-a544-fb2068e2d7ce" />

Why not just use the api or fetch tool?

You can already POST to Slack with api. The difference is what the model has to know, and what happens when the network misbehaves:

| | api / fetch | webhook |
| --- | --- | --- |
| Destination | model supplies the URL | fixed in config |
| Secret | in the model's context | never in the model's context |
| Payload shape | model must know Slack ≠ Discord ≠ Telegram | built from provider |
| 429 / 5xx | model sees the error and improvises | retried with backoff, honours Retry-After |
| Duplicate sends | model may retry on its own | suppressed for 30s |
| Blocking | model waits for the HTTP round-trip | returns immediately |

The bottom four rows are the substance. A model that gets an HTTP 429 will happily retry in a loop, or give up and report failure when nothing was wrong. Retry policy is not something a language model should be improvising.

How it works

A send_webhook call passes two cheap guards before any network I/O, then delivers - in the background when the runtime allows it:

<img width="608" height="822" alt="image" src="https://github.com/user-attachments/assets/79057c0a-fcbc-4b83-beb9-ff6e27230df5" />

1. Fire-and-forget

send_webhook returns as soon as the message is accepted - the agent isn't blocked on a network round-trip and doesn't stall its turn behind a slow Slack. Delivery continues on a background context (context.WithoutCancel) so it survives the tool call returning. The agent is interrupted only if delivery ultimately fails, via Recall; success is silent.

<img width="803" height="340" alt="image" src="https://github.com/user-attachments/assets/067ad458-8217-4d69-bdd6-070e8ca97980" />

A notification tool that makes the agent babysit every send is worse than no tool. When the runtime doesn't support Recall, it falls back to delivering synchronously and returning the real result - the semantics degrade to "blocking but correct" rather than silently dropping failures.

2. Retries are classified, not blind

Every response is sorted into delivered / transient / permanent, and only transient failures are retried - up to 4 attempts, honouring the server's Retry-After:

<img width="596" height="766" alt="image" src="https://github.com/user-attachments/assets/9f0c750d-e907-44c6-9e5b-4e88405dbcb4" />

| Response | Verdict | Action |
| --- | --- | --- |
| 2xx | delivered | stop |
| 429, 5xx | transient | retry - honour Retry-After, else exponential backoff |
| other 4xx | permanent | stop immediately, report |
| network error | transient | retry |
| bad URL / bad payload | permanent | stop, report |

Retry-After is capped at backoff.MaxRetryAfterWait, so a hostile server can't park a delivery forever. Retrying a 401 forever is pointless; not retrying a 503 is careless - hence the split.

3. Duplicate suppression and rate limiting

An identical (message, value2, value3) within 30s is suppressed, and sends are spaced at least 1s apart (the two amber guards in the flow above). Models retry on their own when they think something failed; without a guard, one flaky send becomes ten Slack messages.

Providers

provider selects the payload shape. Same send_webhook(message) call, different body:

| provider | Body |
| --- | --- |
| slack, mattermost, rocketchat, googlechat, teams | {"text": "..."} |
| discord | {"content": "..."} |
| telegram | {"chat_id": "...", "text": "..."} |
| ifttt | {"value1": "...", "value2": "...", "value3": "..."} |
| generic (default) | {"text": "..."} |

value2 / value3 are optional and exist for IFTTT's three-value contract; other providers ignore them.

More examples

Discord:

toolsets:
  - type: webhook
    webhook_config:
      provider: discord
      url: ${env.DISCORD_WEBHOOK_URL}

Telegram - needs a destination chat as well as the token URL:

toolsets:
  - type: webhook
    webhook_config:
      provider: telegram
      url: https://api.telegram.org/bot${env.TELEGRAM_BOT_TOKEN}/sendMessage
      chat_id: ${env.TELEGRAM_CHAT_ID}

A generic endpoint that authenticates with a header instead of a secret URL:

toolsets:
  - type: webhook
    webhook_config:
      provider: generic
      url: https://alerts.internal.example.com/hook
      headers:
        Authorization: Bearer ${env.ALERTS_TOKEN}

url and headers expand through the standard ${env.VAR} expander - the same one api and open_url use - so secrets stay in the environment rather than in the config file or the model's context.

Notes for review

  • The destination is deliberately not a tool parameter. Making it one would put the secret in the model's context and let a prompt injection retarget the notification. (This is the change from the first revision of this PR.)

  • webhook_config is required for type: webhook, enforced by a dedicated anyOf branch in the schema, so a misconfigured toolset fails at parse time rather than at send time.

  • Response bodies are read through a 64 KiB LimitReader before being echoed into an error, so a misbehaving endpoint can't flood the transcript.
  • Verification

  • go test ./pkg/tools/builtin/webhook/ ./pkg/teamloader/toolsets/ → passing

  • golangci-lint run (repo's own .golangci.yml) → 0 issues

  • Schema drift guards (TestSchemaMatchesGoTypes, TestJsonSchemaWorksForExamples, TestDocYAMLSnippetsAreValid) → passing

  • markdownlint-cli2 from docs/ → 0 errors
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: dwin-gharibi Review duration: 8269m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.57 · 650 lines diff across 8 files
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Ai Authored ai_authored
    0.050
    Real PR Conversation Timeline
    1 comments
    "Review active on #3641"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%