← Back to honi.dev

Observability

Monitor, log, and trace every interaction your agent has — from LLM calls to tool invocations.

createObservability() API

TypeScript
1import { createObservability } from 'honidev'
2
3function createObservability(config: ObservabilityConfig): Observability

ObservabilityConfig

FieldTypeDescription
logLevel'debug' | 'info' | 'warn' | 'error'Minimum log level to capture
aiGateway{ accountId: string; gatewayId: string }Route LLM calls through Cloudflare AI Gateway
onEvent(event: HoniEvent) => voidCustom callback for every agent event

HoniEvent Types

Event TypeDescriptionKey Fields
llm.requestLLM API call initiatedmodel, messages, tools
llm.responseLLM API response receivedmodel, response, latencyMs, tokens
llm.errorLLM API call failedmodel, error, latencyMs
tool.callTool invocation startedtoolName, input
tool.resultTool execution completedtoolName, output, latencyMs
tool.errorTool execution failedtoolName, error
memory.readMemory retrievaltier, query, results
memory.writeMemory storagetier, data
session.startNew session createdsessionId
session.endSession terminatedsessionId, messageCount

AI Gateway Setup

Cloudflare AI Gateway provides caching, rate limiting, analytics, and logging for your LLM calls. To enable it:

TypeScript
1export const agent = createAgent({
2 name: 'my-agent',
3 model: 'claude-sonnet-4-20250514',
4 observability: {
5 aiGateway: {
6 accountId: 'your-cf-account-id',
7 gatewayId: 'my-gateway'
8 }
9 }
10})

Once configured, all LLM requests are proxied through the AI Gateway. View analytics, logs, and caching stats in the Cloudflare dashboard.

Example: Logging Every Tool Call

TypeScript
1export const agent = createAgent({
2 name: 'debug-agent',
3 model: 'claude-sonnet-4-20250514',
4
5 observability: {
6 logLevel: 'debug',
7
8 onEvent(event) {
9 if (event.type === 'tool.call') {
10 console.log(`Tool called: ${event.toolName}`)
11 console.log(` Input:`, JSON.stringify(event.input))
12 }
13 if (event.type === 'tool.result') {
14 console.log(` Result (${event.latencyMs}ms):`, event.output)
15 }
16 },
17
18 aiGateway: {
19 accountId: 'abc123',
20 gatewayId: 'my-gateway'
21 }
22 }
23})