Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Investigation playbooks

Six investigations an agent is asked for most, each as the user would ask and as the calls the agent makes. They follow the Agent quickstart loop; every call is a complete tools/call parameter object, checked against the tools TKTail serves - replace the values in angle brackets with what TKTail returned. The prompts are examples of what users say; any wording works.

A request: where did it fail?

“Find every record of request R1 and tell me where it failed.”

“Did a request in payments.log fail in orders.jsonl within 10 seconds?”

  1. Discover - the open sources and their formats: does a format have a requestId field, or is the id only in the text?

    { "name": "tktail_list_sources", "arguments": {} }
    
  2. Narrow - one search over every open source: the field where the format has it, the text where it does not.

    {
      "name": "tktail_search",
      "arguments": {
        "definition": {
          "sources": [{ "kind": "open" }],
          "predicate": { "any": [
            { "field": { "name": "requestId", "op": "eq", "value": "<request id>" } },
            { "text": "requestId=<request id>" }
          ] }
        },
        "maxResults": 50,
        "withFields": true
      }
    }
    
  3. Inspect - the records around the error result (its evidenceRef, or its source and line):

    { "name": "tktail_get_records_around", "arguments": { "sourceId": "<payments sourceId>", "line": 2, "before": 5, "after": 5 } }
    
  4. Correlate - the relationship in time, as a sequence: a request received in one log, an error for the same request in another within 10 seconds.

    {
      "name": "tktail_search",
      "arguments": {
        "definition": {
          "sources": [{ "kind": "source", "path": "<payments sourceId>" }, { "kind": "source", "path": "<orders sourceId>" }],
          "predicate": { "all": [] },
          "sequence": {
            "steps": [
              { "sources": [0], "predicate": { "all": [{ "text": "Request received" }] } },
              { "sources": [1], "predicate": { "all": [{ "field": { "name": "level", "op": "eq", "value": "ERROR" } }] },
                "window": { "after": "previous", "earliestMs": 0, "latestMs": 10000 } }
            ],
            "correlation": [
              { "name": "requestId", "compare": "exact", "steps": [
                { "input": "message", "extract": "after", "text": "requestId=" },
                { "input": "field", "field": "requestId" }
              ] }
            ],
            "policy": "earliest"
          }
        }
      }
    }
    
  5. Report - each sequence’s members in order with their times and sources; say if the search was incomplete.

An alert: what happened, and watching for it

“What happened in the last Payment errors incident?”

  1. The alerts and the newest incident of one of them:

    { "name": "tktail_list_alerts", "arguments": {} }
    
    { "name": "tktail_list_alert_occurrences", "arguments": { "alertNumber": 3, "limit": 1 } }
    
  2. The incident and the evidence it kept - the trigger record, the records before and after it, events, metric samples - each item with its own state:

    { "name": "tktail_get_alert_occurrence", "arguments": { "occurrenceId": "<occurrenceId>" } }
    
    { "name": "tktail_get_occurrence_evidence", "arguments": { "occurrenceId": "<occurrenceId>", "item": 1, "limit": 20 } }
    
  3. Report what fired, when, and what the evidence shows; an item that is partial or failed says why. Why it fired comes from the incident’s trace: the conditions that contributed (by their ids, C1, C2), what each matched or measured, and - when complete is false - what the proof is missing.

“Watch orders.jsonl for ERROR records and keep the records around each one.”

Saving needs the user’s permissions Allow AI to save searches and Metric Sets and Allow AI to manage alerts; without them, validate and give the alert to the user to create in Manage Alerts.

  1. Check the alert with TKTail - this writes nothing and needs no permission:

    {
      "name": "tktail_validate_alert",
      "arguments": {
        "alert": {
          "name": "Order errors",
          "severity": "error",
          "condition": {
            "sources": [{ "kind": "source", "path": "<orders sourceId>" }],
            "predicate": { "all": [{ "field": { "name": "level", "op": "eq", "value": "ERROR" } }] }
          },
          "trigger": { "kind": "everyMatch" },
          "actions": ["notify"],
          "capture": { "items": [{ "kind": "file", "recordsBefore": 5, "recordsAfter": 5 }] }
        }
      }
    }
    
  2. With the user’s consent, save the same alert with tktail_save_alert, and the condition as a Saved Search:

    {
      "name": "tktail_save_search",
      "arguments": {
        "name": "Order errors",
        "definition": {
          "sources": [{ "kind": "source", "path": "<orders sourceId>" }],
          "predicate": { "all": [{ "field": { "name": "level", "op": "eq", "value": "ERROR" } }] }
        }
      }
    }
    
  3. To change a saved one later, read it first (tktail_get_alert, tktail_get_saved_search) and pass its version as expectedVersion - a change to something the user edited since is refused, never overwritten.

An unknown format: why is this plain text?

“Why is this log shown as plain text? Write a format for it.”

  1. How TKTail chose the format, and what the detector saw:

    { "name": "tktail_detect_format", "arguments": { "sourceId": "<sourceId>" } }
    
  2. A sample of the log’s records as TKTail frames them:

    { "name": "tktail_get_source_sample", "arguments": { "sourceId": "<sourceId>", "records": 20 } }
    
  3. A draft profile fitted to the log (delimited for CSV-like logs, lineBased or multiline otherwise), then the profile with the fields named and given their roles - checked, and previewed on the log’s own records until every record parses:

    { "name": "tktail_new_format_draft", "arguments": { "sourceId": "<sourceId>", "template": "lineBased" } }
    
    {
      "name": "tktail_validate_format",
      "arguments": {
        "definition": {
          "schemaVersion": 1,
          "id": "orders.worker",
          "name": "Orders worker",
          "framing": { "kind": "line" },
          "envelope": { "pattern": "^(?<timestamp>\\S+ \\S+) (?<level>[A-Z]+) (?<body>.*)$" },
          "fields": [
            { "id": "timestamp", "group": "timestamp", "type": "timestamp", "role": "timestamp" },
            { "id": "level", "group": "level", "role": "severity" },
            { "id": "body", "group": "body", "role": "message" }
          ]
        }
      }
    }
    

    A delimited draft has the log’s delimiter, quote and header and one field per column (columns lists them, 1-based): give the time column "role": "timestamp" and "type": "timestamp", the others "role": "severity", "role": "message", and rename ids freely. tktail_preview_format takes the same definition with the sourceId and shows each record as the profile parses it.

  4. With the user’s consent and Allow AI to save custom formats: tktail_save_format with the definition and applyToSourceId; to have the file use it after a restart, put its file name in definition.fileMatch.names before saving (["export-*.csv"]). Without the permission, give the profile to the user to import in the Custom Format Studio (Your own log formats).

Performance: what did the machine do?

“What did CPU, memory and disk do in the minute around this error?”

Metrics are included with Trial and Pro, and TKTail reports only what it collects: a Metric Set or a Metrics View must be open (View > Metrics…) - the agent never starts collection.

  1. The metrics TKTail collects or still keeps:

    { "name": "tktail_list_metrics", "arguments": {} }
    
  2. Minimum, average and maximum around the error’s time, the peak with its time, and every gap:

    { "name": "tktail_get_metric_summary", "arguments": { "around": { "time": "2026-10-08T10:00:01", "seconds": 60 } } }
    
  3. The samples of one metric over the same interval, if the summary shows a peak worth a closer look:

    { "name": "tktail_get_metric_history", "arguments": { "metricId": "<metricId>", "around": { "time": "2026-10-08T10:00:01", "seconds": 60 } } }
    
  4. Report the values with the metric’s unit and say where samples were missing - a reading TKTail could not take is missing, never zero.

Evidence: keep it before the log rotates

“Save these results with 20 records of context before the log rotates.”

“Pin this search and preserve its evidence - include orders.jsonl for the same seconds.”

A busy log may keep only minutes of history. Preserve what explains the problem as soon as it is found - never copy a whole log with a shell command. Saving and pinning need Allow AI to save evidence and pin searches (off until the user turns it on - a refusal not_allowed says so: ask the user); TKTail redacts secrets before anything is written, and everything read back is the redacted package.

  1. The search whose results are the evidence (or a searchId the investigation already has):

    { "name": "tktail_search", "arguments": { "definition": { "sources": [{ "kind": "open" }], "predicate": { "all": [{ "text": "Payment failed" }] } }, "maxResults": 20 } }
    
  2. Pin it while the investigation goes on - kept across restarts and outside the limit of five AI searches (a pin keeps references; only a package keeps the bytes):

    { "name": "tktail_pin_search", "arguments": { "searchId": 19 } }
    
  3. Preserve: the hits’ records with 20 records on each side (a stack trace is one record), and the other log for the same seconds. The answer names the package, its SHA-256, the time range and how many secrets were redacted; a source that rotated before it could be read is reported, never guessed:

    {
      "name": "tktail_save_evidence",
      "arguments": {
        "searchId": 19,
        "contextRecordsBefore": 20,
        "contextRecordsAfter": 20,
        "contextTimeBeforeMs": 15000,
        "contextTimeAfterMs": 15000,
        "correlatedSourceIds": ["<orders sourceId>"],
        "note": "payment timeouts before the outage"
      }
    }
    

    The capture runs in the background. state: capturing (preserved: false) is NOT saved yet: call tktail_get_evidence with the package id (it waits up to waitMs) until the state is saved - only then tell the user the evidence is preserved. failed or cancelled (preserved: false, a failureCode such as evidence_quota_exceeded, and the reason) means nothing was kept: say so, fix the cause (a narrower search, room in the store) and save again - a new capture with a new package id. tktail_list_evidence lists recent failed captures under failed, so a failure is found even after the package id is forgotten. A package keeps at most 5,000 hits (as many as a search stores).

  4. Check what was kept - the manifest summary, then a page of the parsed records of the first source (fields returns only the fields named):

    { "name": "tktail_get_evidence", "arguments": { "packageId": "<packageId>", "maxHits": 10 } }
    
    { "name": "tktail_get_evidence", "arguments": { "packageId": "<packageId>", "artifact": "sources/source-001/records.jsonl", "maxBytes": 4096 } }
    
  5. Verify before it is shared - VALID, MODIFIED, INCOMPLETE or UNSUPPORTED, also after the original log is gone:

    { "name": "tktail_verify_evidence", "arguments": { "packageId": "<packageId>" } }
    
  6. Report the package id, its SHA-256, the time range and the redactions; the user makes a shareable copy or links it to an incident in the Evidence Library (Saving evidence). Deleting a package is a request (tktail_delete_evidence) the user confirms - ask first.

Archives and compressed history: what was searched, and what was not

“The incident began three days ago - check the old logs too.”

“Is there anything about order 7741 in last week’s support bundle?”

Old logs are compressed (app.log.2.gz, u_ex261107.log.gz) or packed into archives (support-bundle.zip, older-logs.tar.gz, .7z, .rar). TKTail reads them where they lie - never unpack, copy or decompress them yourself (no unzip, 7z, tar, gunzip, Expand-Archive or Python helpers); widen TKTail’s search scope instead. Two different mechanisms (Compressed files and archives):

  • A log’s history ({"kind":"history"}): the log and its rotated generations - compressed ones included (.gz, .zst, .xz, .bz2, .lz4), each generation once. Compression is storage, not archive traversal: no archive option is needed for it.
  • A folder ({"kind":"folder"}): its compressed logs are searched by default; archive contents (ZIP, 7Z, RAR, TARs) are not - they are an explicit expansion of the scope ("archives": true, default false), narrowed with "entryInclude". Nested archives are never searched.
  1. Search the normal scope first - and read the answer’s scope: archivesExcludedByScope counts the archives the folder held that this search did not read, and the hint says so. 0 matches with archives excluded is “0 in this scope” - never “the folder has none”. The same holds when there are matches.

    {
      "name": "tktail_search",
      "arguments": {
        "definition": {
          "sources": [{ "kind": "folder", "path": "<a folder the AI access rules allow>", "include": "*.log*" }],
          "predicate": { "all": [{ "text": "<order id>" }] }
        },
        "waitMs": 5000
      }
    }
    
  2. Relevant archives were excluded? Estimate before widening - nothing decompressed or searched: the archives found, their eligible entries, physical and known logical bytes, and the weight now and with archive contents (light, moderate, heavy - the expected work, never a license matter). Prefer narrow entry masks for a heavy scope:

    {
      "name": "tktail_search",
      "arguments": {
        "definition": {
          "sources": [{ "kind": "folder", "path": "<folder>", "include": "*.log*", "archives": true, "entryInclude": "*.log" }],
          "predicate": { "all": [{ "text": "<order id>" }] }
        },
        "estimateOnly": true
      }
    }
    
  3. Widen deliberately - the same source with "archives": true (and the narrowest "entryInclude" that covers the question). Results name container and entry (support-bundle.zip :: api/api.log); an aggregate covers plain, compressed and archived sources together; evidence keeps container -> entry -> record:

    {
      "name": "tktail_search",
      "arguments": {
        "definition": {
          "sources": [{ "kind": "folder", "path": "<folder>", "include": "*.log*", "archives": true, "entryInclude": "*.log" }],
          "predicate": { "all": [{ "text": "<order id>" }] }
        },
        "waitMs": 5000
      }
    }
    

    TKTail never widens a scope by itself: a search with no matches never turns archive traversal on. capability_unavailable with requiredCapability: "archive-scope" means the edition does not search archives’ entries together - the archives exist; one entry at a time still reads (an archive source with "entry"). outside_investigation_access means no AI access rule of the user allows the path - ask the user to allow exactly what is needed; never read it another way, never try other spellings.

  4. A log’s history - the current log and its compressed generations as one source:

    { "name": "tktail_get_log_history", "arguments": { "path": "<the log, allowed by the AI access rules>" } }
    
    { "name": "tktail_search", "arguments": { "definition": { "sources": [{ "kind": "history", "path": "<the log>" }], "predicate": { "all": [{ "text": "<order id>" }] } }, "waitMs": 5000 } }
    

    The answer says what orders the generations: rotationKeyKind (sequence, date, datetime, date+sequence, datetime+sequence), currentGeneration, and per generation order (0 = newest), current and rotationKey (date, time, sequence) - use them; never order files by their names (app.log.10 is older than app.log.9). A fixed current name with renamed history (app.log and app-2026-11-08_23-00.log) answers fixedCurrentName. A folder search that finds app*.log* is not the history: it does not know which file is current, the order, or which files are one generation stored twice. When the application names its files in a way TKTail does not infer, pass the pattern: "series": "app_{YYYY-MM-DD}_{N}.log" (and the same series in the history search source).

  5. Report the scope with the answer - what was searched (folders, compressed logs, which archives) and what was deliberately not; a negative conclusion holds only for that scope.

  6. A rotating log is ONE logical source with physical generations. tktail_list_sources says so in file.rotation: followsRotation, logicalSource, currentGeneration and whether this source is it (thisIsCurrentGeneration - a tab may show a previous file, or a pinned one: pinnedGeneration), and the history (previousGenerations, generationsKnown, licensed). Never assume a source’s path is stable through an investigation - the tab moves to the new file when the log rotates. A search of one source covers that generation only; the previous generations (compressed ones too) are the log’s history - {"kind":"history"} (Trial / Pro; capability_unavailable names series-history). Say which generations an answer covered: “no timeout in the current file” is not “none in the log”. Alerts follow the logical log; evidence and incidents name the physical file each record came from.