Class AgentModelResponse
java.lang.Object
dev.langchain4j.agentic.internal.AgentModelResponse
- All Implemented Interfaces:
LangChain4jManaged
The response of the model called by one invocation of an AI or decision agent, as reported to the agent's
listeners after the invocation. The invoker of the agent creates one instance per invocation and puts it, next to
the
AgenticScope, in the LangChain4jManaged parameters of the invocation, so that the handler
of the agent finds it in the invocation context of the AI service events it receives, on whatever thread they
arrive, and the invoker reads it once the agent method has returned.
The model call of an agent returning a TokenStream or a future completes on another thread, usually after
the invoker has already reported the invocation, so such a response is not reported; the state of this class is
guarded by its lock, so that a model call completing while the invoker reads it is never seen half-written.
-
Field Summary
Fields inherited from interface LangChain4jManaged
CURRENT -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidClaims this response for the handler running the agent method of the invocation.booleanvoidRecords one model call of the invocation: an agent calling tools makes several, and its reported response is the last one with the token usage of all of them, and the model name only when all the calls agree on it.voidonDecisionResponse(DecisionResponse decisionResponse)
-
Constructor Details
-
AgentModelResponse
public AgentModelResponse()
-
-
Method Details
-
claim
Claims this response for the handler running the agent method of the invocation. An agent invoked directly from inside another agent on the same thread, for instance by one of its tools, finds the response of the enclosing invocation already owned, so its model calls are ignored instead of being summed into it. -
isOwnedBy
-
onChatResponse
Records one model call of the invocation: an agent calling tools makes several, and its reported response is the last one with the token usage of all of them, and the model name only when all the calls agree on it. -
onDecisionResponse
-
chatRequest
-
chatResponse
-
lastUserMessage
-
decisionResponse
-