telescopeEmitter (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 Emitter class, 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 Emitter instance directly emitted events will not be propagated to the root which may or may not be desired. The piping concept 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 observe method is also supported on Tools and LLMs.

[!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 emitter property.