engine

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2026 License: GPL-3.0 Imports: 1 Imported by: 0

Documentation

Overview

Package engine defines the framework-agnostic AI provider interfaces.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Progress

func Progress(ctx context.Context) func(StreamEvent)

Progress returns the emitter attached by WithProgress, or a no-op.

func WithProgress

func WithProgress(ctx context.Context, emit func(StreamEvent)) context.Context

WithProgress attaches an emitter for nested tool progress.

Types

type ChatRequest

type ChatRequest struct {
	Model        string
	System       string
	Messages     []Message
	Tools        []ToolSpec
	MaxSteps     int
	MaxOutTokens int
}

ChatRequest is one provider turn: system prompt, history, tools, and caps.

type EventType

type EventType string

EventType tags a streamed turn event.

const (
	EventTextDelta      EventType = "text_delta"
	EventReasoningDelta EventType = "reasoning_delta"
	EventToolCall       EventType = "tool_call"
	EventToolResult     EventType = "tool_result"
	EventStep           EventType = "step"
	EventError          EventType = "error"
	EventDone           EventType = "done"
)

type Message

type Message struct {
	Role    Role   `json:"role"`
	Content string `json:"content"`
	// ToolCalls is set on assistant messages that called tools.
	ToolCalls []ToolCall `json:"toolCalls,omitempty"`
	// ToolCallID + Name identify a tool-result message.
	ToolCallID string `json:"toolCallId,omitempty"`
	Name       string `json:"name,omitempty"`
}

Message is one entry of conversation history passed to the provider.

type ModelInfo

type ModelInfo struct {
	ID            string `json:"id"`
	ContextWindow int    `json:"contextWindow,omitempty"`
}

ModelInfo describes a model the provider exposes.

type Provider

type Provider interface {
	// Models lists the provider's available models (for the switcher/validation).
	Models(ctx context.Context) ([]ModelInfo, error)
	// Stream runs one turn, invoking exec for tool calls and emitting events on
	// the returned channel until it closes with a done (or error) event.
	Stream(ctx context.Context, req ChatRequest, exec ToolExecutor) (<-chan StreamEvent, error)
}

Provider is a configured LLM endpoint capable of streaming a tool-calling turn.

type Role

type Role string

Role is a chat message role.

const (
	RoleSystem    Role = "system"
	RoleUser      Role = "user"
	RoleAssistant Role = "assistant"
	RoleTool      Role = "tool"
)

type StreamEvent

type StreamEvent struct {
	Type     EventType      `json:"type"`
	Text     string         `json:"text,omitempty"`
	ToolName string         `json:"toolName,omitempty"`
	ToolID   string         `json:"toolId,omitempty"`
	Input    map[string]any `json:"input,omitempty"`
	Output   any            `json:"output,omitempty"`
	Err      string         `json:"err,omitempty"`
	Usage    *Usage         `json:"usage,omitempty"`
	// Subagent, when set, marks a tool event as nested work performed by a
	// subagent (the UI prefixes it and styles it distinctly).
	Subagent  string `json:"subagent,omitempty"`
	Truncated bool   `json:"truncated,omitempty"`
}

StreamEvent is one event relayed from a running turn.

type ToolCall

type ToolCall struct {
	ID    string         `json:"id"`
	Name  string         `json:"name"`
	Input map[string]any `json:"input"`
}

ToolCall is a model-requested invocation of a tool.

type ToolExecutor

type ToolExecutor interface {
	Execute(ctx context.Context, call ToolCall) (any, error)
}

ToolExecutor runs a model-requested tool call.

type ToolSpec

type ToolSpec struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	Parameters  map[string]any `json:"parameters"`
}

ToolSpec describes a tool to the model. Parameters is a JSON Schema object.

type Usage

type Usage struct {
	InputTokens  int `json:"inputTokens"`
	OutputTokens int `json:"outputTokens"`
}

Usage carries token accounting reported on a done event.

Directories

Path Synopsis
Package eino is the only package that imports cloudwego/eino; it adapts the framework to the engine.Provider seam with an explicit tool-calling loop so each tool call flows through the risk-gated executor.
Package eino is the only package that imports cloudwego/eino; it adapts the framework to the engine.Provider seam with an explicit tool-calling loop so each tool call flows through the risk-gated executor.

Jump to

Keyboard shortcuts

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