Observability
Agent instances uses the observability property to emit various internal events that can be used for logging and monitoring.
The default behavior is to console.log() the event value.
{ "type": "event-type", "timestamp": "2024-01-01T00:00:00.000Z", "displayMessage": "Connection established", "payload": { ... }}This can be configured by overriding the property with an implementation of the Observability interface. This interface has a single emit() method that takes an ObservabilityEvent.
import { Agent } from "agents";const customObservability = { async emit(event) { // Custom logic here (e.g., send to external logging service) console.log(`[${event.type}]`, event.displayMessage); },};
class MyAgent extends Agent { observability = customObservability;}import { Agent } from "agents";import type { Observability } from "agents/observability";
const customObservability: Observability = { async emit(event) { // Custom logic here (e.g., send to external logging service) console.log(`[${event.type}]`, event.displayMessage); },};
class MyAgent extends Agent { override observability = customObservability;}Or, alternatively, you can set the property to undefined to ignore all events.
import { Agent } from "agents";
class MyAgent extends Agent { observability = undefined;}import { Agent } from "agents";
class MyAgent extends Agent { override observability = undefined;}Was this helpful?
- Resources
- API
- New to Cloudflare?
- Directory
- Sponsorships
- Open Source
- Support
- Help Center
- System Status
- Compliance
- GDPR
- Company
- cloudflare.com
- Our team
- Careers
- © 2025 Cloudflare, Inc.
- Privacy Policy
- Terms of Use
- Report Security Issues
- Trademark