Class LlmSecretReference

java.lang.Object
com.agentforge4j.llm.LlmSecretReference

public final class LlmSecretReference extends Object
An opaque reference to an LLM provider credential, carried through neutral provider configuration so a raw credential value never has to travel through the wiring layer.

A reference is either:

  • literal — a direct credential value supplied programmatically (or already resolved by the embedding application); or
  • indirect — a scheme:key pointer (for example env:OPENAI_API_KEY) that an LlmSecretResolver turns into an LlmSecret at the point of use.

Deliberately a final class, not a record: a literal reference holds a credential value, so its toString() is fully redacted; an indirect reference renders only scheme:key (a key name is not a secret value).

  • Constructor Details

    • LlmSecretReference

      public LlmSecretReference()
  • Method Details

    • literal

      public static LlmSecretReference literal(String value)
      Creates a literal reference wrapping a direct credential value.
      Parameters:
      value - the credential value; must not be blank
      Returns:
      a literal reference
    • reference

      public static LlmSecretReference reference(String scheme, String key)
      Creates an indirect reference pointing at a credential held in an external source.
      Parameters:
      scheme - the source scheme, for example env or sysprop; must not be blank
      key - the lookup key within that source; must not be blank
      Returns:
      an indirect reference
    • parse

      public static LlmSecretReference parse(String raw)
      Parses a raw configuration value into a reference. A value of the form ${env:NAME} or ${sysprop:name} becomes an indirect reference; any other value is treated as a literal.
      Parameters:
      raw - the raw value; must not be blank
      Returns:
      the parsed reference
    • literalValue

      public String literalValue()
      Returns the literal credential value. Only valid for a literal reference.
      Returns:
      the literal value
      Throws:
      IllegalStateException - if this is an indirect reference
    • scheme

      public String scheme()
      Returns the source scheme of an indirect reference.
      Returns:
      the scheme, for example env
      Throws:
      IllegalStateException - if this is a literal reference
    • key

      public String key()
      Returns the lookup key of an indirect reference.
      Returns:
      the key
      Throws:
      IllegalStateException - if this is a literal reference
    • toString

      public String toString()
      Overrides:
      toString in class Object