agentmode

package
v0.46.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 18, 2026 License: Apache-2.0 Imports: 4 Imported by: 2 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package agentmode provides AI agent detection and structured JSON output.

It detects whether the CLI is running under an AI coding agent (e.g. Claude Code, Cursor, GitHub Copilot) by checking environment variables, and provides the standard Dynatrace CLI agent envelope format:

{"ok": true, "result": ..., "context": {...}}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ClassifyHTTPError

func ClassifyHTTPError(statusCode int) string

ClassifyHTTPError maps an HTTP status code to a machine-readable error code.

func EnvVars

func EnvVars() []string

EnvVars returns every environment variable Detect consults. Tests clear these to keep a developer's own agent session from flipping output to the agent envelope.

func UserAgentSuffix

func UserAgentSuffix() string

UserAgentSuffix returns a suffix to append to the User-Agent header. Returns empty string if no AI agent is detected.

func WriteError

func WriteError(w io.Writer, detail *ErrorDetail) error

WriteError writes an error response envelope to the writer.

func WriteSuccess

func WriteSuccess(w io.Writer, result interface{}, ctx *ResponseContext) error

WriteSuccess writes a success response envelope to the writer.

Types

type AgentInfo

type AgentInfo struct {
	// Detected is true if an AI agent environment was identified.
	Detected bool
	// Name is the canonical name of the detected agent (e.g. "claude-code").
	Name string
}

AgentInfo represents detected AI agent information.

func Detect

func Detect() AgentInfo

Detect checks environment variables to identify if running under an AI agent.

An AI_AGENT value that names a known agent wins, because it is the agent identifying itself. Otherwise the agent-specific signals decide, in order. An AI_AGENT value naming no known agent still counts as detection, reported as "generic-ai", but only once every specific signal has had its turn.

type ErrorDetail

type ErrorDetail struct {
	Code        string   `json:"code"`
	Message     string   `json:"message"`
	Operation   string   `json:"operation,omitempty"`
	StatusCode  int      `json:"status_code,omitempty"`
	RequestID   string   `json:"request_id,omitempty"`
	Suggestions []string `json:"suggestions,omitempty"`
}

ErrorDetail is a structured error for machine consumption.

type Response

type Response struct {
	OK      bool             `json:"ok"`
	Result  interface{}      `json:"result"`
	Error   *ErrorDetail     `json:"error,omitempty"`
	Context *ResponseContext `json:"context,omitempty"`
}

Response is the standard agent mode envelope that wraps all CLI output. Success responses have OK=true with Result populated. Error responses have OK=false with Error populated.

type ResponseContext

type ResponseContext struct {
	Total       *int              `json:"total,omitempty"`
	HasMore     bool              `json:"has_more,omitempty"`
	Verb        string            `json:"verb,omitempty"`
	Resource    string            `json:"resource,omitempty"`
	Suggestions []string          `json:"suggestions,omitempty"`
	Warnings    []string          `json:"warnings,omitempty"`
	Duration    string            `json:"duration,omitempty"`
	Links       map[string]string `json:"links,omitempty"`
}

ResponseContext provides operational metadata alongside the result.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL