debug.go

Overview

The debug.go file implements the DebugAPIController, a REST API controller responsible for exposing debugging and diagnostic information related to AI agent sessions and their events. It provides HTTP handlers to retrieve detailed trace data and graphical representations of session event workflows, aiding in analysis, troubleshooting, and observability of agent invocations and interactions.

This controller acts as a bridge between the session service, agent loader, and span exporting services to gather, process, and present debug information in JSON format for client consumption. It is part of the broader REST API Controllers that expose various agent runtime and management functionalities over HTTP.


Entities

DebugAPIController

The core struct of this file, encapsulating dependencies necessary for debug operations:

type DebugAPIController struct {
	sessionService session.Service
	agentloader    agent.Loader
	spansExporter  *services.APIServerSpanExporter
}

Constructor

NewDebugAPIController

func NewDebugAPIController(sessionService session.Service, agentLoader agent.Loader, spansExporter *services.APIServerSpanExporter) *DebugAPIController

HTTP Handlers

TraceDictHandler

func (c *DebugAPIController) TraceDictHandler(rw http.ResponseWriter, req *http.Request)

EventGraphHandler

func (c *DebugAPIController) EventGraphHandler(rw http.ResponseWriter, req *http.Request)

Helper Functions

functionalCalls

func functionalCalls(event *session.Event) []*genai.FunctionCall

functionalResponses

func functionalResponses(event *session.Event) []*genai.FunctionResponse

Implementation Details and Algorithms


Interaction with Other Components

This file is integrated into the REST API server as part of the debug endpoints, facilitating monitoring and diagnostics for ongoing agent sessions and executions. It complements the REST API Controllers by focusing on debugging and observability aspects.


Visual Diagram: DebugAPIController Structure and Workflow

flowchart TD
DebugAPIController -->|uses| sessionService[Session Service]
DebugAPIController -->|uses| agentloader[Agent Loader]
DebugAPIController -->|uses| spansExporter[Span Exporter]
TraceDictHandler --> spansExporter
TraceDictHandler --> HTTPResponse[Writes JSON Trace Dict]
EventGraphHandler --> sessionService
EventGraphHandler --> agentloader
EventGraphHandler --> services_GetAgentGraph[services.GetAgentGraph]
EventGraphHandler --> HTTPResponse[Writes JSON Graph DOT]
functionalCalls --> EventGraphHandler
functionalResponses --> EventGraphHandler

Usage Summary


For detailed understanding of related REST API controller design and routing, see REST API and Web Launchers and REST API Controllers. For agent loading and session management details, refer to AI Agent Framework and Session Management. The span exporting and trace data collection is further described in Telemetry and Observability.