Mojentic.Agents.BaseLLMAgent (Mojentic v1.2.0)

Copy Markdown View Source

A basic LLM agent with behaviour, tools, and broker.

This agent encapsulates an LLM broker, a set of tools, and behavioural instructions, providing a complete agent that can be used standalone or wrapped as a tool for delegation patterns.

Examples

alias Mojentic.Agents.BaseLLMAgent
alias Mojentic.LLM.Broker

broker = Broker.new("qwen3:7b", Mojentic.LLM.Gateways.Ollama)

agent = BaseLLMAgent.new(
  broker: broker,
  behaviour: "You are a helpful historian specializing in ancient civilizations.",
  tools: [DateResolver]
)

{:ok, response} = BaseLLMAgent.generate_response(agent, "When was Rome founded?")

Summary

Functions

Creates initial messages from the agent's behaviour.

Generates a response from the agent for the given input.

Creates a new BaseLLMAgent.

Types

t()

@type t() :: %Mojentic.Agents.BaseLLMAgent{
  behaviour: String.t(),
  broker: Mojentic.LLM.Broker.t(),
  tools: [module()] | nil
}

Functions

create_initial_messages(base_llm_agent)

Creates initial messages from the agent's behaviour.

Returns a list containing the system message with the agent's behaviour.

Examples

iex> agent = BaseLLMAgent.new(broker: broker, behaviour: "You are helpful.")
iex> BaseLLMAgent.create_initial_messages(agent)
[%Message{role: :system, content: "You are helpful."}]

generate_response(agent, content)

Generates a response from the agent for the given input.

Creates initial messages from the agent's behaviour, appends the user input, and calls the broker to generate a response using the agent's tools.

Parameters

  • agent: The BaseLLMAgent instance
  • content: The user input string

Returns

  • {:ok, response} on success
  • {:error, reason} on failure

Examples

{:ok, response} = BaseLLMAgent.generate_response(agent, "What is 2+2?")

new(opts)

Creates a new BaseLLMAgent.

Parameters

  • opts: Keyword list with:
    • :broker - LLM broker instance (required)
    • :behaviour - System message defining agent's personality and role (required)
    • :tools - List of tool modules (optional, default: nil)

Examples

broker = Broker.new("qwen3:32b", Ollama)

agent = BaseLLMAgent.new(
  broker: broker,
  behaviour: "You are a helpful assistant.",
  tools: [WeatherTool]
)