Class AgentInvocation

java.lang.Object
dev.langchain4j.agentic.observability.AgentInvocation

public class AgentInvocation extends Object
  • Method Details

    • done

      public boolean done()
    • suspended

      public boolean suspended()
      Returns true while the agentic system is suspended, for instance waiting for a human, with this invocation in progress: the root agent and the workflows containing the suspended step stay in progress until the system is resumed by invoking the root agent again, when they continue this same invocation. An agent still running in another branch of a parallel workflow also returns true, until it completes.
    • suspendedDuration

      public Duration suspendedDuration()
      Returns the total time the agentic system spent suspended during this invocation, counting an ongoing suspension until now, or zero if it never was: a loop whose step waits for a human adds up one wait per iteration. Once the invocation is finished, its duration() includes this time.
    • skipped

      public boolean skipped()
      Returns true if the agent was skipped instead of being invoked, because its activation condition was false or because it is optional and one of its arguments was missing.
    • skipReason

      public String skipReason()
      Returns why the agent was skipped, or null if it was invoked.
    • startTime

      public LocalDateTime startTime()
    • finishTime

      public LocalDateTime finishTime()
    • duration

      public Duration duration()
      Returns how long the invocation took, measured between two instants: a daylight saving time change in the meantime does not affect it, unlike the difference between startTime() and finishTime().
    • agent

      public AgentInstance agent()
    • agenticScope

      public AgenticScope agenticScope()
    • inputs

      public Map<String,Object> inputs()
    • output

      public Object output()
    • totalTokenCount

      public int totalTokenCount()
      Returns the total number of tokens of tokenUsage(), or zero if it is empty. For an agent whose planner calls a model itself, like a supervisor, it counts only those calls, and not the tokens of its subagents.
    • tokenUsage

      public Optional<TokenUsage> tokenUsage()
      Returns the token usage of an AI agent, which is the total of all its LLM calls when it calls tools, or of the decision call of a decision agent. For an agent whose planner calls a model itself, like a supervisor or a decision router, it is the total of those calls, without the token usage of its subagents, which is reported by their own invocations. It is empty if the agent called no model, like a workflow or a non-AI agent, if it was skipped, or if the provider didn't report the token usage.

      This method can be called at any time. For an agent whose planner calls a model itself it returns what those calls consumed so far, also while the invocation is in progress or suspended, and after it failed. The token usage of an AI agent or of a decision agent is only known when its invocation completes, so it is empty until then, and it stays empty when the invocation fails.

    • modelName

      public Optional<String> modelName()
      Returns the name of the model that answered the LLM calls of an AI agent, or the decision call of a decision agent, as reported by the provider in the response metadata. It is empty if the agent called no model, like a workflow or a non-AI agent, if it was skipped, if the provider didn't report the model name, or if the LLM calls of an AI agent (for example, the calls of a tool loop) were answered by different models, since tokenUsage() is the total of all those calls. In the same way, for an agent whose planner calls a model itself, like a supervisor or a decision router, it is the name of the model that answered all those calls, and it is empty if they were answered by different models.

      Like tokenUsage(), this method can be called at any time: it tells the model of the calls made so far by the planner of the agent, and it is empty for an AI agent or a decision agent whose invocation didn't complete.

    • decisionResponse

      public Optional<DecisionResponse> decisionResponse()
      Returns the response of the decision model of a decision agent, with its answers and their probabilities. It is empty for every other kind of agent, and if the agent was skipped.
    • iterationIndex

      public int iterationIndex()
      Returns the zero-based iteration index when this invocation is part of a loop, or -1 otherwise.
    • nestedInvocations

      public List<AgentInvocation> nestedInvocations()
    • toolExecutions

      public List<ToolExecution> toolExecutions()
    • toString

      public String toString()
      Overrides:
      toString in class Object