agent_with_hooks

command
v0.3.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 11, 2026 License: Apache-2.0 Imports: 16 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

agent_with_hooks

Demonstrates every middleware hook point in the SDK with realistic transformations:

Hook What this example does
BeforeLLM / AfterLLM Redact email addresses and SSNs from prompts and responses
BeforeTool / AfterTool Scrub PII from tool args and results
BeforeRetrieve / AfterRetrieve Prefix queries with kb:; drop documents containing SSNs
BeforeMemoryLoad / AfterMemoryLoad Require tenant_id in scope; wrap recalled context with a scrubbed header
BeforeMemoryStore / AfterMemoryStore Scrub PII before persist; audit log after store

Hook activity is printed to stderr with a [hooks] prefix so you can see when each hook fires without mixing into the assistant reply.

Run

From examples/:

go run ./agent_with_hooks

Default: two-run demo (store memories + prefetch retrieval + tools, then recall).

go run ./agent_with_hooks "My email is alice@example.com. What is the return policy?"

Durable runtimes

Temporal: Hooks are Go functions — they run in the process that executes activities (the worker). Register the same hook groups on both the agent starter and the worker via HookOptions() (or equivalent WithHooks calls). Group names are fingerprinted for drift detection; hook logic consistency is your responsibility.

Restate: Hooks run in the process that serves the embedded SDK endpoint (AGENT_RUNTIME=restate).

Documentation

Overview

Example agent demonstrating all middleware hook points.

Run from examples/:

go run ./agent_with_hooks
go run ./agent_with_hooks "My email is alice@example.com. What is the return policy?"

Hook activity is printed to stderr with a [hooks] prefix. When AGENT_RUNTIME=temporal, register the same HookOptions on both the agent starter and the worker process.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL