Skip to content

Commit 73c3edd

Browse files
authored
Merge pull request #742 from maximhq/11-04-fixes_arm64_docker_build_and_docs_for_plugins
fixes arm64 docker build and docs for plugins
2 parents 34ac713 + d790775 commit 73c3edd

File tree

5 files changed

+791
-2
lines changed

5 files changed

+791
-2
lines changed

docs/docs.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
]
6868
}
6969
]
70-
},
70+
},
7171
{
7272
"group": "Models Catalog",
7373
"icon": "box",
@@ -87,6 +87,14 @@
8787
"integrations/langchain-sdk"
8888
]
8989
},
90+
{
91+
"group": "Custom plugins",
92+
"icon": "puzzle-piece",
93+
"pages": [
94+
"plugins/getting-started",
95+
"plugins/writing-plugin"
96+
]
97+
},
9098
{
9199
"group": "Open Source Features",
92100
"icon": "bolt",
170 KB
Loading

docs/plugins/getting-started.mdx

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
---
2+
title: "Getting Started"
3+
description: "Learn how to extend Bifrost's functionality by creating custom plugins that intercept and modify requests and responses."
4+
icon: "book"
5+
---
6+
7+
## What are Bifrost Plugins?
8+
9+
Bifrost plugins allow you to extend the gateway's functionality by intercepting requests and responses. Plugins can modify, log, validate, or enrich data as it flows through the system, giving you powerful hooks into Bifrost's request lifecycle.
10+
11+
## Use Cases
12+
13+
Custom plugins enable you to:
14+
15+
- **Transform requests and responses** - Modify data before it reaches providers or after it returns
16+
- **Add custom validation** - Enforce business rules on incoming requests
17+
- **Implement custom caching** - Cache responses based on custom logic
18+
- **Integrate with external systems** - Send data to logging, monitoring, or analytics platforms
19+
- **Apply custom transformations** - Parse, filter, or enrich LLM responses
20+
21+
## Plugin Architecture
22+
23+
![architecture](../media/dynamic-plugins-architecture.png)
24+
25+
Bifrost leverages **Go's native plugin system** to enable dynamic extensibility. Plugins are built as **shared object files** (`.so` files) that are loaded at runtime by the Bifrost gateway.
26+
27+
### How Go Plugins Work
28+
29+
Go plugins use the `plugin` package from the standard library, which allows Go programs to dynamically load code at runtime. Here's what makes this approach powerful:
30+
31+
- **Native Go Integration** - Plugins are written in Go and have full access to Bifrost's type system and interfaces
32+
- **Dynamic Loading** - Plugins can be loaded, unloaded, and reloaded without restarting Bifrost
33+
- **Type Safety** - Go's type system ensures plugin methods match expected signatures
34+
- **Performance** - No IPC overhead; plugins run in the same process as Bifrost
35+
36+
### Building Shared Objects
37+
38+
Plugins must be compiled as shared objects using Go's `-buildmode=plugin` flag:
39+
40+
```bash
41+
go build -buildmode=plugin -o myplugin.so main.go
42+
```
43+
44+
This generates a `.so` file that exports specific functions matching Bifrost's plugin interface:
45+
46+
- `Init(config any) error` - Initialize the plugin with configuration
47+
- `GetName() string` - Return the plugin name
48+
- `PreHook()` - Intercept requests before they reach providers
49+
- `PostHook()` - Process responses after provider calls
50+
- `TransportInterceptor()` - Modify raw HTTP headers/body (HTTP transport only)
51+
- `Cleanup() error` - Clean up resources on shutdown
52+
53+
### Platform Requirements
54+
55+
**Important Limitations:**
56+
57+
- **Supported Platforms**: Linux and macOS (Darwin) only
58+
- **No Cross-Compilation**: Plugins must be built on the target platform
59+
- **Architecture Matching**: Plugin and Bifrost must use the same architecture (amd64, arm64)
60+
- **Go Version Compatibility**: Plugin must be built with the same Go version as Bifrost
61+
62+
This means if you're running Bifrost on Linux AMD64, you must build your plugin on Linux AMD64 with the same Go version.
63+
64+
### Plugin Lifecycle
65+
66+
1. **Load** - Bifrost loads the `.so` file using Go's `plugin.Open()`
67+
2. **Initialize** - Calls `Init()` with configuration from `config.json`
68+
3. **Hook Execution** - Calls `PreHook()` and `PostHook()` for each request
69+
4. **Cleanup** - Calls `Cleanup()` when Bifrost shuts down
70+
71+
Plugins execute in a specific order:
72+
1. `TransportInterceptor` - Modifies raw HTTP requests (HTTP transport only)
73+
2. `PreHook` - Executes in registration order, can short-circuit requests
74+
3. Provider call (if not short-circuited)
75+
4. `PostHook` - Executes in reverse order of PreHooks
76+
77+
## Next Steps
78+
79+
Ready to build your first plugin? Continue to [Writing Plugins](./writing-plugins) to learn how to create, build, and deploy custom plugins for Bifrost.
80+

0 commit comments

Comments
 (0)