runtime.go

Overview

This file defines the data structure and validation logic for agent execution requests in the system. Specifically, it models a request to run an AI agent within a session context, encapsulating details such as the application name, user and session identifiers, the new input message from the user, streaming preferences, and optional state changes. The primary purpose of this file is to ensure that any request to run an agent contains all the required information before processing.

Data Structures

RunAgentRequest

RunAgentRequest is a struct representing the payload for invoking an agent run operation. It contains the following fields:

Field

Type

Description

AppName

string

Name of the application requesting the agent run. Identifies the app context for the agent.

UserId

string

Unique identifier for the user initiating the request.

SessionId

string

Unique identifier for the session in which the agent is being run.

NewMessage

genai.Content

The new user message content triggering the agent’s response. This type represents LLM input.

Streaming

bool

Optional flag enabling streaming output mode for the agent response.

StateDelta

*map[string]any

Optional pointer to a map representing incremental state changes to apply during agent execution.

The NewMessage field uses the genai.Content type from the google.golang.org/genai package, which encapsulates content suitable for large language models.

Functions and Methods

AssertRunAgentRequestRequired()

func (req RunAgentRequest) AssertRunAgentRequestRequired() error

This method validates that all required fields within a RunAgentRequest instance are populated with non-zero values.

req := RunAgentRequest{
    AppName:   "myApp",
    UserId:    "user123",
    SessionId: "sess789",
    NewMessage: genai.Content{
        // assume content initialization
    },
}

if err := req.AssertRunAgentRequestRequired(); err != nil {
    // handle missing required field error
    log.Fatalf("Invalid request: %v", err)
}

This validation is typically called early in the agent invocation pipeline to ensure input integrity before further processing.

Implementation Details

Interaction with Other System Components

Diagram: RunAgentRequest Structure and Validation Workflow

classDiagram
class RunAgentRequest {
+AppName: string
+UserId: string
+SessionId: string
+NewMessage: genai.Content
+Streaming: bool
+StateDelta: *map[string]any
+AssertRunAgentRequestRequired()
}
RunAgentRequest : +AppName
RunAgentRequest : +UserId
RunAgentRequest : +SessionId
RunAgentRequest : +NewMessage
RunAgentRequest : +Streaming
RunAgentRequest : +StateDelta
RunAgentRequest : +AssertRunAgentRequestRequired()
RunAgentRequest --> IsZeroValue : uses

This diagram depicts the RunAgentRequest class with its properties and the validation method. It also illustrates its dependency on the IsZeroValue utility function for field validation.


For detailed information about agent invocation contexts, session handling, and LLM integration relevant to this request struct, see the following topics: