atif

package
v0.0.26 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package atif provides ATIF (Agent Trajectory Interchange Format) v1.6 export support. It converts pi-go session events into the standardized ATIF JSON format for interoperability with external tools and pipelines.

Index

Constants

View Source
const SchemaVersion = "ATIF-v1.6"

SchemaVersion is the ATIF schema version produced by this package.

Variables

This section is empty.

Functions

This section is empty.

Types

type AgentInfo

type AgentInfo struct {
	Name            string         `json:"name"`
	Version         string         `json:"version,omitempty"`
	ModelName       string         `json:"model_name,omitempty"`
	ToolDefinitions []any          `json:"tool_definitions,omitempty"`
	Extra           map[string]any `json:"extra,omitempty"`
}

AgentInfo describes the agent that produced the trajectory.

type ContentPart

type ContentPart struct {
	Type     string `json:"type"`
	Text     string `json:"text,omitempty"`
	ImageURL string `json:"image_url,omitempty"`
}

ContentPart represents a multimodal content part (v1.6).

type Metrics

type Metrics struct {
	PromptTokens     int            `json:"prompt_tokens,omitempty"`
	CompletionTokens int            `json:"completion_tokens,omitempty"`
	CachedTokens     int            `json:"cached_tokens,omitempty"`
	CostUSD          float64        `json:"cost_usd,omitempty"`
	Extra            map[string]any `json:"extra,omitempty"`
}

Metrics holds token usage and cost information.

type Observation

type Observation struct {
	Results []ObservationResult `json:"results"`
}

Observation holds the results of tool executions.

type ObservationResult

type ObservationResult struct {
	SourceCallID          string `json:"source_call_id"`
	Content               any    `json:"content"`
	SubagentTrajectoryRef string `json:"subagent_trajectory_ref,omitempty"`
}

ObservationResult is a single tool execution result.

type SessionMeta

type SessionMeta struct {
	SessionID string
	AgentName string
	Model     string
	WorkDir   string
}

SessionMeta holds metadata needed to initialize the ATIF trajectory header.

type Step

type Step struct {
	StepID           int            `json:"step_id"`
	Timestamp        string         `json:"timestamp,omitempty"`
	Source           string         `json:"source"`
	Message          any            `json:"message"`
	ModelName        string         `json:"model_name,omitempty"`
	ReasoningEffort  any            `json:"reasoning_effort,omitempty"`
	ReasoningContent string         `json:"reasoning_content,omitempty"`
	ToolCalls        []ToolCall     `json:"tool_calls,omitempty"`
	Observation      *Observation   `json:"observation,omitempty"`
	IsCopiedContext  bool           `json:"is_copied_context,omitempty"`
	Metrics          *Metrics       `json:"metrics,omitempty"`
	Extra            map[string]any `json:"extra,omitempty"`
}

Step represents a single interaction step in the trajectory.

func ConvertEvent

func ConvertEvent(event *session.Event, stepID int) []Step

ConvertEvent converts a session.Event into zero or more ATIF Steps. The stepID parameter is the starting step ID; returned steps are numbered sequentially from stepID.

type ToolCall

type ToolCall struct {
	ToolCallID   string         `json:"tool_call_id"`
	FunctionName string         `json:"function_name"`
	Arguments    map[string]any `json:"arguments"`
}

ToolCall represents a tool invocation by the agent.

type Trajectory

type Trajectory struct {
	SchemaVersion          string         `json:"schema_version"`
	SessionID              string         `json:"session_id"`
	Agent                  AgentInfo      `json:"agent"`
	Steps                  []Step         `json:"steps"`
	Notes                  string         `json:"notes,omitempty"`
	FinalMetrics           *Metrics       `json:"final_metrics,omitempty"`
	ContinuedTrajectoryRef string         `json:"continued_trajectory_ref,omitempty"`
	Extra                  map[string]any `json:"extra,omitempty"`
}

Trajectory is the root ATIF document.

type Writer

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

Writer manages incremental writing of an ATIF trajectory file. It is safe for concurrent use; each AppendEvent call converts the event, appends to the in-memory trajectory, and atomically rewrites the JSON file.

func NewWriter

func NewWriter(filePath string, meta SessionMeta) *Writer

NewWriter creates a Writer that will maintain an ATIF file at filePath. The trajectory header is initialized from meta but the file is not written until the first AppendEvent call.

func (*Writer) AppendEvent

func (w *Writer) AppendEvent(event *session.Event) error

AppendEvent converts a session event into ATIF step(s) and appends them to the trajectory. The updated trajectory is atomically flushed to disk. Returns nil if the event produces no steps (e.g., empty or partial events).

func (*Writer) Close

func (w *Writer) Close() error

Close performs a final flush. It is safe to call multiple times.

func (*Writer) LinkSubagentTrajectories

func (w *Writer) LinkSubagentTrajectories(event *session.Event, parentSessionDir, sessionsBaseDir string)

LinkSubagentTrajectories inspects a session event for subagent tool responses. When a FunctionResponse from the "subagent" tool contains result entries with session_id fields, it computes relative paths to the subagent trajectory files and calls SetSubagentRef to link them in the parent trajectory.

parentSessionDir is the directory of the parent session (e.g. ~/.pi-go/sessions/<id>). sessionsBaseDir is the root sessions directory (e.g. ~/.pi-go/sessions).

func (*Writer) SetSubagentRef

func (w *Writer) SetSubagentRef(toolCallID string, refPath string)

SetSubagentRef sets the subagent_trajectory_ref on the observation result whose source_call_id matches toolCallID. This is called after a subagent completes to link its trajectory into the parent.

func (*Writer) StepCount

func (w *Writer) StepCount() int

StepCount returns the number of steps in the trajectory.

Jump to

Keyboard shortcuts

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