Class ToolServiceContext
java.lang.Object
dev.langchain4j.service.tool.ToolServiceContext
- Direct Known Subclasses:
ToolServiceContext.Empty
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic class -
Constructor Summary
ConstructorsConstructorDescriptionToolServiceContext(List<ToolSpecification> toolSpecifications, Map<String, ToolExecutor> toolExecutors) Deprecated. -
Method Summary
Modifier and TypeMethodDescriptionReturns all available tool specifications configured for AI service.static ToolServiceContext.Builderbuilder()Returns dynamic tool providers that are re-evaluated before each LLM call.Returns effective tool specifications that should be included in the nextChatRequest.booleanReturns theGuardrailRequestParamsof the AI service invocation, which the tool guardrails receive in their requests (so they see the same context as the AI service guardrails, and their events reach the listeners registered for the invocation), if the invocation has any.inthashCode()Deprecated.usereturnBehavior(String)insteadreturnBehavior(String toolName) Returns the effectiveReturnBehaviorfor the given tool.Returns the key thatToolGuardrailService.bind(AiServiceTool)of the tool guardrail service returned for each tool, by tool name.Returns the service that executes the tool guardrails, and binds the tools that have no key (the tools that are provided while the invocation runs, or a framework did not bind), if one is set.Deprecated.useeffectiveTools()insteadtoString()
-
Constructor Details
-
ToolServiceContext
-
ToolServiceContext
@Deprecated(since="1.12.0") public ToolServiceContext(List<ToolSpecification> toolSpecifications, Map<String, ToolExecutor> toolExecutors) Deprecated.useToolServiceContext(Builder)instead
-
-
Method Details
-
effectiveTools
Returns effective tool specifications that should be included in the nextChatRequest.- See Also:
-
toolSpecifications
Deprecated.useeffectiveTools()insteadReturns effective tool specifications that should be included in the nextChatRequest.- See Also:
-
availableTools
Returns all available tool specifications configured for AI service. These tool specifications can be discovered/found by the LLM (seeToolSearchStrategy) and included in the nextChatRequest.- Since:
- 1.12.0
- See Also:
-
toolExecutors
-
returnBehaviors
- Since:
- 1.14.0
-
returnBehavior
Returns the effectiveReturnBehaviorfor the given tool. If the tool is unknown or has no explicitly configured behavior,ReturnBehavior.TO_LLMis returned.- Since:
- 1.14.0
-
immediateReturnTools
Deprecated.usereturnBehavior(String)instead -
dynamicToolProviders
Returns dynamic tool providers that are re-evaluated before each LLM call.- Since:
- 1.13.0
-
toolGuardrailKeys
Returns the key thatToolGuardrailService.bind(AiServiceTool)of the tool guardrail service returned for each tool, by tool name. The key carries the specification and the source of the tool, and the guardrails that apply to it.A tool without a key is bound on demand by the tool guardrail service when it is called, with its specification and executor from this context, so it gets at least the guardrails that apply to every tool: no tool skips the tool guardrails because it was not bound beforehand. A context without a tool guardrail service gets the one of the
ToolServicethat runs its tools, if it has one, and these keys are not used. A key from another tool guardrail service fails the call with anIllegalArgumentException.- Since:
- 1.25.0
-
toolGuardrailService
Returns the service that executes the tool guardrails, and binds the tools that have no key (the tools that are provided while the invocation runs, or a framework did not bind), if one is set.- Since:
- 1.25.0
-
guardrailRequestParams
Returns theGuardrailRequestParamsof the AI service invocation, which the tool guardrails receive in their requests (so they see the same context as the AI service guardrails, and their events reach the listeners registered for the invocation), if the invocation has any.It is absent when the context is not created by an AI service invocation. The tool guardrails then run with minimal parameters (an empty user message template and no variables).
- Since:
- 1.25.0
-
toBuilder
-
equals
-
hashCode
-
toString
-
builder
-
ToolServiceContext(Builder)instead