agent

package
v0.10.0-preview2 Latest Latest
Warning

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

Go to latest
Published: May 9, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const EdgeTypeAgentLookup = "AGENT_LOOKUP"

EdgeTypeAgentLookup is the lineage type emitted for tool-call observations where the agent touched a catalogued asset.

Variables

View Source
var (
	ErrAgentNotFound = errors.New("agent not found")
	ErrRunNotFound   = errors.New("agent run not found")
)

Functions

func IsNotFound

func IsNotFound(err error) bool

IsNotFound returns true if err is one of the package's not-found sentinels. Useful for handlers that translate to 404.

Types

type Bucket

type Bucket struct {
	Hour    time.Time `json:"hour"`
	Success int       `json:"success"`
	Error   int       `json:"error"`
}

Bucket is an hour-aligned aggregate of runs by status.

type PostgresRepository

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

func (*PostgresRepository) BucketRuns

func (r *PostgresRepository) BucketRuns(ctx context.Context, agentID string, since time.Time) ([]Bucket, error)

func (*PostgresRepository) GetByAgentRunID

func (r *PostgresRepository) GetByAgentRunID(ctx context.Context, agentID, runID string) (*Run, error)

func (*PostgresRepository) InsertRun

func (r *PostgresRepository) InsertRun(ctx context.Context, run *Run) error

func (*PostgresRepository) ListRuns

func (r *PostgresRepository) ListRuns(ctx context.Context, agentID string, since time.Time, limit int) ([]*Run, error)

func (*PostgresRepository) Stats

func (r *PostgresRepository) Stats(ctx context.Context, agentID string, since time.Time) (*Stats, error)

type Repository

type Repository interface {
	InsertRun(ctx context.Context, r *Run) error
	GetByAgentRunID(ctx context.Context, agentID, runID string) (*Run, error)
	ListRuns(ctx context.Context, agentID string, since time.Time, limit int) ([]*Run, error)
	BucketRuns(ctx context.Context, agentID string, since time.Time) ([]Bucket, error)
	Stats(ctx context.Context, agentID string, since time.Time) (*Stats, error)
}

func NewPostgresRepository

func NewPostgresRepository(db *pgxpool.Pool) Repository

type Run

type Run struct {
	ID         string     `json:"id"`
	AgentID    string     `json:"agent_id"`
	RunID      string     `json:"run_id"`
	StartedAt  time.Time  `json:"started_at"`
	EndedAt    *time.Time `json:"ended_at,omitempty"`
	DurationMs *int       `json:"duration_ms,omitempty"`
	Status     string     `json:"status"`
	Model      string     `json:"model,omitempty"`
	TokensIn   int        `json:"tokens_in"`
	TokensOut  int        `json:"tokens_out"`
	Error      string     `json:"error,omitempty"`
	CreatedAt  time.Time  `json:"created_at"`
	ToolCalls  []ToolCall `json:"tool_calls,omitempty"`
}

Run is a single agent invocation as recorded by the SDK.

type RunInput

type RunInput struct {
	AgentMRN  string          `json:"agent_mrn"`
	RunID     string          `json:"run_id"`
	StartedAt time.Time       `json:"started_at"`
	EndedAt   *time.Time      `json:"ended_at,omitempty"`
	Status    string          `json:"status"`
	Model     string          `json:"model,omitempty"`
	TokensIn  int             `json:"tokens_in"`
	TokensOut int             `json:"tokens_out"`
	Error     string          `json:"error,omitempty"`
	ToolCalls []ToolCallInput `json:"tool_calls,omitempty"`
	// ObservedAssets are MRNs the agent touched at runtime that aren't already
	// surfaced through ToolCalls' target_mrn — typically extracted from tool
	// outputs (e.g. catalog-traversal tools that return MRNs). The server
	// emits an AGENT_LOOKUP observed edge for each.
	ObservedAssets []string `json:"observed_assets,omitempty"`
}

RunInput is what the SDK posts when an agent run completes.

type Service

type Service interface {
	RecordRun(ctx context.Context, input RunInput) (*Run, error)
	ListRuns(ctx context.Context, assetID string, period time.Duration, limit int) ([]*Run, error)
	BucketRuns(ctx context.Context, assetID string, period time.Duration) ([]Bucket, error)
	Stats(ctx context.Context, assetID string, period time.Duration) (*Stats, error)
}

func NewService

func NewService(repo Repository, assetSvc asset.Service, lineageSvc lineage.Service) Service

type Stats

type Stats struct {
	RunCount      int     `json:"run_count"`
	SuccessRate   float64 `json:"success_rate"`
	MedianLatency int     `json:"median_latency_ms"`
	P95Latency    int     `json:"p95_latency_ms"`
	TokensIn      int     `json:"tokens_in"`
	TokensOut     int     `json:"tokens_out"`
}

Stats summarises agent activity over a window.

type ToolCall

type ToolCall struct {
	Ordinal    int       `json:"ordinal"`
	ToolName   string    `json:"tool_name"`
	TargetMRN  string    `json:"target_mrn,omitempty"`
	StartedAt  time.Time `json:"started_at"`
	DurationMs *int      `json:"duration_ms,omitempty"`
	Status     string    `json:"status"`
}

ToolCall is a single tool invocation inside a Run.

type ToolCallInput

type ToolCallInput struct {
	ToolName   string    `json:"tool_name"`
	TargetMRN  string    `json:"target_mrn,omitempty"`
	StartedAt  time.Time `json:"started_at"`
	DurationMs *int      `json:"duration_ms,omitempty"`
	Status     string    `json:"status"`
}

Jump to

Keyboard shortcuts

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