Configuration

Bilge uses a nested configuration system with BilgeConfig as the top-level struct. You can configure either an OpenAI-compatible backend (LLMConfig) or a local Ollama backend (OllamaConfig).


BilgeConfig

Top-level configuration. Set either llm or ollama (not both).

BilgeConfig(;
    llm::Union{LLMConfig, Nothing} = nothing,
    ollama::Union{OllamaConfig, Nothing} = nothing,
    max_tool_rounds::Int = 50,
    max_output_chars::Int = 100_000,
)
FieldTypeDefaultDescription
llmUnion{LLMConfig, Nothing}nothingOpenAI-compatible backend configuration
ollamaUnion{OllamaConfig, Nothing}nothingOllama backend configuration
max_tool_roundsInt50Maximum tool-call rounds per turn
max_output_charsInt100_000Truncate tool output beyond this limit

Examples

# OpenAI backend
config = BilgeConfig(
    llm = LLMConfig(api_key="sk-...")
)

# Ollama backend
config = BilgeConfig(
    ollama = OllamaConfig(model="qwen3")
)

# Custom limits
config = BilgeConfig(
    ollama = OllamaConfig(model="qwen3"),
    max_tool_rounds = 100,
    max_output_chars = 200_000,
)

LLMConfig

Configuration for OpenAI-compatible API backends.

LLMConfig(;
    api_key::String,
    model::String = "gpt-4o",
    base_url::String = "https://api.openai.com/v1",
    max_tokens::Int = 4096,
    temperature::Float64 = 0.1,
)
FieldTypeDefaultDescription
api_keyStringrequiredAPI key for authentication
modelString"gpt-4o"Model identifier
base_urlString"https://api.openai.com/v1"API base URL
max_tokensInt4096Maximum tokens in LLM response
temperatureFloat640.1Sampling temperature (lower = more deterministic)

Examples

# OpenAI GPT-4o (default)
llm = LLMConfig(api_key="sk-...")

# OpenAI with custom model
llm = LLMConfig(
    api_key = "sk-...",
    model = "gpt-4o-mini",
    max_tokens = 8192,
)

# Custom OpenAI-compatible API
llm = LLMConfig(
    api_key = "your-key",
    base_url = "https://api.together.xyz/v1",
    model = "meta-llama/Llama-3-70b-chat-hf",
)
API Key from Environment

When using the bilge() REPL function, the API key is automatically read from ENV["OPENAI_API_KEY"] if not provided explicitly.


OllamaConfig

Configuration for the Ollama backend. Supports both the native Ollama API (/api/chat) and the OpenAI-compatible endpoint (/v1/chat/completions).

OllamaConfig(;
    model::String = "llama3.1",
    host::String = "http://localhost:11434",
    max_tokens::Int = 4096,
    temperature::Float64 = 0.1,
    use_openai_compat::Bool = false,
)
FieldTypeDefaultDescription
modelString"llama3.1"Ollama model name
hostString"http://localhost:11434"Ollama server address
max_tokensInt4096Maximum tokens in response
temperatureFloat640.1Sampling temperature
use_openai_compatBoolfalseUse /v1/chat/completions instead of /api/chat

Examples

# Default Ollama (native API)
ollama = OllamaConfig(model="qwen3")

# Ollama with OpenAI-compatible endpoint
ollama = OllamaConfig(
    model = "qwen3",
    use_openai_compat = true,
)

# Remote Ollama server
ollama = OllamaConfig(
    model = "llama3.1",
    host = "http://192.168.1.100:11434",
    max_tokens = 8192,
)
Native vs OpenAI-Compatible

The native Ollama API (/api/chat) is the default and generally works well. The OpenAI-compatible endpoint (/v1/chat/completions) can be useful for models that have better tool-calling support through the OpenAI format.


State Types

BilgeState

Mutable state maintained across the session. Created automatically by BilgeAgent.

FieldTypeDescription
working_directoryStringCurrent working directory
conversation_historyVector{Message}Full conversation history
turn_countIntNumber of completed turns
total_tokens_inIntCumulative input tokens
total_tokens_outIntCumulative output tokens

TurnResult

Returned by process_turn after each conversation turn.

FieldTypeDescription
responseStringThe LLM's final text response
tool_executionsVector{ToolExecution}Record of each tool call
input_tokensIntTokens consumed this turn
output_tokensIntTokens generated this turn

ToolExecution

Record of a single tool execution.

FieldTypeDescription
tool_nameStringName of the tool (e.g., "read_file")
argumentsDict{String, Any}Arguments passed to the tool
resultStringJSON-serialized tool result
duration_msIntExecution time in milliseconds