testGraph

Installs the Testing feature with graph testing enabled and executes the provided test block.

This is a convenience function that combines withTesting and graph to provide a clean API for testing agent graph structures. It allows you to define and validate the structure, behavior, and connections of nodes within an agent's graph.

Parameters

test

A lambda with receiver that configures the testing environment with assertions.

See also

Example usage:

// Create an agent with testing enabled
AIAgent(
promptExecutor = mockLLMApi,
toolRegistry = toolRegistry,
strategy = strategy,
eventHandler = eventHandler,
agentConfig = agentConfig,
) {
// Test the agent's graph structure
testGraph {
// Assert the order of stages
assertStagesOrder("first", "second")

// Test the first stage
stage("first") {
val start = startNode()
val finish = finishNode()

// Assert nodes by name
val askLLM = assertNodeByName<String, Message.Response>("callLLM")
val callTool = assertNodeByName<ToolCall.Signature, ToolCall.Result>("executeTool")

// Assert node reachability
assertReachable(start, askLLM)
assertReachable(askLLM, callTool)

// Test node behavior
assertNodes {
askLLM withInput "Hello" outputs Message.Assistant("Hello!")
askLLM withInput "Solve task" outputs toolCallMessage(CreateTool, CreateTool.Args("solve"))
}

// Test edge connections
assertEdges {
askLLM withOutput Message.Assistant("Hello!") goesTo giveFeedback
askLLM withOutput toolCallMessage(CreateTool, CreateTool.Args("solve")) goesTo callTool
}
}
}
}