Documentation
¶
Overview ¶
Package bondtest provides test utilities for the bond agent framework.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Repeat ¶
func Repeat(events []bond.StreamEvent) func(ctx context.Context, messages []bond.Message) iter.Seq2[bond.StreamEvent, error]
Repeat creates a StreamFunc that always returns the same events on every call.
func Sequence ¶
func Sequence(eventSets ...[]bond.StreamEvent) func(ctx context.Context, messages []bond.Message) iter.Seq2[bond.StreamEvent, error]
Sequence creates a StreamFunc that returns different events on each call. First call returns events[0], second returns events[1], etc. Wraps around if more calls are made than event sets provided.
func TextEvents ¶
func TextEvents(chunks ...string) []bond.StreamEvent
TextEvents creates a sequence of StreamEvents that emit text deltas followed by a stop event. Simulates a simple text response.
func ToolUseEvents ¶
func ToolUseEvents(toolUse *bond.ToolUseBlock) []bond.StreamEvent
ToolUseEvents creates a sequence of StreamEvents that emit a tool use request followed by a stop. Simulates the model requesting a tool call.
Types ¶
type Agent ¶
type Agent struct {
// Events is the sequence of events to emit on each Stream call.
Events []bond.StreamEvent
// Err, if set, is yielded as an error after all events are emitted.
Err error
// StreamFunc, if set, overrides Events/Err and provides full control.
// Use for dynamic test behavior (e.g., inspecting input messages).
StreamFunc func(ctx context.Context, messages []bond.Message) iter.Seq2[bond.StreamEvent, error]
}
Agent is a test agent that emits a preconfigured sequence of StreamEvents. Useful for deterministic testing of code that consumes bond.Agent.
Example:
agent := &bondtest.Agent{
Events: bondtest.TextEvents("Hello, ", "world!"),
}
resp, err := bond.Invoke(ctx, agent, bond.TextPrompt("hi"), bond.AgentOptions{})
// resp.Text == "Hello, world!"
type EchoAgent ¶
type EchoAgent struct{}
EchoAgent is a bond.Agent that echoes back the last user message content. Useful for testing pipelines where you need a predictable agent that reflects input without transformation.
Example:
agent := &bondtest.EchoAgent{}
resp, _ := bond.Invoke(ctx, agent, bond.TextPrompt("hello"), bond.AgentOptions{})
// resp.Text == "hello"