Class ScriptedLlmOperations
-
- All Implemented Interfaces:
-
com.embabel.agent.spi.LlmOperations
public final class ScriptedLlmOperations implements LlmOperations
A scripted LLM operations implementation for testing.
This allows tests to script exact sequences of:
Tool calls (with specific arguments)
Text responses
Object creation
The scripted operations track what was called for verification.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classScriptedLlmOperations.ScriptedActionRepresents a scripted action to take.
public final classScriptedLlmOperations.ToolCallRecord
-
Field Summary
Fields Modifier and Type Field Description private final List<ScriptedLlmOperations.ToolCallRecord>toolCallsMadeprivate final List<String>promptsReceived
-
Constructor Summary
Constructors Constructor Description ScriptedLlmOperations()
-
Method Summary
Modifier and Type Method Description final List<ScriptedLlmOperations.ToolCallRecord>getToolCallsMade()final List<String>getPromptsReceived()final ScriptedLlmOperationsscript(ScriptedLlmOperations.ScriptedAction action)Add a scripted action to the sequence. final ScriptedLlmOperationscallTool(String toolName, String inputJson)Script a tool call. final ScriptedLlmOperationsrespond(String text)Script a text response. final <T extends Any> ScriptedLlmOperationsreturnObject(T obj)Script returning an object. final Unitreset()Reset the script to start from the beginning. Stringgenerate(String prompt, LlmInteraction interaction, AgentProcess agentProcess, Action action)Generate text in the context of an AgentProcess. <O extends Any> OcreateObject(List<Message> messages, LlmInteraction interaction, Class<O> outputClass, AgentProcess agentProcess, Action action)Create an output object, in the context of an AgentProcess. <O extends Any> Result<O>createObjectIfPossible(List<Message> messages, LlmInteraction interaction, Class<O> outputClass, AgentProcess agentProcess, Action action)Try to create an output object in the context of an AgentProcess. <O extends Any> OdoTransform(List<Message> messages, LlmInteraction interaction, Class<O> outputClass, LlmRequestEvent<O> llmRequestEvent)Low level transform, not necessarily aware of platform -
-
Method Detail
-
getToolCallsMade
final List<ScriptedLlmOperations.ToolCallRecord> getToolCallsMade()
-
getPromptsReceived
final List<String> getPromptsReceived()
-
script
final ScriptedLlmOperations script(ScriptedLlmOperations.ScriptedAction action)
Add a scripted action to the sequence.
-
callTool
final ScriptedLlmOperations callTool(String toolName, String inputJson)
Script a tool call.
-
respond
final ScriptedLlmOperations respond(String text)
Script a text response.
-
returnObject
final <T extends Any> ScriptedLlmOperations returnObject(T obj)
Script returning an object.
-
generate
String generate(String prompt, LlmInteraction interaction, AgentProcess agentProcess, Action action)
Generate text in the context of an AgentProcess.
- Parameters:
prompt- Prompt to generate text frominteraction- Llm options and tool callbacks to use, plus unique identifieragentProcess- Agent process we are running withinaction- Action we are running within if we are running within an action
-
createObject
<O extends Any> O createObject(List<Message> messages, LlmInteraction interaction, Class<O> outputClass, AgentProcess agentProcess, Action action)
Create an output object, in the context of an AgentProcess.
- Parameters:
messages- messages in the conversation so far.interaction- Llm options and tool callbacks to use, plus unique identifieroutputClass- Class of the output objectagentProcess- Agent process we are running withinaction- Action we are running within if we are running within an action
-
createObjectIfPossible
<O extends Any> Result<O> createObjectIfPossible(List<Message> messages, LlmInteraction interaction, Class<O> outputClass, AgentProcess agentProcess, Action action)
Try to create an output object in the context of an AgentProcess. Return a failure result if the LLM does not have enough information to create the object.
- Parameters:
messages- messagesinteraction- Llm options and tool callbacks to use, plus unique identifieroutputClass- Class of the output objectagentProcess- Agent process we are running withinaction- Action we are running within if we are running within an action
-
doTransform
<O extends Any> O doTransform(List<Message> messages, LlmInteraction interaction, Class<O> outputClass, LlmRequestEvent<O> llmRequestEvent)
Low level transform, not necessarily aware of platform
- Parameters:
messages- messagesinteraction- The LLM call optionsoutputClass- Class of the output objectllmRequestEvent- Event already published for this request if one has been
-
-
-
-