Package dev.dokimos.core.conversation
Record Class ConversationTrajectory
java.lang.Object
java.lang.Record
dev.dokimos.core.conversation.ConversationTrajectory
- Record Components:
messages- the list of messages in chronological orderscenario- a description of the test scenariometadata- additional metadata about the conversation
public record ConversationTrajectory(List<Message> messages, String scenario, Map<String,Object> metadata)
extends Record
Represents a complete conversation trajectory between a simulated user and an
application.
A trajectory captures the full history of messages exchanged during a multi-turn conversation, along with scenario information and metadata for evaluation.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for constructing conversation trajectories. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionReturns only the assistant messages from the conversation.builder()Creates a new builder for constructing trajectories.static ConversationTrajectoryempty()Creates an empty trajectory with no messages.final booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.booleanisEmpty()Checks if the conversation is empty.Returns the last assistant message in the conversation, if any.Returns the last message in the conversation, if any.Returns the last user message in the conversation, if any.messages()Returns the value of themessagesrecord component.metadata()Returns the value of themetadatarecord component.scenario()Returns the value of thescenariorecord component.Returns only the system messages from the conversation.Builds the actual-outputs map the agent evaluators read, identical in shape toAgentTrace.toOutputMap().Collapses the conversation into a singleAgentTrace: the final response is the last assistant message's content (or empty), the tool calls aretoolCalls(), reasoning is empty, and metadata carries the scenario and turn count.toJson()Serializes the trajectory to JSON for debugging and logging.Flattens every assistant turn's tool calls into one list, in chronological order.Groups tool calls per assistant turn, in order: one inner list per assistant message (each possibly empty).final StringtoString()Returns a string representation of this record class.Builds a test case for the deterministic tool-call evaluators, using the last user message as input.toTestCase(List<ToolDefinition> tools) Builds a test case for the deterministic tool-call and tool-definition evaluators, adding the tools the agent could call.toTestCase(List<ToolDefinition> tools, List<String> tasks) Builds a test case for the judge-based evaluators (TaskCompletionEvaluator,ToolArgumentHallucinationEvaluator).toText()Formats the conversation as a simple text transcript.intReturns the number of conversation turns (user-assistant message pairs).Returns only the user messages from the conversation.withMessage(Message message) Creates a new trajectory with an additional message appended.
-
Constructor Details
-
ConversationTrajectory
Compact constructor ensuring immutability.
-
-
Method Details
-
empty
Creates an empty trajectory with no messages.- Returns:
- an empty trajectory
-
builder
Creates a new builder for constructing trajectories.- Returns:
- a new builder
-
turnCount
public int turnCount()Returns the number of conversation turns (user-assistant message pairs).A turn is counted as a user message followed by an assistant response.
- Returns:
- the number of complete turns
-
userMessages
Returns only the user messages from the conversation.- Returns:
- list of user messages
-
assistantMessages
Returns only the assistant messages from the conversation.- Returns:
- list of assistant messages
-
systemMessages
Returns only the system messages from the conversation.- Returns:
- list of system messages
-
lastMessage
Returns the last message in the conversation, if any.- Returns:
- the last message or null if empty
-
lastUserMessage
Returns the last user message in the conversation, if any.- Returns:
- the last user message or null if none
-
lastAssistantMessage
Returns the last assistant message in the conversation, if any.- Returns:
- the last assistant message or null if none
-
toolCalls
Flattens every assistant turn's tool calls into one list, in chronological order. This is the flatList<ToolCall>the agent tool-call evaluators read.- Returns:
- all tool calls across the conversation, never null
-
toolCallsByTurn
Groups tool calls per assistant turn, in order: one inner list per assistant message (each possibly empty). This is the per-turn view for scoring each turn against its own expected calls. The unit of grouping is an assistant message, which can differ fromturnCount()(which counts user/assistant pairs) when a conversation has consecutive or trailing assistant messages.- Returns:
- tool calls grouped by assistant message, never null
-
toAgentTrace
Collapses the conversation into a singleAgentTrace: the final response is the last assistant message's content (or empty), the tool calls aretoolCalls(), reasoning is empty, and metadata carries the scenario and turn count. Intended for deterministic, scripted conversations; for non-deterministic simulated runs, prefer per-turn evaluation overtoolCallsByTurn().- Returns:
- the collapsed agent trace
-
toAgentOutputs
Builds the actual-outputs map the agent evaluators read, identical in shape toAgentTrace.toOutputMap().- Returns:
- the actual outputs map
-
toTestCase
Builds a test case for the deterministic tool-call evaluators, using the last user message as input.- Returns:
- a new test case
-
toTestCase
Builds a test case for the deterministic tool-call and tool-definition evaluators, adding the tools the agent could call.- Parameters:
tools- the available tool definitions- Returns:
- a new test case
-
toTestCase
Builds a test case for the judge-based evaluators (TaskCompletionEvaluator,ToolArgumentHallucinationEvaluator). The input is the full rendered transcript so the judge reasons over the whole conversation, but tool calls are rendered name-only ([tool: name], not[tool: name(args)]): the hallucination evaluator grounds against this input, so the argument values under test must not appear in it. The arguments stay available throughactualOutputs["toolCalls"].- Parameters:
tools- the available tool definitionstasks- the tasks the user asked the agent to complete- Returns:
- a new test case
-
withMessage
Creates a new trajectory with an additional message appended.- Parameters:
message- the message to append- Returns:
- a new trajectory with the message added
-
isEmpty
public boolean isEmpty()Checks if the conversation is empty.- Returns:
- true if there are no messages
-
toText
Formats the conversation as a simple text transcript.- Returns:
- the conversation as text
-
toJson
Serializes the trajectory to JSON for debugging and logging.- Returns:
- JSON representation of the trajectory
-
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object). -
messages
Returns the value of themessagesrecord component.- Returns:
- the value of the
messagesrecord component
-
scenario
Returns the value of thescenariorecord component.- Returns:
- the value of the
scenariorecord component
-
metadata
Returns the value of themetadatarecord component.- Returns:
- the value of the
metadatarecord component
-