Class AgentInvocation
java.lang.Object
dev.langchain4j.agentic.observability.AgentInvocation
-
Method Summary
Modifier and TypeMethodDescriptionagent()Returns the response of the decision model of a decision agent, with its answers and their probabilities.booleandone()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 betweenstartTime()andfinishTime().inputs()intReturns the zero-based iteration index when this invocation is part of a loop, or -1 otherwise.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.output()booleanskipped()Returnstrueif 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.Returns why the agent was skipped, ornullif it was invoked.booleanReturnstruewhile 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.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.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.toString()intReturns the total number of tokens oftokenUsage(), or zero if it is empty.
-
Method Details
-
done
public boolean done() -
suspended
public boolean suspended()Returnstruewhile 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 returnstrue, until it completes. -
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, itsduration()includes this time. -
skipped
public boolean skipped()Returnstrueif 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
Returns why the agent was skipped, ornullif it was invoked. -
startTime
-
finishTime
-
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 betweenstartTime()andfinishTime(). -
agent
-
agenticScope
-
inputs
-
output
-
totalTokenCount
public int totalTokenCount()Returns the total number of tokens oftokenUsage(), 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
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
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, sincetokenUsage()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
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
-
toolExecutions
-
toString
-