You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
All streaming endpoints (`/api/stream/investigate`, `/api/stream/chat`, `/api/stream/issue_chat`, etc.) emit Server-Sent Events (SSE) to provide real-time updates during the investigation or chat process.
365
+
366
+
### Metadata Object Reference
367
+
368
+
Many events include a `metadata` object that provides detailed information about token usage, context window limits, and message truncation. This section describes the complete structure of the metadata object.
369
+
370
+
#### Token Usage Information
371
+
372
+
**Structure:**
373
+
```json
374
+
{
375
+
"metadata": {
376
+
"usage": {
377
+
"prompt_tokens": 2500,
378
+
"completion_tokens": 150,
379
+
"total_tokens": 2650
380
+
},
381
+
"tokens": {
382
+
"total_tokens": 2650,
383
+
"tools_tokens": 100,
384
+
"system_tokens": 500,
385
+
"user_tokens": 300,
386
+
"tools_to_call_tokens": 50,
387
+
"assistant_tokens": 1600,
388
+
"other_tokens": 100
389
+
},
390
+
"max_tokens": 128000,
391
+
"max_output_tokens": 16384
392
+
}
393
+
}
394
+
```
395
+
396
+
**Fields:**
397
+
398
+
- `usage` (object): Token usage from the LLM provider (raw response from the model)
399
+
- `prompt_tokens` (integer): Tokens in the prompt (input)
400
+
- `completion_tokens` (integer): Tokens in the completion (output)
401
+
- `total_tokens` (integer): Total tokens used (prompt + completion)
402
+
403
+
- `tokens` (object): HolmesGPT's detailed token count breakdown by message role
404
+
- `total_tokens` (integer): Total tokens in the conversation
405
+
- `tools_tokens` (integer): Tokens used by tool definitions
406
+
- `system_tokens` (integer): Tokens in system messages
407
+
- `user_tokens` (integer): Tokens in user messages
408
+
- `tools_to_call_tokens` (integer): Tokens used for tool call requests from the assistant
409
+
- `assistant_tokens` (integer): Tokens in assistant messages (excluding tool calls)
410
+
- `other_tokens` (integer): Tokens from other message types
411
+
412
+
- `max_tokens` (integer): Maximum context window size for the model
413
+
- `max_output_tokens` (integer): Maximum tokens reserved for model output
414
+
415
+
#### Truncation Information
416
+
417
+
When messages are truncated to fit within context limits, the metadata includes truncation details:
418
+
419
+
**Structure:**
420
+
```json
421
+
{
422
+
"metadata": {
423
+
"truncations": [
424
+
{
425
+
"tool_call_id": "call_abc123",
426
+
"start_index": 0,
427
+
"end_index": 5000,
428
+
"tool_name": "kubectl_logs",
429
+
"original_token_count": 15000
430
+
}
431
+
]
432
+
}
433
+
}
434
+
```
435
+
436
+
**Fields:**
437
+
438
+
- `truncations` (array): List of truncated tool results
439
+
- `tool_call_id` (string): ID of the truncated tool call
440
+
- `start_index` (integer): Character index where truncation starts (always 0)
441
+
- `end_index` (integer): Character index where content was cut off
442
+
- `tool_name` (string): Name of the tool whose output was truncated
443
+
- `original_token_count` (integer): Original token count before truncation
444
+
445
+
Truncated content will include a `[TRUNCATED]` marker at the end.
446
+
447
+
---
448
+
449
+
### Event Types
450
+
451
+
#### `start_tool_calling`
452
+
453
+
Emitted when the AI begins executing a tool. This event is sent before the tool runs.
454
+
455
+
**Payload:**
456
+
```json
457
+
{
458
+
"tool_name": "kubectl_describe",
459
+
"id": "call_abc123"
460
+
}
461
+
```
462
+
463
+
**Fields:**
464
+
465
+
- `tool_name` (string): The name of the tool being called
466
+
- `id` (string): Unique identifier for this tool call
467
+
468
+
---
469
+
470
+
#### `tool_calling_result`
471
+
472
+
Emitted when a tool execution completes. Contains the tool's output and metadata.
473
+
474
+
**Payload:**
475
+
```json
476
+
{
477
+
"tool_call_id": "call_abc123",
478
+
"role": "tool",
479
+
"description": "kubectl describe pod my-pod -n default",
- `metadata` (object): See [Metadata Object Reference](#metadata-object-reference) for complete structure including token usage, truncations, and compaction info
570
+
571
+
**RCA-Specific Fields:**
572
+
573
+
- `sections` (object): Structured investigation output with predefined sections (customizable via request)
574
+
- `analysis` (string): Full analysis text (markdown format)
575
+
- `instructions` (array): List of runbooks that were used during investigation
576
+
577
+
**Chat-Specific Fields:**
578
+
579
+
- `analysis` (string): The AI's response (markdown format)
580
+
- `conversation_history` (array): Complete conversation history including the latest response
581
+
- `follow_up_actions` (array|null): Optional follow-up actions the user can take
582
+
- `id` (string): Unique identifier for the action
583
+
- `action_label` (string): Display label for the action
584
+
- `pre_action_notification_text` (string): Text to show before executing the action
585
+
- `prompt` (string): The prompt to send when the action is triggered
586
+
587
+
---
588
+
589
+
#### `approval_required`
590
+
591
+
Emitted when tool execution requires user approval (e.g., potentially destructive operations). The stream pauses until the user provides approval decisions via a subsequent request.
592
+
593
+
**Payload:**
594
+
```json
595
+
{
596
+
"content": null,
597
+
"conversation_history": [...],
598
+
"follow_up_actions": [...],
599
+
"requires_approval": true,
600
+
"pending_approvals": [
601
+
{
602
+
"tool_call_id": "call_xyz789",
603
+
"tool_name": "kubectl_delete",
604
+
"description": "kubectl delete pod failed-pod -n default",
To continue after approval, send a new request with `tool_decisions`:
624
+
```json
625
+
{
626
+
"conversation_history": [...],
627
+
"tool_decisions": [
628
+
{"tool_call_id": "call_xyz789", "approved": true}
629
+
]
630
+
}
631
+
```
632
+
633
+
---
634
+
635
+
#### `token_count`
636
+
637
+
Emitted periodically to provide token usage updates during the investigation. This event is sent after each LLM iteration to help track resource consumption in real-time.
638
+
639
+
**Payload:**
640
+
```json
641
+
{
642
+
"metadata": {...}
643
+
}
644
+
```
645
+
646
+
**Fields:**
647
+
648
+
- `metadata` (object): See [Metadata Object Reference](#metadata-object-reference) for complete token usage structure. This event provides the same metadata structure as other events, allowing you to monitor token consumption throughout the investigation
649
+
650
+
---
651
+
652
+
#### `conversation_history_compacted`
653
+
654
+
Emitted when the conversation history has been compacted to fit within the context window. This happens automatically when the conversation grows too large.
655
+
656
+
**Payload:**
657
+
```json
658
+
{
659
+
"content": "Conversation history was compacted to fit within context limits.",
660
+
"messages": [...],
661
+
"metadata": {
662
+
"initial_tokens": 150000,
663
+
"compacted_tokens": 80000
664
+
}
665
+
}
666
+
```
667
+
668
+
**Fields:**
669
+
670
+
- `content` (string): Human-readable description of the compaction
671
+
- `messages` (array): The compacted conversation history
672
+
- `metadata` (object): Token information about the compaction
673
+
- `initial_tokens` (integer): Token count before compaction
674
+
- `compacted_tokens` (integer): Token count after compaction
0 commit comments