Class ToolContext

java.lang.Object
org.springframework.ai.chat.model.ToolContext

public class ToolContext extends Object
Represents the context for tool execution in a function calling scenario.

This class encapsulates a map of contextual information that can be passed to tools (functions) when they are called. It provides an immutable view of the context to ensure thread-safety and prevent modification after creation.

The context is typically populated from the toolContext field of FunctionCallingOptions and is used in the function execution process.

The context map can contain any information that is relevant to the tool execution.

Since:
1.0.0
Author:
Christian Tzolov
  • Field Details

    • TOOL_CALL_HISTORY

      public static final String TOOL_CALL_HISTORY
      The key for the running, tool call history stored in the context map.
      See Also:
  • Constructor Details

    • ToolContext

      public ToolContext(Map<String,Object> context)
      Constructs a new ToolContext with the given context map.
      Parameters:
      context - A map containing the tool context information. This map is wrapped in an unmodifiable view to prevent changes.
  • Method Details

    • getContext

      public Map<String,Object> getContext()
      Returns the immutable context map.
      Returns:
      An unmodifiable view of the context map.
    • getToolCallHistory

      public List<Message> getToolCallHistory()
      Returns the tool call history from the context map.
      Returns:
      The tool call history.