Class AgentSession

java.lang.Object
neqsim.util.agentic.AgentSession
All Implemented Interfaces:
Serializable

public class AgentSession extends Object implements Serializable
Tracks an AI agent workflow session from start to completion.

Records the sequence of phases an agent traverses while solving an engineering task (scope, research, analysis, validation, reporting). Each phase captures timing, tool invocations, validation outcomes, and the final result status. Sessions can be serialized to JSON for persistent logging and cross-session learning.

Workflow Phases:

  • SCOPE — Task classification, standards identification, context gathering
  • RESEARCH — Literature review, API discovery, pattern search
  • ANALYSIS — Simulation building, flash calculations, equipment sizing
  • VALIDATION — Result verification, benchmark comparison, mass/energy balance
  • REPORTING — Report generation, figure creation, results.json assembly

Usage:


AgentSession session = AgentSession.start("solve.task", "TEG dehydration sizing");
session.beginPhase(AgentSession.Phase.SCOPE);
session.recordToolUse("thermo.fluid", "Create SRK fluid with water");
session.endPhase(AgentSession.Phase.SCOPE);

session.beginPhase(AgentSession.Phase.ANALYSIS);
session.recordSimulationRun("process.run()", true, 2.3);
session.endPhase(AgentSession.Phase.ANALYSIS);

session.complete(AgentSession.Outcome.SUCCESS);
String json = session.toJson();

Version:
1.0
Author:
Even Solbraa
See Also:
  • Field Details

  • Constructor Details

    • AgentSession

      private AgentSession(String agentName, String taskDescription)
      Constructor.
      Parameters:
      agentName - name of the agent
      taskDescription - task description
  • Method Details

    • start

      public static AgentSession start(String agentName, String taskDescription)
      Start a new agent session.
      Parameters:
      agentName - name of the agent (e.g., "solve.task", "process.model")
      taskDescription - brief description of the engineering task
      Returns:
      new session instance
    • beginPhase

      public void beginPhase(AgentSession.Phase phase)
      Begin a workflow phase.
      Parameters:
      phase - the phase to start
    • endPhase

      public void endPhase(AgentSession.Phase phase)
      End a workflow phase.
      Parameters:
      phase - the phase to end
    • recordToolUse

      public void recordToolUse(String toolName, String description)
      Record a tool invocation during the session.
      Parameters:
      toolName - name of the tool or agent invoked
      description - what the tool was used for
    • recordSimulationRun

      public void recordSimulationRun(String description, boolean success, double durationSeconds)
      Record a simulation run and its outcome.
      Parameters:
      description - what simulation was run
      success - whether it succeeded
      durationSeconds - execution time in seconds
    • addMetadata

      public void addMetadata(String key, String value)
      Add metadata to the session.
      Parameters:
      key - metadata key
      value - metadata value
    • complete

      public void complete(AgentSession.Outcome outcome)
      Mark the session as complete.
      Parameters:
      outcome - the final outcome
    • fail

      public void fail(String reason)
      Mark the session as failed with a reason.
      Parameters:
      reason - failure reason
    • getSessionId

      public String getSessionId()
      Get the session ID.
      Returns:
      unique session identifier
    • getAgentName

      public String getAgentName()
      Get the agent name.
      Returns:
      agent name
    • getTaskDescription

      public String getTaskDescription()
      Get the task description.
      Returns:
      task description
    • getOutcome

      public AgentSession.Outcome getOutcome()
      Get the session outcome.
      Returns:
      outcome or null if not yet completed
    • getFailureReason

      public String getFailureReason()
      Get the failure reason.
      Returns:
      failure reason or null if not failed
    • getDurationSeconds

      public double getDurationSeconds()
      Get duration of the session in seconds.
      Returns:
      duration in seconds, or time since start if not yet completed
    • getSimulationRunCount

      public int getSimulationRunCount()
      Get the number of simulation runs.
      Returns:
      total simulation run count
    • getSuccessfulSimulationCount

      public int getSuccessfulSimulationCount()
      Get the number of successful simulation runs.
      Returns:
      successful run count
    • getToolInvocationCount

      public int getToolInvocationCount()
      Get the number of tool invocations.
      Returns:
      tool invocation count
    • getPhases

      public List<AgentSession.PhaseRecord> getPhases()
      Get the phases traversed.
      Returns:
      unmodifiable list of phase records
    • getToolInvocations

      public List<AgentSession.ToolInvocation> getToolInvocations()
      Get the tool invocations.
      Returns:
      unmodifiable list of tool invocations
    • getSimulationRuns

      public List<AgentSession.SimulationRun> getSimulationRuns()
      Get the simulation runs.
      Returns:
      unmodifiable list of simulation runs
    • toJson

      public String toJson()
      Serialize the session to JSON.
      Returns:
      JSON representation of the session