Package com.tnsai.llm
Class LLMResolver
java.lang.Object
com.tnsai.llm.LLMResolver
Resolves the appropriate LLM client using a fallback chain.
Implements the LLM resolution hierarchy:
- Role's LLM - if role has dedicated LLM config
- Agent's LLM - fallback to agent's default LLM
- Error - if none configured and LLM is required
Note: LLM is required only when action type is LLM or LLM.
Usage - Simple
// Role → Agent fallback
Optional<LLMClient> llm = LLMResolver.resolve(agent, role);
Usage - With Builder
// Role → Agent fallback with config factory
LLMClient llm = LLMResolver.builder()
.roleLLMSpec(() -> roleLLMSpec)
.agentLLM(agent::llm)
.configFactory(cfg -> LLMClient.create(cfg.model(), cfg.temperature()))
.context(action.getName())
.resolve();
Resolution Examples
| Role Spec | Agent LLM | Result |
|---|---|---|
| claude | GPT-3.5 | claude (role) |
| null | GPT-3.5 | GPT-3.5 (agent) |
| null | null | ERROR |
- Author:
- TnsAI Team
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for LLM resolution with full fallback chain support.static final recordLLM configuration record for passing model settings.static final recordResult of LLM resolution with source tracking.static enumSource of the resolved LLM in the fallback chain. -
Method Summary
Modifier and TypeMethodDescriptionstatic LLMResolver.Builderbuilder()Creates a new builder for advanced LLM resolution with Action support.static booleanChecks if the given agent-role combination has an LLM configured.Resolves the LLM client for an agent without role context.Resolves the LLM client for the given agent and role.static LLMClientresolveOrThrow(Agent agent, Role role) Gets the LLM client or throws if none configured.
-
Method Details
-
resolve
Resolves the LLM client for the given agent and role.Resolution priority:
- Role's LLM (if set)
- Agent's LLM (if set)
- Empty (no LLM configured)
- Parameters:
agent- the agent (may have LLM configured)role- the role being executed (may have dedicated LLM)- Returns:
- the resolved LLM client, or empty if none configured
-
resolve
Resolves the LLM client for an agent without role context.- Parameters:
agent- the agent- Returns:
- the agent's LLM, or empty if none configured
-
hasLLM
Checks if the given agent-role combination has an LLM configured.- Parameters:
agent- the agentrole- the role (may be null)- Returns:
- true if LLM is available
-
resolveOrThrow
Gets the LLM client or throws if none configured.- Parameters:
agent- the agentrole- the role- Returns:
- the resolved LLM client
- Throws:
IllegalStateException- if no LLM is configured
-
builder
Creates a new builder for advanced LLM resolution with Action support.- Returns:
- a new builder instance
-