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
| Field | Type | Description |
|---|---|---|
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) => void | Custom callback for every agent event |
HoniEvent Types
| Event Type | Description | Key Fields |
|---|---|---|
llm.request | LLM API call initiated | model, messages, tools |
llm.response | LLM API response received | model, response, latencyMs, tokens |
llm.error | LLM API call failed | model, error, latencyMs |
tool.call | Tool invocation started | toolName, input |
tool.result | Tool execution completed | toolName, output, latencyMs |
tool.error | Tool execution failed | toolName, error |
memory.read | Memory retrieval | tier, query, results |
memory.write | Memory storage | tier, data |
session.start | New session created | sessionId |
session.end | Session terminated | sessionId, 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})