agent

package
v0.1.7 Latest Latest
Warning

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

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

Documentation

Index

Constants

View Source
const (
	// RuntimeKindLeros is the built-in Leros agent runtime.
	RuntimeKindLeros = "leros"
)

Variables

This section is empty.

Functions

func BuildAttachmentText added in v0.1.2

func BuildAttachmentText(attachments []Attachment) string

BuildAttachmentText formats input attachments as a text block for prompt injection.

func BuildUserInput

func BuildUserInput(req *RequestContext) string

BuildUserInput joins the user-side messages from the request into a formatted text.

Types

type ActorContext

type ActorContext struct {
	UserID      string `json:"user_id"`
	DisplayName string `json:"display_name,omitempty"`
	Channel     string `json:"channel,omitempty"`
	ExternalID  string `json:"external_id,omitempty"`
	AccountID   string `json:"account_id,omitempty"`
}

ActorContext describes the human or system actor that initiated the run.

type AssistantContext

type AssistantContext struct {
	ID           string   `json:"id"`
	Name         string   `json:"name,omitempty"`
	Role         string   `json:"role,omitempty"`
	SystemPrompt string   `json:"system_prompt,omitempty"`
	Skills       []string `json:"skills,omitempty"`
	Tools        []string `json:"tools,omitempty"`
}

AssistantContext is the assistant snapshot used for one run.

type Attachment

type Attachment struct {
	ID       string `json:"id,omitempty"`
	Name     string `json:"name,omitempty"`
	MimeType string `json:"mime_type,omitempty"`
	URL      string `json:"url,omitempty"`
}

Attachment describes an input attachment made available to the run.

type CapabilityContext

type CapabilityContext struct {
	AllowedTools []string `json:"allowed_tools,omitempty"`
}

CapabilityContext describes allowed capabilities for one run.

type ConversationContext

type ConversationContext struct {
	ID       string         `json:"id,omitempty"`
	Messages []InputMessage `json:"messages,omitempty"`
}

ConversationContext carries recent conversation state when available.

type Event

type Event struct {
	ID        string     `json:"id,omitempty"`
	RunID     string     `json:"run_id,omitempty"`
	TraceID   string     `json:"trace_id,omitempty"`
	Seq       int64      `json:"seq,omitempty"`
	Type      EventType  `json:"type"`
	CreatedAt time.Time  `json:"created_at,omitempty"`
	Payload   RawPayload `json:"payload,omitempty"`
	Content   string     `json:"content,omitempty"`
}

Event is the stable runtime event envelope emitted during execution.

type EventSink

type EventSink interface {
	Emit(ctx context.Context, event *Event) error
}

EventSink receives observable events emitted during a run.

type EventType

type EventType string

EventType identifies an observable runtime event emitted during execution.

type InputContext

type InputContext struct {
	Type        InputType      `json:"type"`
	Messages    []InputMessage `json:"messages,omitempty"`
	Attachments []Attachment   `json:"attachments,omitempty"`
}

InputContext is the normalized input passed to the agent.

type InputMessage

type InputMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

InputMessage is a simple role/content message snapshot.

type InputType

type InputType string

InputType describes the primary shape of the run input.

const (
	InputTypeMessage         InputType = "message"
	InputTypeTaskInstruction InputType = "task_instruction"
	InputTypeEvent           InputType = "event"
)

type ModelOptions

type ModelOptions struct {
	Provider     string  `json:"provider,omitempty"`
	Model        string  `json:"model,omitempty"`
	APIKey       string  `json:"-"`
	BaseURL      string  `json:"base_url,omitempty"`
	BaseURLHasV1 bool    `json:"base_url_has_v1,omitempty"`
	Temperature  float64 `json:"temperature,omitempty"`
}

ModelOptions lets callers override model behavior when supported.

type PolicyContext

type PolicyContext struct {
	RequireApproval bool   `json:"require_approval,omitempty"`
	PermissionMode  string `json:"permission_mode,omitempty"` // "bypass" | "on-request" | "auto"; empty defaults to bypass
}

PolicyContext carries policy knobs for one run.

type RawPayload

type RawPayload json.RawMessage

RawPayload stores structured event payload JSON while keeping Event easy to marshal.

func (RawPayload) MarshalJSON

func (p RawPayload) MarshalJSON() ([]byte, error)

MarshalJSON serializes the raw payload bytes.

func (*RawPayload) UnmarshalJSON

func (p *RawPayload) UnmarshalJSON(data []byte) error

UnmarshalJSON stores the raw payload bytes.

type RequestContext

type RequestContext struct {
	RunID        string              `json:"run_id"`
	TraceID      string              `json:"trace_id,omitempty"`
	TaskID       string              `json:"task_id,omitempty"`
	Assistant    AssistantContext    `json:"assistant"`
	Actor        ActorContext        `json:"actor"`
	Conversation ConversationContext `json:"conversation,omitempty"`
	Workspace    WorkspaceContext    `json:"workspace,omitempty"`
	Input        InputContext        `json:"input"`
	Runtime      RuntimeOptions      `json:"runtime,omitempty"`
	Model        ModelOptions        `json:"model,omitempty"`
	Capability   CapabilityContext   `json:"capability,omitempty"`
	Policy       PolicyContext       `json:"policy,omitempty"`
	Metadata     map[string]any      `json:"metadata,omitempty"`

	SystemPrompt string    `json:"-"`
	EventSink    EventSink `json:"-"`
}

RequestContext is the normalized execution snapshot consumed by runtime.

type RunResult

type RunResult struct {
	RunID       string           `json:"run_id"`
	TraceID     string           `json:"trace_id,omitempty"`
	Status      RunStatus        `json:"status"`
	Message     string           `json:"message,omitempty"`
	Error       string           `json:"error,omitempty"`
	Usage       *Usage           `json:"usage,omitempty"`
	ToolCalls   []ToolCallRecord `json:"tool_calls,omitempty"`
	Metadata    map[string]any   `json:"metadata,omitempty"`
	StartedAt   time.Time        `json:"started_at"`
	CompletedAt time.Time        `json:"completed_at,omitempty"`
}

RunResult is the final result of one agent run.

type RunStatus

type RunStatus string

RunStatus is the final status returned from Run.

const (
	RunStatusCompleted RunStatus = "completed"
	RunStatusFailed    RunStatus = "failed"
	RunStatusCancelled RunStatus = "cancelled"
)

type Runner

type Runner interface {
	Run(ctx context.Context, req *RequestContext) (*RunResult, error)
}

Runner executes one normalized agent request.

type RuntimeOptions

type RuntimeOptions struct {
	Kind    string `json:"kind,omitempty"`
	WorkDir string `json:"work_dir,omitempty"`
	MaxStep int    `json:"max_step,omitempty"`
}

RuntimeOptions controls runtime execution behavior.

type RuntimeRouter

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

RuntimeRouter 根据请求选择具体 runtime。

func NewRuntimeRouter

func NewRuntimeRouter(defaultKind string) *RuntimeRouter

NewRuntimeRouter 创建带默认 runtime 的路由器。

func (*RuntimeRouter) Register

func (r *RuntimeRouter) Register(kind string, runner Runner) error

Register 注册或替换一个 runtime runner。

func (*RuntimeRouter) Run

Run 使用请求指定的 runtime 执行任务。

func (*RuntimeRouter) SetDefault

func (r *RuntimeRouter) SetDefault(kind string)

SetDefault 更新默认 runtime。

type ToolCallRecord

type ToolCallRecord struct {
	CallID string         `json:"call_id,omitempty"`
	Name   string         `json:"name,omitempty"`
	Result map[string]any `json:"result,omitempty"`
	Error  string         `json:"error,omitempty"`
}

ToolCallRecord is a compact final tool call summary.

type Usage

type Usage struct {
	InputTokens  int `json:"input_tokens,omitempty"`
	OutputTokens int `json:"output_tokens,omitempty"`
	TotalTokens  int `json:"total_tokens,omitempty"`
}

Usage describes model token usage when available.

type WorkspaceContext

type WorkspaceContext struct {
	OrgID     uint   `json:"org_id,omitempty"`
	ProjectID string `json:"project_id,omitempty"`
	TaskID    string `json:"task_id,omitempty"`
	RequestID string `json:"request_id,omitempty"`
}

WorkspaceContext identifies the project workspace owned by this run.

Jump to

Keyboard shortcuts

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