Record Class PlanningContext

java.lang.Object
java.lang.Record
dev.langchain4j.agentic.planner.PlanningContext
Record Components:
agenticScope - the scope of the agentic system running the planner
previousAgentInvocation - the invocation of the subagent that just completed, or null for the first action
plannerAgent - the agent running the planner, or null when the context is not created by an agentic system, for instance in a unit test of the planner. The model responses reported to a context are notified only when this is an agent created by the agentic system.

public record PlanningContext(AgenticScope agenticScope, @Nullable AgentInvocation previousAgentInvocation, @Nullable AgentInstance plannerAgent) extends Record
The context in which a Planner decides its next action.
  • Constructor Details

  • Method Details

    • isActive

      public boolean isActive(AgentInstance agent)
      Tells whether the given subagent would run if it were invoked now, according to its activation condition. A planner never needs this for correctness, because an inactive agent is skipped when invoked anyway, but a planner selecting its candidates from the state of the AgenticScope can use it to avoid selecting inactive agents.

      The condition is evaluated each time this method is called and once more when the agent is invoked, so the agent can still be skipped if the state changed in between: the planner must handle a skipped invocation anyway. A condition throwing an exception is considered to hold here, so that the failure is raised, and handled by the error handler, when the agent is invoked.

      Parameters:
      agent - a subagent of the planner
      Returns:
      true if the agent has no activation condition, was already activated, or its condition holds
    • reportChatModelResponse

      public void reportChatModelResponse(@Nullable ChatResponse chatResponse)
      Reports the response of a chat model that the planner called itself to decide what to do. Its token usage and its model name are notified to the listeners of the agent running the planner, so that the token usage is counted on the invocation of that agent, for instance by the AgentMonitor: a model call that is not reported is invisible to them. Call it as soon as the model returns, once for each call.

      A planner calling its model through an AI service calls this method from an AiServiceResponseReceivedListener registered on that service, which receives each response of the model before the AI service parses it: so a response that cannot be parsed is reported too.

      It does nothing when this context has no planner agent created by the agentic system, or when the response is null.

      Parameters:
      chatResponse - the response returned by the chat model, or null, which is ignored
    • reportDecisionModelResponse

      public void reportDecisionModelResponse(@Nullable DecisionResponse decisionResponse)
      Reports the response of a decision model that the planner called itself to decide what to do, like reportChatModelResponse(ChatResponse) does for a chat model.
      Parameters:
      decisionResponse - the response returned by the decision model, or null, which is ignored
    • 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.
    • agenticScope

      public AgenticScope agenticScope()
      Returns the value of the agenticScope record component.
      Returns:
      the value of the agenticScope record component
    • previousAgentInvocation

      public @Nullable AgentInvocation previousAgentInvocation()
      Returns the value of the previousAgentInvocation record component.
      Returns:
      the value of the previousAgentInvocation record component
    • plannerAgent

      public @Nullable AgentInstance plannerAgent()
      Returns the value of the plannerAgent record component.
      Returns:
      the value of the plannerAgent record component