LemonAgent.Types.AgentLoopConfig (lemon_agent v0.1.0)

View Source

Configuration for the agent loop.

Required Fields

  • model - The AI model to use
  • convert_to_llm - Function to convert agent messages to LLM-compatible messages

Optional Fields

  • transform_context - Transform applied to context before convert_to_llm (useful for context window management, injecting external context)
  • get_api_key - Resolves API key dynamically for each LLM call (useful for short-lived OAuth tokens)
  • get_steering_messages - Returns messages to inject mid-run for steering
  • get_follow_up_messages - Returns follow-up messages after agent would stop
  • max_tool_concurrency - Max number of concurrent tool calls (nil/:infinity = unbounded)
  • max_tool_turns - Max assistant turns that may execute tools before terminal fallback
  • tool_timeout_ms - Optional per-tool task timeout in milliseconds
  • tool_task_supervisor - Task supervisor used to run tools (defaults to LemonAgent.ToolTaskSupervisor)
  • tool_schema_snapshot - Per-run snapshot used for provider schemas and tool execution
  • stream_options - Options for streaming requests
  • stream_fn - Custom stream function (defaults to LemonAi.stream_simple/3)

Summary

Types

convert_to_llm_fn()

@type convert_to_llm_fn() :: ([LemonAgent.Types.agent_message()] ->
                          [LemonAi.Types.message()]
                          | {:ok, [LemonAi.Types.message()]}
                          | {:error, term()})

get_api_key_fn()

@type get_api_key_fn() :: (provider :: String.t() -> String.t() | nil)

get_follow_up_messages_fn()

@type get_follow_up_messages_fn() :: (-> [LemonAgent.Types.agent_message()])

get_steering_messages_fn()

@type get_steering_messages_fn() :: (-> [LemonAgent.Types.agent_message()])

stream_fn()

t()

@type t() :: %LemonAgent.Types.AgentLoopConfig{
  convert_to_llm: convert_to_llm_fn(),
  get_api_key: get_api_key_fn() | nil,
  get_follow_up_messages: get_follow_up_messages_fn() | nil,
  get_steering_messages: get_steering_messages_fn() | nil,
  max_tool_concurrency: pos_integer() | :infinity | nil,
  max_tool_turns: pos_integer() | :infinity | nil,
  model: LemonAi.Types.Model.t(),
  stream_fn: stream_fn() | nil,
  stream_options: LemonAi.Types.StreamOptions.t(),
  tool_schema_snapshot: LemonAgent.Types.ToolSchemaSnapshot.t() | nil,
  tool_task_supervisor: Supervisor.supervisor() | nil,
  tool_timeout_ms: pos_integer() | :infinity | nil,
  transform_context: transform_context_fn() | nil
}

transform_context_fn()

@type transform_context_fn() :: ([LemonAgent.Types.agent_message()],
                           signal :: reference() | nil ->
                             [LemonAgent.Types.agent_message()]
                             | {:ok, [LemonAgent.Types.agent_message()]}
                             | {:error, term()})