agenttrace

package
v0.3.0 Latest Latest
Warning

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

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

Documentation

Overview

Package agenttrace converts agentkit's effect requests and results into gollem's trace representation.

It exists because agentkit builds its own gollem session per Generate and therefore never runs gollem.WithTrace. Everything the trace consumers in this repository read — the Cloud Storage archive and the JobRunEvent timeline — comes from trace.Handler callbacks, so the kernel middleware drives those callbacks itself and uses this package to build their payloads.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LLMCallData

func LLMCallData(req *agentkit.GenerateRequest, res *agentkit.GenerateResult, model string) *trace.LLMCallData

LLMCallData builds the span payload for one Generate. res may be nil when the call failed, in which case the request side is still recorded — a failed call is exactly the one an operator wants the prompt for.

model is passed in rather than read off res because agentkit.GenerateResult does not carry it; only the provider client knows which model answered. See ModelCapture for where the caller gets it.

func Messages

func Messages(h *gollem.History, input []gollem.Input) []trace.Message

Messages renders the conversation a Generate was issued against: the carried history followed by this call's new input.

A content block that cannot be decoded is rendered as a placeholder rather than dropped or turned into an error. Tracing is observation: losing a block's detail must never fail the transition that produced it, and silently omitting it would make the recorded conversation disagree with the one the model saw.

Types

type ModelCapture

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

ModelCapture is a trace.Handler that keeps the model name reported for an LLM call and discards everything else.

It exists because agentkit.GenerateResult carries the token counts but not the model that produced them, so LLMCallData has nothing to fill trace.LLMCallData.Model from. gollem's provider clients DO know it: each builds its own trace.LLMCallData naming the model it called and hands it to whatever trace.Handler the context carries. Installing one of these for the duration of one Generate is how that name is obtained.

Every other callback is deliberately a no-op. Installing the run's real handler there instead would make the provider record the call a second time, so the timeline and the archive would hold two entries for one call — the kernel's Generate middleware is what records it.

func (*ModelCapture) AddEvent

func (c *ModelCapture) AddEvent(context.Context, string, any)

func (*ModelCapture) EndAgentExecute

func (c *ModelCapture) EndAgentExecute(context.Context, error)

func (*ModelCapture) EndChildAgent

func (c *ModelCapture) EndChildAgent(context.Context, error)

func (*ModelCapture) EndLLMCall

func (c *ModelCapture) EndLLMCall(_ context.Context, data *trace.LLMCallData, _ error)

EndLLMCall is the only callback that keeps anything. A failed call reports nil data, and a provider that names no model reports an empty one; neither overwrites a name already captured.

func (*ModelCapture) EndSubAgent

func (c *ModelCapture) EndSubAgent(context.Context, error)

func (*ModelCapture) EndToolExec

func (c *ModelCapture) EndToolExec(context.Context, map[string]any, error)

func (*ModelCapture) Finish

func (c *ModelCapture) Finish(context.Context) error

func (*ModelCapture) Model

func (c *ModelCapture) Model() string

Model returns the captured model name, or "" when the provider reported none.

func (*ModelCapture) StartAgentExecute

func (c *ModelCapture) StartAgentExecute(ctx context.Context) context.Context

func (*ModelCapture) StartChildAgent

func (c *ModelCapture) StartChildAgent(ctx context.Context, _ string) context.Context

func (*ModelCapture) StartLLMCall

func (c *ModelCapture) StartLLMCall(ctx context.Context) context.Context

func (*ModelCapture) StartSubAgent

func (c *ModelCapture) StartSubAgent(ctx context.Context, _ string) context.Context

func (*ModelCapture) StartToolExec

func (c *ModelCapture) StartToolExec(ctx context.Context, _ string, _ map[string]any) context.Context

Jump to

Keyboard shortcuts

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