[PR #6555] [management,proxy] Agent network: per-account LLM gateway (policy, metering, multi-provider) #29656

Closed
opened 2026-08-05 08:08:35 -04:00 by saavagebueno · 0 comments
Owner

Original Pull Request: https://github.com/netbirdio/netbird/pull/6555

State: closed
Merged: Yes


Describe your changes

This PR introduces Agent Networks — a per-account, synthesized reverse-proxy service that sits in front of LLM providers and gives operators identity-aware access control, token/cost metering, and budget enforcement for agent traffic, without the agents needing provider credentials.

A request from a NetBird peer hits the account's agent-network service, runs through a middleware chain, and is routed to the configured upstream provider with the operator's credential injected:

[ llm_request_parser → llm_router → llm_limit_check → llm_identity_inject
  → llm_guardrail → llm_limit_record → cost_meter → llm_response_parser ]

Policies bind source groups → providers with per-group/per-user token and USD budget caps; usage and cost are metered from the live request/response (including streaming) and recorded against policy + account-level budget windows. An access log captures per-request attribution (user, groups, provider, model, tokens, cost, decision).

What's included

  • Management — provider/policy/budget CRUD, store, the reverse-proxy service synthesizer, policy selection + limit enforcement, a curated provider catalog, and the HTTP + proxy gRPC APIs.
  • Proxy — the middleware framework + chain, LLM request/response parsers (OpenAI, Anthropic), pricing table, and the builtin middlewares (router, limit-check/record, cost meter, guardrail, identity inject).
  • Path-routed providersGoogle Vertex AI (service-account credential via a keyfile:: api_key → per-request OAuth token minting) and AWS Bedrock (bearer auth; invoke / converse / streaming; optional /bedrock namespace prefix). Both carry the model in the URL path and enforce a per-route model allowlist.
  • Network-map fix — synthesized agent-network services are now folded into the affected-peer recompute, so an embedded proxy peer learns a newly-authorised client immediately (previously it only converged on a full resync / restart).
  • Hardening — IPv6 in-place apply and TCP accept-loop hardening on the proxy's netstack listeners.
  • End-to-end test suite + a turnkey deployment preset.

Local Documentation

A module-guide doc pack ships with this PR under docs/agent-networks/:

  • README.md — entry point, reading order, module/ownership map
  • 00-overview.md — architecture overview
  • 01-end-to-end-flows.md — request lifecycle
  • modules/50-path-routed-providers.mdVertex AI + AWS Bedrock setup, credential syntax, endpoints, and metering
  • per-package module guides under modules/ (shared API, management store/service/handlers, proxy framework/builtins/parsers/runtime) mapping each concern to the code

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • This change does not modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — OR I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See CONTRIBUTING.md.

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/813

**Original Pull Request:** https://github.com/netbirdio/netbird/pull/6555 **State:** closed **Merged:** Yes --- ## Describe your changes This PR introduces **Agent Networks** — a per-account, synthesized reverse-proxy service that sits in front of LLM providers and gives operators identity-aware **access control, token/cost metering, and budget enforcement** for agent traffic, without the agents needing provider credentials. A request from a NetBird peer hits the account's agent-network service, runs through a middleware chain, and is routed to the configured upstream provider with the operator's credential injected: ``` [ llm_request_parser → llm_router → llm_limit_check → llm_identity_inject → llm_guardrail → llm_limit_record → cost_meter → llm_response_parser ] ``` Policies bind **source groups → providers** with per-group/per-user **token and USD budget caps**; usage and cost are metered from the live request/response (including streaming) and recorded against policy + account-level budget windows. An access log captures per-request attribution (user, groups, provider, model, tokens, cost, decision). ## What's included - **Management** — provider/policy/budget CRUD, store, the reverse-proxy **service synthesizer**, policy selection + limit enforcement, a curated **provider catalog**, and the HTTP + proxy gRPC APIs. - **Proxy** — the middleware framework + chain, LLM request/response **parsers** (OpenAI, Anthropic), **pricing** table, and the builtin middlewares (router, limit-check/record, cost meter, guardrail, identity inject). - **Path-routed providers** — **Google Vertex AI** (service-account credential via a `keyfile::` api_key → per-request OAuth token minting) and **AWS Bedrock** (bearer auth; `invoke` / `converse` / streaming; optional `/bedrock` namespace prefix). Both carry the model in the URL path and enforce a per-route model allowlist. - **Network-map fix** — synthesized agent-network services are now folded into the affected-peer recompute, so an embedded proxy peer learns a newly-authorised client immediately (previously it only converged on a full resync / restart). - **Hardening** — IPv6 in-place apply and TCP accept-loop hardening on the proxy's netstack listeners. - **End-to-end test suite** + a turnkey deployment preset. ## Local Documentation A module-guide doc pack ships with this PR under [`docs/agent-networks/`](https://github.com/netbirdio/netbird/blob/agent-network/docs/agent-networks/README.md): - [`README.md`](https://github.com/netbirdio/netbird/blob/agent-network/docs/agent-networks/README.md) — entry point, reading order, module/ownership map - [`00-overview.md`](https://github.com/netbirdio/netbird/blob/agent-network/docs/agent-networks/00-overview.md) — architecture overview - [`01-end-to-end-flows.md`](https://github.com/netbirdio/netbird/blob/agent-network/docs/agent-networks/01-end-to-end-flows.md) — request lifecycle - [`modules/50-path-routed-providers.md`](https://github.com/netbirdio/netbird/blob/agent-network/docs/agent-networks/modules/50-path-routed-providers.md) — **Vertex AI + AWS Bedrock** setup, credential syntax, endpoints, and metering - per-package module guides under `modules/` (shared API, management store/service/handlers, proxy framework/builtins/parsers/runtime) mapping each concern to the code ## Stack <!-- branch-stack --> ### Checklist - [ ] Is it a bug fix - [ ] Is a typo/documentation fix - [x] Is a feature enhancement - [ ] It is a refactor - [ ] Created tests that fail without the change (if possible) - [ ] This change does **not** modify the public API, gRPC protocols, functionality behavior, CLI / service flags, or introduce a new feature — **OR** I have discussed it with the NetBird team beforehand (link the issue / Slack thread in the description). See [CONTRIBUTING.md](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTING.md#discuss-changes-with-the-netbird-team-first). > By submitting this pull request, you confirm that you have read and agree to the terms of the [Contributor License Agreement](https://github.com/netbirdio/netbird/blob/main/CONTRIBUTOR_LICENSE_AGREEMENT.md). ## Documentation Select exactly one: - [x] I added/updated documentation for this change - [ ] Documentation is **not needed** for this change (explain why) ### Docs PR URL (required if "docs added" is checked) Paste the PR link from https://github.com/netbirdio/docs here: https://github.com/netbirdio/docs/pull/813
saavagebueno added the pull-request label 2026-08-05 08:08:35 -04:00
Sign in to join this conversation.
No Label pull-request
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: DYNR/netbird#29656