Record Class AgentTrace

java.lang.Object
java.lang.Record
dev.dokimos.core.agents.AgentTrace
Record Components:
finalResponse - the agent's final text response
toolCalls - all tool calls made during execution
reasoningSteps - optional reasoning/thought steps
metadata - latency, token usage, and other metadata

public record AgentTrace(String finalResponse, List<ToolCall> toolCalls, List<String> reasoningSteps, Map<String,Object> metadata) extends Record
Wraps a complete agent execution trace for evaluation.

Contains the agent's final text response, all tool calls made during execution, optional reasoning steps, and metadata such as latency and token usage.

The toOutputMap() method converts the trace to a map suitable for returning from a Task implementation.

  • Constructor Details

    • AgentTrace

      public AgentTrace(String finalResponse, List<ToolCall> toolCalls, List<String> reasoningSteps, Map<String,Object> metadata)
      Creates an instance of a AgentTrace record class.
      Parameters:
      finalResponse - the value for the finalResponse record component
      toolCalls - the value for the toolCalls record component
      reasoningSteps - the value for the reasoningSteps record component
      metadata - the value for the metadata record component
  • Method Details

    • toOutputMap

      public Map<String,Object> toOutputMap()
      Converts this agent trace to a map suitable for use as actualOutputs in an EvalTestCase.
      Returns:
      a map with keys "output", "toolCalls", and "reasoningSteps"
    • toTestCase

      public EvalTestCase toTestCase(String input)
      Builds an EvalTestCase from this trace for the given user input.
      Parameters:
      input - the user input the agent responded to
      Returns:
      a test case carrying this trace's outputs
      See Also:
    • toTestCase

      public EvalTestCase toTestCase(String input, List<ToolDefinition> tools)
      Builds an EvalTestCase from this trace, also wiring the available tool definitions into metadata.
      Parameters:
      input - the user input the agent responded to
      tools - the tool definitions available to the agent
      Returns:
      a test case carrying this trace's outputs and tool definitions
      See Also:
    • toTestCase

      public EvalTestCase toTestCase(String input, List<ToolDefinition> tools, List<String> tasks)
      Builds an EvalTestCase from this trace with everything the agent evaluators need in one call.

      This populates output, toolCalls and reasoningSteps in actual outputs, and tools and tasks in metadata. It exists so callers stop hitting EvaluationException when they forget to add the tools or tasks entries that ToolCallValidityEvaluator and TaskCompletionEvaluator require.

      Parameters:
      input - the user input the agent responded to (may be null)
      tools - the tool definitions available to the agent (may be null)
      tasks - the tasks the agent was asked to complete (may be null)
      Returns:
      a fully-populated test case
    • toolNames

      public Set<String> toolNames()
      Returns the set of tool names used in this trace.
      Returns:
      set of tool names
    • metadataAs

      public <T> T metadataAs(String key, Class<T> type)
      Reads the metadata entry stored under key and converts it into an instance of type.

      The value is already in memory, so this converts in place (no textual round-trip). An absent key (or a null stored value) yields null.

      Type Parameters:
      T - the target type
      Parameters:
      key - the metadata key
      type - the target class
      Returns:
      the converted value, or null if the key is absent or its value is null
      Throws:
      DokimosTypeConversionException - if the value cannot be converted to type
    • metadataAs

      public <T> T metadataAs(String key, OutputType<T> type)
      Reads the metadata entry stored under key and converts it into a generic target captured by an OutputType token, for example new OutputType<List<String>>() {}.

      An absent key (or a null stored value) yields null.

      Type Parameters:
      T - the target type
      Parameters:
      key - the metadata key
      type - the captured generic output type
      Returns:
      the converted value, or null if the key is absent or its value is null
      Throws:
      DokimosTypeConversionException - if the value cannot be converted to type
    • builder

      public static AgentTrace.Builder builder()
      Creates a new builder for constructing agent traces.
      Returns:
      a new builder
    • toString

      public final String 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.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • 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.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      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 with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • finalResponse

      public String finalResponse()
      Returns the value of the finalResponse record component.
      Returns:
      the value of the finalResponse record component
    • toolCalls

      public List<ToolCall> toolCalls()
      Returns the value of the toolCalls record component.
      Returns:
      the value of the toolCalls record component
    • reasoningSteps

      public List<String> reasoningSteps()
      Returns the value of the reasoningSteps record component.
      Returns:
      the value of the reasoningSteps record component
    • metadata

      public Map<String,Object> metadata()
      Returns the value of the metadata record component.
      Returns:
      the value of the metadata record component