agent

package
v1.26.2 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package agent adapts the generate/agent agentic loop to the serving layer.

Stability: alpha

Package agent adapts the generate/agent agentic loop to the OpenAI-compatible chat completions API, translating between OpenAI tool definitions and the internal ToolRegistry/Supervisor types.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ConvertTools

func ConvertTools(tools []serve.Tool) []genagent.ToolDef

ConvertTools converts OpenAI Tool definitions into generate/agent ToolDef values suitable for registration in a ToolRegistry.

func MarshalChunk

func MarshalChunk(chunk StreamChunk) ([]byte, error)

MarshalChunk serialises a StreamChunk as a JSON byte slice suitable for an SSE "data:" line.

func ResponseFromSession

func ResponseFromSession(session *genagent.AgentSession, model string) serve.ChatCompletionResponse

ResponseFromSession builds a ChatCompletionResponse from a completed AgentSession. The last step's tool calls (if any) are included in the response choice. If the session ended with tool calls, the finish_reason is "tool_calls"; otherwise it is "stop".

func ToolCallFromAgent

func ToolCallFromAgent(tc genagent.ToolCall) serve.ToolCall

ToolCallFromAgent converts a generate/agent ToolCall into an OpenAI-format serve.ToolCall suitable for inclusion in a ChatCompletionChoice.

func ToolCallsFromStep

func ToolCallsFromStep(step *genagent.AgentStep) []serve.ToolCall

ToolCallsFromStep extracts all tool calls from an AgentStep and converts them to the OpenAI response format.

Types

type StreamChunk

type StreamChunk struct {
	ID      string              `json:"id"`
	Object  string              `json:"object"`
	Created int64               `json:"created"`
	Model   string              `json:"model"`
	Choices []StreamChunkChoice `json:"choices"`
}

StreamChunk is the SSE data payload for a streaming chat completion chunk that may contain tool call deltas.

func BuildToolCallChunks

func BuildToolCallChunks(step *genagent.AgentStep, model string) []StreamChunk

BuildToolCallChunks builds the sequence of SSE chunks needed to stream tool calls from an AgentStep. Per the OpenAI spec, the first chunk for each tool call includes id, type, and function name; subsequent chunks carry argument fragments. This implementation emits one initial chunk per tool call (with the full arguments in a single fragment).

type StreamChunkChoice

type StreamChunkChoice struct {
	Index        int         `json:"index"`
	Delta        StreamDelta `json:"delta"`
	FinishReason *string     `json:"finish_reason"`
}

StreamChunkChoice is a single choice within a streaming chunk.

type StreamDelta

type StreamDelta struct {
	Role      string                `json:"role,omitempty"`
	Content   string                `json:"content,omitempty"`
	ToolCalls []StreamToolCallDelta `json:"tool_calls,omitempty"`
}

StreamDelta holds the incremental content or tool calls for one streaming chunk.

type StreamFunctionDelta

type StreamFunctionDelta struct {
	Name      string `json:"name,omitempty"`
	Arguments string `json:"arguments,omitempty"`
}

StreamFunctionDelta holds incremental function name/arguments in a streaming tool call delta.

type StreamToolCallDelta

type StreamToolCallDelta struct {
	Index    int                  `json:"index"`
	ID       string               `json:"id,omitempty"`
	Type     string               `json:"type,omitempty"`
	Function *StreamFunctionDelta `json:"function,omitempty"`
}

StreamToolCallDelta represents an incremental tool call update for SSE streaming, following the OpenAI delta format.

Jump to

Keyboard shortcuts

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