agentrun

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2026 License: Apache-2.0 Imports: 32 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Adapt

func Adapt(legacy tools.Tool, toolCtx tools.ToolContext) agent.Tool

Adapt binds a business tools.Tool to run-scoped context and the agent.Tool result contract.

Types

type ArtifactBaseline

type ArtifactBaseline struct {
	Ref string
}

ArtifactBaseline captures artifact state before execution.

type AttachmentIngestor

type AttachmentIngestor interface {
	IngestAttachments(ctx context.Context, req *agentrundomain.RunRequest)
}

AttachmentIngestor downloads and commits user attachments into the workspace. It is best-effort: failures are logged but do not block the run.

func NewAttachmentIngestor

func NewAttachmentIngestor() AttachmentIngestor

NewAttachmentIngestor creates a new AttachmentIngestor.

type EventContext

type EventContext struct {
	OrgID             uint
	WorkerID          uint
	SessionID         string
	AssistantID       string
	TraceID           string
	RequestID         string
	TaskID            string
	RunID             string
	ParentID          string
	ReplyToMessageIDs []string
}

EventContext carries immutable routing and tracing values for one business run.

type Finalization

type Finalization struct {
	Result *agentrundomain.RunResult
	Events []messaging.RunEventBody
}

Finalization holds the final business result and events emitted before terminal.

type Finalizer

type Finalizer interface {
	FinalizeRequired(
		ctx context.Context,
		run *PreparedRun,
		runtimeResult *agent.ExecutionResult,
		snapshot JournalSnapshot,
	) (*Finalization, error)
	PostRunBestEffort(
		ctx context.Context,
		run *PreparedRun,
		result *agentrundomain.RunResult,
		snapshot JournalSnapshot,
	)
}

Finalizer performs required business finalization and best-effort post-run work.

func NewFinalizer

func NewFinalizer() Finalizer

NewFinalizer creates a new RunFinalizer.

type Journal

type Journal interface {
	Record(ctx context.Context, event RunEventDraft) error
	Snapshot() JournalSnapshot
}

Journal records, sequences, archives, and publishes events for one business run.

func NewJournal

func NewJournal(
	req *agentrundomain.RunRequest,
	eventContext EventContext,
	publisher RunEventPublisher,
) Journal

NewJournal creates a Journal bound to a request and an explicit publisher.

type JournalFactory

type JournalFactory interface {
	New(
		req *agentrundomain.RunRequest,
		eventContext EventContext,
		publisher RunEventPublisher,
	) Journal
}

JournalFactory creates a Journal bound to a run and downstream observer.

func NewJournalFactory

func NewJournalFactory() JournalFactory

NewJournalFactory creates the default JournalFactory.

type JournalSnapshot

type JournalSnapshot struct {
	ToolCalls    []agentrundomain.ToolCallRecord
	Usage        *agentrundomain.Usage
	MessageCount int
	ToolFailures int
	ToolNames    []string
	Events       []messaging.RunEventRecord
}

JournalSnapshot is the immutable activity summary used by finalization.

type NodeHandler

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

NodeHandler owns the Worker-side interpretation of runtime NodeEvents.

func NewNodeHandler

func NewNodeHandler(
	journal Journal,
	planPublisher PlanPublisher,
	sessionStore ProviderSessionStore,
	provider string,
	sessionKey string,
	assistantID string,
) *NodeHandler

NewNodeHandler creates the business handler used as the Runtime observer.

func (*NodeHandler) Observe

func (h *NodeHandler) Observe(ctx context.Context, event agent.NodeEvent) error

Observe handles internal nodes and maps externally visible nodes to RunEventBody.

func (*NodeHandler) PlanError

func (h *NodeHandler) PlanError() error

PlanError returns a plan publication error captured during runtime observation.

type PlanPublishError

type PlanPublishError struct {
	Phase string
	Err   error
}

PlanPublishError is a business-stage error during plan publishing. AgentRun records it after Runtime execution returns so it is not mistaken for a Runtime adapter failure.

func (*PlanPublishError) Error

func (e *PlanPublishError) Error() string

func (*PlanPublishError) Unwrap

func (e *PlanPublishError) Unwrap() error

type PlanPublisher

type PlanPublisher interface {
	Publish(ctx context.Context, event agent.NodeEvent) (*messaging.RunEventBody, error)
}

PlanPublisher processes plan.ready events emitted by the runtime. It reads the plan file, uploads it, and returns a plan.published event. Upload failures return PlanPublishError; AgentRun classifies those failures as business plan_publish errors instead of Runtime execution errors.

func NewPlanPublisher

func NewPlanPublisher(cfg PlanPublisherConfig) PlanPublisher

NewPlanPublisher creates a PlanPublisher with injected dependencies.

type PlanPublisherConfig

type PlanPublisherConfig struct {
	ServerAddr string
	OrgID      uint
	AuthToken  string
	HTTPClient *http.Client
}

PlanPublisherConfig holds injected dependencies for plan publishing.

type PreparedRun

type PreparedRun struct {
	Request   *agentrundomain.RunRequest
	Execution agent.ExecutionRequest
	Workspace WorkspacePreparation
	Baseline  ArtifactBaseline
}

PreparedRun holds the immutable original request and the fully-built execution context. Request is the caller's original snapshot — it is never modified during preparation.

type Preparer

type Preparer interface {
	Prepare(ctx context.Context, req *agentrundomain.RunRequest) (*PreparedRun, error)
}

Preparer converts a business run request into an immutable prepared run.

func NewPreparer

func NewPreparer(builder *agentruncontext.ContextBuilder) Preparer

NewPreparer creates a new RunPreparer.

func NewPreparerWithPorts

func NewPreparerWithPorts(
	builder *agentruncontext.ContextBuilder,
	wm WorkspaceManager,
	ai AttachmentIngestor,
	modelStore *modelrouter.ModelStore,
) Preparer

NewPreparerWithPorts creates a RunPreparer with injected workspace and attachment ports.

func NewPreparerWithSessionStore

func NewPreparerWithSessionStore(
	builder *agentruncontext.ContextBuilder,
	wm WorkspaceManager,
	ai AttachmentIngestor,
	modelStore *modelrouter.ModelStore,
	toolProvider ToolProvider,
	sessionStore ProviderSessionStore,
) Preparer

NewPreparerWithSessionStore creates a RunPreparer with ProviderSessionStore for resume support.

func NewPreparerWithTools

func NewPreparerWithTools(
	builder *agentruncontext.ContextBuilder,
	wm WorkspaceManager,
	ai AttachmentIngestor,
	modelStore *modelrouter.ModelStore,
	toolProvider ToolProvider,
) Preparer

NewPreparerWithTools creates a RunPreparer with all external dependencies injected.

type ProviderSessionBinding

type ProviderSessionBinding struct {
	InternalSessionID string
	Provider          string
	ProviderSessionID string
	WorkDir           string
	AssistantID       string
	Status            string
	LastError         string
}

ProviderSessionBinding maps a SingerOS session to a provider native session.

type ProviderSessionKey

type ProviderSessionKey struct {
	InternalSessionID string
	Provider          string
	WorkDir           string
	AssistantID       string
}

ProviderSessionKey identifies a provider session binding.

type ProviderSessionStore

type ProviderSessionStore interface {
	GetProviderSession(ctx context.Context, key ProviderSessionKey) (*ProviderSessionBinding, error)
	UpsertProviderSession(ctx context.Context, binding *ProviderSessionBinding) error
	MarkProviderSessionFailed(ctx context.Context, key ProviderSessionKey, reason string) error
}

ProviderSessionStore persists provider session bindings for external CLI resume. Implementations are provided by the Worker host layer (e.g. SQLite).

type RunEventDraft

type RunEventDraft struct {
	OccurredAt time.Time
	Body       messaging.RunEventBody
}

RunEventDraft is an unsequenced business event produced inside AgentRun.

type RunEventPublisher

type RunEventPublisher interface {
	PublishRunEvent(ctx context.Context, event messaging.RunEvent) error
}

RunEventPublisher publishes a fully constructed Worker/Server business event.

type Service

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

Service is the single business entry point for an Agent Run.

func NewService

func NewService(
	preparer Preparer,
	executor *agent.Executor,
	finalizer Finalizer,
	journal JournalFactory,
	planPublisher PlanPublisher,
) *Service

NewService creates a new AgentRun Service.

func NewServiceWithSessionStore

func NewServiceWithSessionStore(
	preparer Preparer,
	executor *agent.Executor,
	finalizer Finalizer,
	journal JournalFactory,
	planPublisher PlanPublisher,
	sessionStore ProviderSessionStore,
) *Service

NewServiceWithSessionStore creates a new Service with ProviderSessionStore for resume support.

func (*Service) Run

func (s *Service) Run(
	ctx context.Context,
	req *agentrundomain.RunRequest,
	eventContext EventContext,
	publisher RunEventPublisher,
) (*agentrundomain.RunResult, error)

Run executes one business agent run. It:

  1. Validates the request
  2. Emits run.started
  3. Calls Preparer to build ExecutionRequest
  4. Calls agent.Executor for the runtime lifecycle
  5. Calls Finalizer for required post-run tasks
  6. Emits artifact events
  7. Emits exactly one terminal event
  8. Runs best-effort post-run tasks

type ToolProvider

type ToolProvider interface {
	ToolsFor(
		req *agentrundomain.RunRequest,
		workspace WorkspacePreparation,
	) ([]agent.Tool, error)
}

ToolProvider resolves business tools into the neutral execution contract.

func NewToolProvider

func NewToolProvider(registry *tools.Registry) ToolProvider

NewToolProvider adapts the application tool registry at the AgentRun business boundary.

type WorkspaceManager

type WorkspaceManager interface {
	PrepareWorkspace(
		ctx context.Context,
		req agentworkspace.TaskWorkspaceRequest,
	) (WorkspacePreparation, error)
}

WorkspaceManager prepares task workspaces (clone/populate repo).

func NewWorkspaceManager

func NewWorkspaceManager(env, giteaEndpoint, giteaOwner, giteaAccessToken string) WorkspaceManager

NewWorkspaceManager creates a WorkspaceManager backed by the given Gitea config.

type WorkspacePreparation

type WorkspacePreparation struct {
	WorkDir              string
	RepoDir              string
	TaskDir              string
	ArtifactManifestPath string
	PreRunTreeSHA        string // Git tree SHA captured before agent execution
}

WorkspacePreparation is the immutable result of preparing a run workspace.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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