Jido.AI.Actions.LLM.Chat
(Jido AI v2.1.0)
View Source
A Jido.Action for chat-style LLM interactions with optional system prompts.
This action uses ReqLLM directly to generate chat-style responses from
language models. It supports model aliases via Jido.AI.resolve_model/1 and
optional system prompts for conversation context.
Parameters
model(optional) - Model alias (e.g.,:fast,:capable) or direct spec (e.g.,"anthropic:claude-haiku-4-5")prompt(required) - The user prompt to send to the LLMsystem_prompt(optional) - System prompt to guide the LLM's behaviormax_tokens(optional) - Maximum tokens to generate (default:1024)temperature(optional) - Sampling temperature 0.0-2.0 (default:0.7)timeout(optional) - Request timeout in milliseconds
Examples
# Basic chat
{:ok, result} = Jido.Exec.run(Jido.AI.Actions.LLM.Chat, %{
prompt: "What is Elixir?"
})
# With system prompt
{:ok, result} = Jido.Exec.run(Jido.AI.Actions.LLM.Chat, %{
model: :capable,
prompt: "Explain GenServers",
system_prompt: "You are an expert Elixir teacher.",
temperature: 0.5
})
# Direct model spec
{:ok, result} = Jido.Exec.run(Jido.AI.Actions.LLM.Chat, %{
model: "openai:gpt-4",
prompt: "Hello!"
})
Summary
Functions
Returns the Action metadata. Alias for to_json/0.
Returns the category of the Action.
Returns the description of the Action.
Returns the name of the Action.
Lifecycle hook called after Action execution.
Lifecycle hook called after output validation.
Lifecycle hook called after parameter validation.
Lifecycle hook called before output validation.
Lifecycle hook called before parameter validation.
Lifecycle hook called when an error occurs.
Returns the output schema of the Action.
Executes the chat action.
Returns the input schema of the Action.
Returns the tags associated with the Action.
Returns the Action metadata as a JSON-serializable map.
Converts the Action to an LLM-compatible tool format.
Validates the output result for the Action.
Validates the input parameters for the Action.
Returns the version of the Action.
Functions
Returns the Action metadata. Alias for to_json/0.
Returns the category of the Action.
Returns the description of the Action.
Returns the name of the Action.
Lifecycle hook called after Action execution.
Lifecycle hook called after output validation.
Lifecycle hook called after parameter validation.
Lifecycle hook called before output validation.
Lifecycle hook called before parameter validation.
Lifecycle hook called when an error occurs.
Returns the output schema of the Action.
Executes the chat action.
Returns
{:ok, result}- Successful response withtext,model, andusagekeys{:error, reason}- Error from ReqLLM or validation
Result Format
%{
text: "The LLM's response text",
model: "anthropic:claude-haiku-4-5",
usage: %{
input_tokens: 10,
output_tokens: 25,
total_tokens: 35
}
}
Returns the input schema of the Action.
Returns the tags associated with the Action.
Returns the Action metadata as a JSON-serializable map.
Converts the Action to an LLM-compatible tool format.
Validates the output result for the Action.
Examples
iex> defmodule ExampleAction do
...> use Jido.Action,
...> name: "example_action",
...> output_schema: [
...> result: [type: :string, required: true]
...> ]
...> end
...> ExampleAction.validate_output(%{result: "test", extra: "ignored"})
{:ok, %{result: "test", extra: "ignored"}}
iex> ExampleAction.validate_output(%{extra: "ignored"})
{:error, "Invalid output for Action: Required key :result not found"}
Validates the input parameters for the Action.
Examples
iex> defmodule ExampleAction do
...> use Jido.Action,
...> name: "example_action",
...> schema: [
...> input: [type: :string, required: true]
...> ]
...> end
...> ExampleAction.validate_params(%{input: "test"})
{:ok, %{input: "test"}}
iex> ExampleAction.validate_params(%{})
{:error, "Invalid parameters for Action: Required key :input not found"}
Returns the version of the Action.