runtime

package
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 17, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package runtime holds the protocol-neutral execution layer shared by the AG-UI and A2A servers. It turns one agent turn into a stream of events and leaves wire formatting to the protocol adapters.

Index

Constants

View Source
const (
	EventRunStart  = "run_start"
	EventContent   = "content"
	EventReasoning = "reasoning"
	EventToolStart = "tool_start"
	EventToolEnd   = "tool_end"
	EventTodos     = "todos"
	EventInterrupt = "interrupt"
	EventError     = "error"
	EventRunEnd    = "run_end"
)

Event types emitted by Runner.

Variables

This section is empty.

Functions

This section is empty.

Types

type EmitFunc

type EmitFunc func(Event)

EmitFunc receives execution events in order.

type Error

type Error struct {
	Status  int
	Message string
}

Error is a user-facing validation or execution error.

func (*Error) Error

func (e *Error) Error() string

type ErrorData

type ErrorData struct {
	Message string `json:"message"`
}

ErrorData reports a failed turn.

type Event

type Event struct {
	Seq      int64  `json:"seq"`
	ThreadID string `json:"thread_id"`
	RunID    string `json:"run_id"`
	Type     string `json:"type"`
	Data     any    `json:"data,omitempty"`
}

Event is one protocol-neutral execution event.

type Interactor

type Interactor interface {
	Ask(ctx context.Context, data InterruptData) (Response, error)
	Approve(ctx context.Context, data InterruptData) (Response, error)
	Todos(ctx context.Context, data TodosData) error
}

Interactor bridges ask_user, approvals and todo updates to a protocol. Implementations may block until a client answers; the run goroutine is kept alive by the adapter while the HTTP response is parked.

type InterruptData

type InterruptData struct {
	ID       string           `json:"id"`
	Kind     string           `json:"kind"` // question or approval
	Question string           `json:"question,omitempty"`
	Options  []string         `json:"options,omitempty"`
	Request  approval.Request `json:"request,omitempty"`
}

InterruptData describes a question or an approval request. The protocol adapter decides how to present it and how to resume the run.

type Request

type Request struct {
	Agent     string
	Prompt    string
	Model     string
	SessionID string
	// History overrides the session history when non-nil. AG-UI clients send
	// the complete message list, while A2A resumes from the stored session.
	History []*schema.Message
}

Request describes one agent turn.

type Response

type Response struct {
	Value    string `json:"value,omitempty"`
	Approved bool   `json:"approved,omitempty"`
	Remember bool   `json:"remember,omitempty"`
}

Response is the answer to an interrupt.

type Result

type Result struct {
	SessionID string
	Answer    string
	Stop      string // end, error, cancelled
}

Result describes a completed turn.

type RunEndData

type RunEndData struct {
	Stop      string `json:"stop"` // end, error, cancelled
	SessionID string `json:"session_id"`
	Answer    string `json:"answer,omitempty"`
}

RunEndData reports why a turn stopped.

type RunStartData

type RunStartData struct {
	Agent   string `json:"agent"`
	Model   string `json:"model"`
	Session string `json:"session_id"`
}

RunStartData announces a run and the session it belongs to.

type Runner

type Runner struct {
	// contains filtered or unexported fields
}

Runner executes agent turns and emits protocol-neutral events.

func New

func New(cfg *config.Config) (*Runner, error)

New creates a runner for cfg.

func (*Runner) Run

func (r *Runner) Run(ctx context.Context, req Request, emit EmitFunc, interactor Interactor) (Result, error)

Run executes one turn. It blocks until the agent finishes, is cancelled, or an Interactor waits for a client response.

func (*Runner) Validate

func (r *Runner) Validate(agentName, modelName string) error

Validate checks the agent and model names without starting a turn.

type TextData

type TextData struct {
	Text string `json:"text"`
}

TextData carries an incremental text or reasoning delta.

type TodosData

type TodosData struct {
	Items []tools.TodoItem `json:"items"`
}

TodosData carries the latest task list snapshot.

type ToolEndData

type ToolEndData struct {
	Name   string `json:"name"`
	CallID string `json:"call_id"`
	Result string `json:"result"`
	Failed bool   `json:"failed"`
}

ToolEndData reports a completed tool call.

type ToolStartData

type ToolStartData struct {
	Name      string `json:"name"`
	CallID    string `json:"call_id"`
	Arguments string `json:"arguments"`
}

ToolStartData reports a tool call requested by the model.

Jump to

Keyboard shortcuts

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