agenttest

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 17 Imported by: 0

Documentation

Overview

Package agenttest provides shared helpers for AgentKit tests.

Tests should still assemble plugins through pluginkit/build; this package only removes duplicated wiring for scripted LLM runs, session assertions, and tool calls. See docs/guides/testing.zh.md for the full pyramid and CI tiers.

Index

Constants

View Source
const DefaultResearcherDef = `` /* 130-byte string literal not displayed */

Variables

This section is empty.

Functions

func AskAllToolsPolicy added in v0.1.10

func AskAllToolsPolicy(reason string) agentkit.Policy

AskAllToolsPolicy returns a policy that requires human approval for every tool call.

func AssertDeriveMessagesToolCallsAnswered

func AssertDeriveMessagesToolCallsAnswered(t *testing.T, sess agentkit.Session, ctx context.Context)

AssertDeriveMessagesToolCallsAnswered checks provider replay invariants.

func AssertEventAtLeast

func AssertEventAtLeast(t *testing.T, events []agentkit.SessionEvent, typ agentkit.EventType, min int)

AssertEventAtLeast fails when an event type appears fewer than min times.

func AssertNoToolResultWithContent

func AssertNoToolResultWithContent(t *testing.T, events []agentkit.SessionEvent, callID agentkit.ToolCallID, substr string)

AssertNoToolResultWithContent fails if any tool result for callID contains substr.

func AssertSubagentParentSession

func AssertSubagentParentSession(t *testing.T, events []agentkit.SessionEvent)

AssertSubagentParentSession verifies post-delegate parent session invariants.

func AssertToolResultContains

func AssertToolResultContains(t *testing.T, events []agentkit.SessionEvent, callID agentkit.ToolCallID, substr string)

AssertToolResultContains finds a tool result by call id and checks content.

func Build

func Build[T any](t *testing.T, graph map[string]any, rootID string) T

Build constructs a plugin instance from a pluginkit graph fragment.

func CallTool

func CallTool(t *testing.T, ctx context.Context, tool agentkit.Tool, input string) string

CallTool executes a tool with JSON input and returns raw JSON output.

func ContentText

func ContentText(msg agentkit.ModelMessage) string

ContentText joins text parts from a model message.

func CountEvents

func CountEvents(events []agentkit.SessionEvent, typ agentkit.EventType) int

CountEvents counts session events of a given type.

func DefaultAssembler

func DefaultAssembler(t *testing.T) agentkit.PromptAssembler

DefaultAssembler builds the standard prompt assembler used in smoke tests.

func DefaultSubagentSmokeSteps

func DefaultSubagentSmokeSteps() []llm.ScriptedStep

DefaultSubagentSmokeSteps matches presets/subagent-smoke.yaml scripted order.

func DenyAllToolsPolicy

func DenyAllToolsPolicy(reason string) agentkit.Policy

DenyAllToolsPolicy returns a policy that blocks all tool execution.

func EmptyToolsRuntime

func EmptyToolsRuntime(t *testing.T) agentkit.ToolRuntime

EmptyToolsRuntime returns a tool runtime with no tools and allow-all approval.

func FindChildSessionID

func FindChildSessionID(t *testing.T, events []agentkit.SessionEvent) agentkit.SessionID

FindChildSessionID reads the child session id from subagent/start.

func LoopTurnContext

func LoopTurnContext(effective, storeSession agentkit.SessionID, agentID agentkit.AgentID) context.Context

LoopTurnContext mimics loop/default seeding for store-session mapping tests.

func MustScripted

func MustScripted(t *testing.T, steps ...llm.ScriptedStep) agentkit.LLMProvider

MustScripted builds an llm/scripted provider or fails the test.

func NewScriptedAgent

func NewScriptedAgent(t *testing.T, cfg ScriptedAgentConfig) (agentkit.Agent, agentkit.SessionStore)

NewScriptedAgent builds an agent on a temp store unless Store is set.

func RepoRoot

func RepoRoot(t *testing.T) string

RepoRoot finds the module root containing go.mod.

func RunTurn

func RunTurn(t *testing.T, ctx context.Context, ag agentkit.Agent, text string)

RunTurn is a thin helper around agent.RunTurn with a user text message.

func SeedCrashedToolCall

func SeedCrashedToolCall(t *testing.T, store agentkit.SessionStore, sessionID agentkit.SessionID, agentID agentkit.AgentID, call agentkit.ToolCall, userText string) agentkit.Session

SeedCrashedToolCall writes an incomplete turn ending on a pending tool call.

func SessionEvents

SessionEvents reads all events from a session id via the store.

func SubagentStart

SubagentStart decodes a subagent/start event payload.

func TempFileStore

func TempFileStore(t *testing.T) (agentkit.SessionStore, string)

TempFileStore creates a session/store rooted at t.TempDir().

func ToolResult

func ToolResult(t *testing.T, ev agentkit.SessionEvent) agentkit.ToolResult

ToolResult decodes a tool/result event payload.

func ToolsRuntime

func ToolsRuntime(t *testing.T, deps tools.RuntimeDeps) agentkit.ToolRuntime

ToolsRuntime builds a tool runtime with optional policies and approval.

func TurnContext

func TurnContext(sessionID agentkit.SessionID, agentID agentkit.AgentID) context.Context

TurnContext returns a context seeded for agent.RunTurn.

Types

type AllowAll

type AllowAll struct{}

AllowAll approves every tool execution.

type DenyAll

type DenyAll struct{}

DenyAll rejects every tool execution.

type DirWorkspace

type DirWorkspace map[string]string

DirWorkspace maps scoped rel paths (e.g. local:agents) to directories.

func (DirWorkspace) Resolve

func (w DirWorkspace) Resolve(_ context.Context, rel string) (string, error)

type ScriptedAgentConfig

type ScriptedAgentConfig struct {
	AgentID  agentkit.AgentID
	MaxSteps int
	Steps    []llm.ScriptedStep
	Tools    agentkit.ToolRuntime
	Store    agentkit.SessionStore
}

ScriptedAgentConfig wires a minimal agent for smoke scenarios.

type SubagentDelegateConfig

type SubagentDelegateConfig struct {
	LogicalID     agentkit.SessionID
	ResearcherDef string
	Steps         []llm.ScriptedStep
	ParentAgentID agentkit.AgentID
}

SubagentDelegateConfig controls subagent smoke wiring.

type SubagentDelegateEnv

type SubagentDelegateEnv struct {
	Store     agentkit.SessionStore
	Agent     agentkit.Agent
	ParentID  agentkit.SessionID
	LogicalID agentkit.SessionID
	AgentsDir string
}

SubagentDelegateEnv wires a parent agent with a delegate tool and in-process subagent.

func NewSubagentDelegateEnv

func NewSubagentDelegateEnv(t *testing.T, cfg SubagentDelegateConfig) SubagentDelegateEnv

NewSubagentDelegateEnv builds a scripted parent→child delegate stack on a temp store.

Jump to

Keyboard shortcuts

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