Emitter (Observability)
Location within the framework
Hive-agent-framework/emitter.
An emitter is a core functionality of the framework that allows you to see what is happening under the hood.
Standalone usage
The following examples demonstrate how Emitter concept works.
Basic Usage
import { Emitter, EventMeta } from "Hive-agent-framework/emitter/emitter";
// Get the root emitter or create your own
const root = Emitter.root;
root.match("*.*", async (data: unknown, event: EventMeta) => {
console.log(`Received event '${event.path}' with data ${JSON.stringify(data)}`);
});
await root.emit("start", { id: 123 });
await root.emit("end", { id: 123 });Source: examples/emitter/base.ts
[!NOTE]
You can create your own emitter by initiating the
Emitterclass, but typically it's better to use or fork the root one (as can be seen in the following examples).
Advanced
Source: examples/emitter/advanced.ts
[!NOTE]
Because we created the
Emitterinstance directly emitted events will not be propagated to therootwhich may or may not be desired. Thepipingconcept is explained later on.
Event Matching
Source: examples/emitter/matchers.ts
Event Piping
Source: examples/emitter/piping.ts
Framework Usage
Typically, you consume out-of-the-box modules that use the Emitter concept on your behalf.
Agent usage
Source: examples/emitter/agentMatchers.ts
[!IMPORTANT]
The
observemethod is also supported onToolsandLLMs.
[!TIP]
The more complex agentic example can be found here.
[!TIP]
To verify if a given class instance has one, check for the presence of the
emitterproperty.