Implement hooks in another language
Implement selected Bub application hooks in Go, Rust, or another language through the experimental bub-extism plugin. Bub runs the Python application; Extism loads the WebAssembly modules that implement your hooks.
This guide connects two example modules. Check the plugin’s supported hooks and value conversions before choosing this integration for your application.
Before you start
Section titled “Before you start”Make sure you have:
- The Bub application, with
bub --helpworking. - A Go toolchain if you plan to build the Go example.
- A Rust toolchain with the
wasm32-unknown-unknowntarget if you plan to build the Rust example.
The plugin documentation covers the supported hooks and module format:
1. Install the experimental plugin
Section titled “1. Install the experimental plugin”Install bub-extism into the same environment where Bub runs:
bub install bub-extism@main
Verify that Bub picks it up:
bub hooks
You should see extism listed alongside builtin.
2. Implement one hook in Go and one in Rust
Section titled “2. Implement one hook in Go and one in Rust”Use the two example modules shipped with bub-extism:
go-build-promptimplements thebuild_prompthookrust-run-modelimplements therun_modelhook
Build the Go example:
cd bub-contrib/packages/bub-extism/examples/go-build-prompt
GOOS=wasip1 GOARCH=wasm go build -buildmode=c-shared -o go-build-prompt.wasm .
Build the Rust example:
cd bub-contrib/packages/bub-extism/examples/rust-run-model
cargo build --release --target wasm32-unknown-unknown
If you need the full build commands for either example, check the examples guide.
3. Wire both modules into extism.json
Section titled “3. Wire both modules into extism.json”Create an extism.json in your project root that binds the prompt hook to the Go module and the model hook to the Rust module:
{
"plugins": {
"prompt": {
"manifest": {
"wasm": [
{
"path": "bub-contrib/packages/bub-extism/examples/go-build-prompt/go-build-prompt.wasm"
}
]
},
"wasi": true,
"hooks": {
"build_prompt": "build_prompt"
}
},
"model": {
"manifest": {
"wasm": [
{
"path": "bub-contrib/packages/bub-extism/examples/rust-run-model/target/wasm32-unknown-unknown/release/bub_extism_rust_run_model.wasm"
}
]
},
"hooks": {
"run_model": "run_model"
}
}
}
}
The configuration connects the modules to the application:
manifestfollows the standard Extism manifest format.hooksmaps Bub hook names to wasm exports.- Bub still owns dispatch and precedence.
Point Bub at the config file before running a turn:
export BUB_EXTISM_CONFIG_PATH=./extism.json
4. Run a turn that spans both languages
Section titled “4. Run a turn that spans both languages”Now let Bub build a prompt first, then execute the model hook:
bub run "Say hello from a prompt built outside Python."
When everything is wired up correctly, Bub will:
- Call
build_promptinside the Go module - Pass the returned prompt to
run_modelinside the Rust module - Hand the final result back for this turn
The CLI prints outbound messages in [channel:chat_id] format, so a default bub run typically shows [cli:local] first, followed by the rendered output.
You can expect output similar to:
[cli:local]
[rust-run-model:cli:local] [go-build-prompt:cli:local] Say hello from a prompt built outside Python.
The Go module wraps the inbound prompt with a [go-build-prompt:<chat_id>] prefix; the Rust module then wraps the Go output with [rust-run-model:<chat_id>]. The leading [cli:local] line is the channel header emitted by the CLI adapter.
5. Check the integration boundary
Section titled “5. Check the integration boundary”The Go module builds the prompt and the Rust module formats a response from it. These examples verify hook loading and data exchange. To use the builtin agent’s model calls and conversation recording, keep its run_model implementation.
Check that the plugin supports the hooks you need, and verify the arguments and return values passed between Python and WebAssembly.
Next steps
Section titled “Next steps”- Building plugins: package a Python integration for the Bub application.
bub-extismREADME: read the package conventions and supported hooks.- Extism overview: understand how Extism runs wasm modules across languages.