Package com.tnsai.metadata
Record Class ActionConfig
java.lang.Object
java.lang.Record
com.tnsai.metadata.ActionConfig
- Record Components:
name- the action name (LLM-facing, unique per role)description- human-readable description for the LLM tool catalogtype- the action type (typicallyActionType.LOCAL)parameters- parameter metadata (may be empty; the handler reads the map)handler- the dispatch callbackcontract- declarative DBC gates (ContractSpec.NONEif none); TNS-637inputGuardrail- per-action input guardrail (nullif none); TNS-643outputGuardrail- per-action output guardrail (nullif none); TNS-643
public record ActionConfig(String name, String description, ActionType type, List<ParamSpec> parameters, ActionHandler handler, ContractSpec contract, InputGuardrailConfig inputGuardrail, OutputGuardrailConfig outputGuardrail)
extends Record
Programmatic counterpart of
@ActionSpec (TNS-551) — declares a role
action via a builder instead of an annotated method, so
RoleBuilder.addAction(ActionConfig) can register
actions that an agent dispatches identically to annotation-derived ones.
Scoped to LOCAL (lambda-handler) actions for now — the common case
and the one with no annotation equivalent for the builder path. The richer
@ActionSpec fields (web-service config, LLM overrides, examples,
safety constraints) land incrementally as their builder forms are needed.
Placed in com.tnsai.metadata (not com.tnsai.actions) to
keep the package graph acyclic: com.tnsai.actions.ActionExecutor
already depends on com.tnsai.roles.Role, so a roles → actions
dependency (which RoleBuilder would introduce) would create a cycle.
- Since:
- 0.11.0
- Author:
- TnsAI Team
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionActionConfig(String name, String description, ActionType type, List<ParamSpec> parameters, ActionHandler handler, ContractSpec contract, InputGuardrailConfig inputGuardrail, OutputGuardrailConfig outputGuardrail) Creates an instance of aActionConfigrecord class. -
Method Summary
Modifier and TypeMethodDescriptioncontract()Returns the value of thecontractrecord component.Returns the value of thedescriptionrecord component.final booleanIndicates whether some other object is "equal to" this one.handler()Returns the value of thehandlerrecord component.final inthashCode()Returns a hash code value for this object.Returns the value of theinputGuardrailrecord component.static ActionConfiglocal(String name, String description, ActionHandler handler) ALOCALaction with no declared parameters — the handler reads the argument map directly.static ActionConfigALOCALaction with declared parameters (surfaced to the LLM tool schema, same as annotation actions).name()Returns the value of thenamerecord component.Returns the value of theoutputGuardrailrecord component.Returns the value of theparametersrecord component.Converts this config into the runtimeActionMetadatashape that reflection produces for@ActionSpecmethods — no reflectiveMethod; dispatch goes throughhandler().final StringtoString()Returns a string representation of this record class.type()Returns the value of thetyperecord component.withContract(ContractSpec contract) Returns a copy of this config with the givenContractSpecattached — the programmatic equivalent of annotating the action method with@Contract(TNS-637).withInputGuardrail(InputGuardrailConfig inputGuardrail) Returns a copy of this config with the given per-action input guardrail (TNS-643) — the programmatic equivalent of a method-level@InputGuardrail.withOutputGuardrail(OutputGuardrailConfig outputGuardrail) Returns a copy of this config with the given per-action output guardrail (TNS-643) — the programmatic equivalent of a method-level@OutputGuardrail.
-
Constructor Details
-
ActionConfig
public ActionConfig(String name, String description, ActionType type, List<ParamSpec> parameters, ActionHandler handler, ContractSpec contract, InputGuardrailConfig inputGuardrail, OutputGuardrailConfig outputGuardrail) Creates an instance of aActionConfigrecord class.- Parameters:
name- the value for thenamerecord componentdescription- the value for thedescriptionrecord componenttype- the value for thetyperecord componentparameters- the value for theparametersrecord componenthandler- the value for thehandlerrecord componentcontract- the value for thecontractrecord componentinputGuardrail- the value for theinputGuardrailrecord componentoutputGuardrail- the value for theoutputGuardrailrecord component
-
-
Method Details
-
local
ALOCALaction with no declared parameters — the handler reads the argument map directly. -
local
public static ActionConfig local(String name, String description, List<ParamSpec> parameters, ActionHandler handler) ALOCALaction with declared parameters (surfaced to the LLM tool schema, same as annotation actions). -
withContract
Returns a copy of this config with the givenContractSpecattached — the programmatic equivalent of annotating the action method with@Contract(TNS-637). Enforced at dispatch byContractValidator.RoleBuilder.addAction(ActionConfig.local("transfer", "...", handler) .withContract(ContractSpec.builder() .precondition("amount > 0") .postcondition("result.success()") .build())); -
withInputGuardrail
Returns a copy of this config with the given per-action input guardrail (TNS-643) — the programmatic equivalent of a method-level@InputGuardrail. Enforced at dispatch byInputGuardrailEnforcer, at method-level precedence (it overrides the role'sRoleBuilder.inputGuardrail(...)default).RoleBuilder.addAction(ActionConfig.local("transfer", "...", handler) .withInputGuardrail(InputGuardrailConfig.builder().maxLength(500).build()));- Parameters:
inputGuardrail- the per-action input guardrail;nullclears it- Returns:
- a copy with the guardrail attached
-
withOutputGuardrail
Returns a copy of this config with the given per-action output guardrail (TNS-643) — the programmatic equivalent of a method-level@OutputGuardrail. Enforced at dispatch byOutputGuardrailEnforcer, at method-level precedence (it overrides the role'sRoleBuilder.outputGuardrail(...)default).- Parameters:
outputGuardrail- the per-action output guardrail;nullclears it- Returns:
- a copy with the guardrail attached
-
toActionMetadata
Converts this config into the runtimeActionMetadatashape that reflection produces for@ActionSpecmethods — no reflectiveMethod; dispatch goes throughhandler(). -
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. -
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. -
equals
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 withObjects::equals(Object,Object). -
name
Returns the value of thenamerecord component.- Returns:
- the value of the
namerecord component
-
description
Returns the value of thedescriptionrecord component.- Returns:
- the value of the
descriptionrecord component
-
type
Returns the value of thetyperecord component.- Returns:
- the value of the
typerecord component
-
parameters
Returns the value of theparametersrecord component.- Returns:
- the value of the
parametersrecord component
-
handler
Returns the value of thehandlerrecord component.- Returns:
- the value of the
handlerrecord component
-
contract
Returns the value of thecontractrecord component.- Returns:
- the value of the
contractrecord component
-
inputGuardrail
Returns the value of theinputGuardrailrecord component.- Returns:
- the value of the
inputGuardrailrecord component
-
outputGuardrail
Returns the value of theoutputGuardrailrecord component.- Returns:
- the value of the
outputGuardrailrecord component
-