Skip to content

Package agent/agenttest ​

Go module github.com/bide-ai/bide; all packages.

github.com/bide-ai/bide/agent/agenttest · pkg.go.dev · Stability: core

Package agenttest holds test doubles and helpers for code built on package agent: a scripted model that plays back the turns you give it, so an agent runs with no provider or API key (ScriptedModel, NewScriptedModel, ToolTurn, TextTurn, ErrorTurn); a Store that counts its round trips (CountingStore); and constructors that panic instead of returning an error (MemJournal, MustJournal, MustNew, Must), for tests whose setup cannot fail.

Functions

  • func Answer(res *agent.Result, err error) (agent.Message, error): Answer returns the answer of a run's Result and the run's error, as the string entry points returned them: Answer(a.Run(ctx, runID, agent.UserText(input))).
  • func IdentityContext(ctx context.Context, id agent.Identity) context.Context: IdentityContext returns ctx carrying id as the acting identity, as a run binds its WithIdentity option for its tool calls: for a test that calls a tool directly, outside a run, and checks what it does with agent.IdentityFrom.
  • func MemJournal() *agent.Journal: MemJournal returns a Journal over a new, empty agent.MemStore.
  • func Must[T any](v T, err error) T: Must returns v, and panics with err if it is not nil: Must(agent.NewJournal(s)), say, in a test whose setup cannot fail.
  • func MustJournal(s agent.Store) *agent.Journal: MustJournal returns agent.NewJournal(s), and panics if that fails (a nil store).
  • func MustNew(model agent.Model, j *agent.Journal, opts ...agent.Option) *agent.Agent: MustNew returns agent.New(model, j, opts...), and panics if it fails.
  • func NotifyTrailContract(t *testing.T, newStore func() func() agent.NotifyTrail): NotifyTrailContract runs the agent.NotifyTrail contract.

type CountingStore ​

go
type CountingStore struct {
	// contains filtered or unexported fields
}

CountingStore wraps a Store and counts the round trips it serves, for tests that hold the engine to a budget of store calls per operation.

Constructors and functions

  • func NewCountingStore(inner agent.Store) *CountingStore: NewCountingStore returns a CountingStore over inner.

Methods

  • func (s *CountingStore) Counts() Counts: Counts returns the counts so far.
  • func (s *CountingStore) Get(ctx context.Context, runID, name string) (agent.Entry, bool, error): Get implements agent.Store.
  • func (s *CountingStore) Insert(ctx context.Context, runID, name string, data []byte) (agent.Entry, bool, error): Insert implements agent.Store.
  • func (s *CountingStore) Load(ctx context.Context, runID string, after int64) iter.Seq2[agent.Entry, error]: Load implements agent.Store.
  • func (s *CountingStore) Reset() Counts: Reset zeroes the counts and returns the ones it cleared.
  • func (s *CountingStore) Unwrap() agent.Store: Unwrap returns the wrapped store.

type Counts ​

go
type Counts struct {
	Insert, Get, Load int

	Inserted int

	EntriesRead int

	Names []string
}

Counts is how many round trips a CountingStore served, and how many entries its Loads yielded.

type ScriptedModel ​

go
type ScriptedModel struct {
	// contains filtered or unexported fields
}

ScriptedModel is a deterministic, LLM-free Model that replays a fixed script of turns, one turn per model call.

Constructors and functions

  • func NewScriptedModel(turns ...ScriptedTurn) *ScriptedModel: NewScriptedModel builds a ScriptedModel that replays turns in order, one per model call.

Methods

  • func (m *ScriptedModel) Stream(_ context.Context, req agent.Request) (*agent.Stream, error): Stream implements agent.Model.

type ScriptedTurn ​

go
type ScriptedTurn struct {
	// contains filtered or unexported fields
}

ScriptedTurn is one scripted model output.

Constructors and functions

  • func ErrorTurn(err error) ScriptedTurn: ErrorTurn scripts a turn that fails the model call with err, so a test can exercise the loop's error path (a mid-run "crash" before the next step is journaled, say).
  • func TextTurn(text string) ScriptedTurn: TextTurn scripts a turn in which the model emits a final text answer, ending the run.
  • func ToolTurn(id, name, args string) ScriptedTurn: ToolTurn scripts a turn in which the model calls one tool: id is the tool-use ID the journal keys the call under, name is the tool, and args is its JSON arguments.

Apache-2.0 licensed.