Skip to main content

Module profile_script

Module profile_script 

Source
Expand description

Lua scripted profile runtime.

Loads .lua profile scripts at startup, extracts their metadata (name, description, tools, arguments), and provides runtime resolution with a context bridge back into the Rust core (search, get, sources).

§Architecture

Profile scripts follow the same sandboxed Lua VM model as connectors and tools, reusing all host APIs from crate::lua_runtime. In addition, profiles receive a context table identical to tools:

  • context.search(query, opts?) — search the knowledge base
  • context.get(id) — retrieve a document by UUID
  • context.sources() — list connector status

The profile-specific config from ctx.toml is passed as the second argument to profile.resolve(args, config, context).

§Script Interface

Every profile script defines a global profile table. The historical agent global remains accepted for compatibility:

profile = {
    name = "my-profile",
    description = "Helps with tasks",
    tools = { "search", "get" },
    arguments = {
        { name = "topic", description = "Focus area", required = false },
    },
}

function profile.resolve(args, config, context)
    return {
        system = "You are a helpful assistant.",
        messages = {},
    }
end

§Configuration

[profiles.script.my_profile]
path = "profiles/my-profile.lua"
timeout = 30
search_limit = 5

See the profiles documentation for the full specification.

Structs§

LuaProfileAdapter
Adapter that wraps a Lua ProfileDefinition as a Profile trait object.
ProfileDefinition
Metadata extracted from a loaded Lua profile script.

Functions§

doc_response_to_lua 🔒
Convert a document response to a Lua table.
extract_arguments 🔒
Extract argument definitions from a Lua profile.arguments table.
extract_string_list 🔒
Extract a list of strings from a Lua table field.
get_profile_table 🔒
Return the canonical profile table, falling back to the legacy agent global so existing scripts continue to work unchanged.
list_profiles
List all configured profiles and print their info.
load_profile_definitions
Load all profile scripts from config and extract their definitions.
load_single_profile
Load a single profile script and extract its definition.
lua_result_to_profile_prompt 🔒
Convert the Lua profile.resolve() return value to a ProfilePrompt.
register_profile_context_bridge 🔒
Register the context table in the Lua VM for profile scripts.
resolve_profile
Resolve a profile script’s prompt.
run_lua_profile 🔒
Run the Lua profile synchronously on a blocking thread.
scaffold_profile
Scaffold a new profile script from a template.
search_results_to_lua 🔒
Convert search results to a Lua array table.
sources_to_lua 🔒
Convert source statuses to a Lua array table.
test_profile
Test a profile script by resolving its prompt.
truncate 🔒
Truncate a string to fit in a column.