Annotation Interface P
Tool-annotated method.
Description
value() and description() are aliases for the same thing: the parameter's description
that the LLM will see. Use one or the other, but not both at the same time.
When only a description is needed, value can be used as a shorthand:
@Tool
void getWeather(@P("The city name") String city) { ... }
When both a name and a description are needed, use named attributes:
@Tool
void getWeather(@P(name = "city", description = "The city name") String city) { ... }
Name
Thename() attribute overrides the parameter name that the LLM will see.
This is useful in two cases:
- Missing
-parametersjavac option. Without it (common when not using frameworks like Quarkus or Spring, which enable it by default), Java reflection returns generic names such asarg0,arg1, etc. The semantic meaning of the parameter is lost, which may confuse the LLM. Settingnamerestores a meaningful name. - Custom name for the LLM. When you want the LLM to see a different parameter name than the one the developer uses in the source code (for example, to match a specific API contract or to provide a more descriptive name).
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSentinel value fordefaultValue()meaning "no default set". -
Optional Element Summary
Optional ElementsModifier and TypeOptional ElementDescriptionDefault value to substitute when the LLM omits this argument.Description of the parameter.Name of the parameter as seen by the LLM.booleanWhether the parameter is required.Description of the parameter.
-
Field Details
-
NO_DEFAULT
Sentinel value fordefaultValue()meaning "no default set". Lets the framework distinguish between "the developer did not specify a default" and "the default is an empty string".- See Also:
-
-
Element Details
-
name
String nameName of the parameter as seen by the LLM.If not specified, the actual method parameter name is used (requires the
-parametersjavac option; otherwise the name defaults toarg0,arg1, etc.).Setting this is useful when:
- The
-parametersjavac option is not enabled and you want to avoid genericarg0/arg1names. Note that frameworks like Quarkus and Spring enable-parametersby default, so you typically do not need to setnamewhen using those frameworks. - You want the LLM to see a different name than the one in the source code.
- Returns:
- the name of the parameter
- Default:
""
- The
-
description
-
value
String valueDescription of the parameter. This is an alias fordescription(). Use eithervalueordescription, but not both.Convenient for the shorthand form:
@P("description here").- Returns:
- the description of the parameter
- Default:
""
-
required
boolean requiredWhether the parameter is required. Default istrue.The
requiredflag controls the JSON schema sent to the LLM: required parameters are listed in the schema'srequiredarray. The LLM is expected to honour this, but in practice it can disregard the schema and omit an argument anyway.1.x behaviour when a required argument is missing:
- Primitive parameters (
int,long,boolean, …) — detected and surfaced as aToolArgumentsException. - Object parameters — not validated;
nullis passed to theTool-annotated method, even though the schema marked the parameter as required.
- Returns:
trueif the parameter is required,falseotherwise
- Default:
true
- Primitive parameters (
-
defaultValue
String defaultValueDefault value to substitute when the LLM omits this argument.Setting a default value is equivalent to setting
required()tofalse: the parameter is marked as optional in the JSON schema sent to the LLM (it is not added to the schema'srequiredarray). When the LLM omits the argument, the framework substitutes this default at runtime instead of passingnull(or, for primitives, throwing).The string is parsed at AI Service registration time according to the parameter's type:
Stringparameters: used verbatim.- Primitives, boxed primitives, enums,
BigDecimal,BigInteger,UUID: parsed via type-specific conversion. - Collections, maps, POJOs: parsed as JSON
(e.g.
"[]","{\"name\":\"foo\"}").
Restrictions:
- Cannot be combined with
Optional<T>parameters (Optional already represents "absent"; pick one mechanism). - Cannot be set on framework-injected parameters
(
@ToolMemoryIdand similar).
- Returns:
- the default value as a string, or
NO_DEFAULTif not set
- Default:
"\u0000__LANGCHAIN4J_NO_DEFAULT__\u0000"
-