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
- func AskAllToolsPolicy(reason string) agentkit.Policy
- func AssertDeriveMessagesToolCallsAnswered(t *testing.T, sess agentkit.Session, ctx context.Context)
- func AssertEventAtLeast(t *testing.T, events []agentkit.SessionEvent, typ agentkit.EventType, min int)
- func AssertNoToolResultWithContent(t *testing.T, events []agentkit.SessionEvent, callID agentkit.ToolCallID, ...)
- func AssertSubagentParentSession(t *testing.T, events []agentkit.SessionEvent)
- func AssertToolResultContains(t *testing.T, events []agentkit.SessionEvent, callID agentkit.ToolCallID, ...)
- func Build[T any](t *testing.T, graph map[string]any, rootID string) T
- func CallTool(t *testing.T, ctx context.Context, tool agentkit.Tool, input string) string
- func ContentText(msg agentkit.ModelMessage) string
- func CountEvents(events []agentkit.SessionEvent, typ agentkit.EventType) int
- func DefaultAssembler(t *testing.T) agentkit.PromptAssembler
- func DefaultSubagentSmokeSteps() []llm.ScriptedStep
- func DenyAllToolsPolicy(reason string) agentkit.Policy
- func EmptyToolsRuntime(t *testing.T) agentkit.ToolRuntime
- func FindChildSessionID(t *testing.T, events []agentkit.SessionEvent) agentkit.SessionID
- func LoopTurnContext(effective, storeSession agentkit.SessionID, agentID agentkit.AgentID) context.Context
- func MustScripted(t *testing.T, steps ...llm.ScriptedStep) agentkit.LLMProvider
- func NewScriptedAgent(t *testing.T, cfg ScriptedAgentConfig) (agentkit.Agent, agentkit.SessionStore)
- func RepoRoot(t *testing.T) string
- func RunTurn(t *testing.T, ctx context.Context, ag agentkit.Agent, text string)
- func SeedCrashedToolCall(t *testing.T, store agentkit.SessionStore, sessionID agentkit.SessionID, ...) agentkit.Session
- func SessionEvents(t *testing.T, ctx context.Context, store agentkit.SessionStore, ...) []agentkit.SessionEvent
- func SubagentStart(t *testing.T, ev agentkit.SessionEvent) session.SubagentStartData
- func TempFileStore(t *testing.T) (agentkit.SessionStore, string)
- func ToolResult(t *testing.T, ev agentkit.SessionEvent) agentkit.ToolResult
- func ToolsRuntime(t *testing.T, deps tools.RuntimeDeps) agentkit.ToolRuntime
- func TurnContext(sessionID agentkit.SessionID, agentID agentkit.AgentID) context.Context
- type AllowAll
- type DenyAll
- type DirWorkspace
- type ScriptedAgentConfig
- type SubagentDelegateConfig
- type SubagentDelegateEnv
Constants ¶
const DefaultResearcherDef = `` /* 130-byte string literal not displayed */
Variables ¶
This section is empty.
Functions ¶
func AskAllToolsPolicy ¶ added in v0.1.10
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 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 ¶
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 ¶
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 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 ¶
func SessionEvents(t *testing.T, ctx context.Context, store agentkit.SessionStore, id agentkit.SessionID) []agentkit.SessionEvent
SessionEvents reads all events from a session id via the store.
func SubagentStart ¶
func SubagentStart(t *testing.T, ev agentkit.SessionEvent) session.SubagentStartData
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.
Types ¶
type AllowAll ¶
type AllowAll struct{}
AllowAll approves every tool execution.
func (AllowAll) Ask ¶
func (AllowAll) Ask(context.Context, agentkit.ApprovalRequest) (agentkit.ApprovalDecision, error)
type DenyAll ¶
type DenyAll struct{}
DenyAll rejects every tool execution.
func (DenyAll) Ask ¶
func (DenyAll) Ask(context.Context, agentkit.ApprovalRequest) (agentkit.ApprovalDecision, error)
type DirWorkspace ¶
DirWorkspace maps scoped rel paths (e.g. local:agents) to directories.
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.