Package 'Rbebelm'

Title: Generic 'R' Agent Framework and 'BebeLM' 'CPU' Backend
Description: Provides a backend-agnostic 'R' agent framework with 'S7'/'s7contract' interfaces for language-model providers, extensions, skills, prompt templates, frontend/TUI command catalogs, event streams, fuzzy file search, and append-only 'JSONL' session trees. It also includes a concrete native backend wrapping the pure-Rust 'BebeLM' 'CPU'-only inference library <https://github.com/maximecb/bebelm> and a native FFF fuzzy file finder <https://github.com/dmtrKovalenko/fff>. The native layer is structured as runtime-selected Rust backends so portable 'R' binaries can avoid build-host-specific SIMD assumptions while still using optimized backends when available.
Authors: Sounkou Mahamane Toure [aut, cre], Maxime Chevalier-Boisvert [cph] (BebeLM upstream), Dmitriy Kovalenko [cph] (FFF fuzzy file finder), Hiroaki Yutani [cph] (savvy R/Rust interface)
Maintainer: Sounkou Mahamane Toure <[email protected]>
License: GPL (>= 3)
Version: 0.2.0-0.1.0
Built: 2026-06-10 02:57:49 UTC
Source: https://github.com/sounkou-bioinfo/Rbebelm

Help Index


Create a persistent BebeLM agent

Description

A BebelAgent owns an independent token transcript and decode cache while sharing the loaded model weights. This mirrors upstream ⁠bebelm::agent::Agent⁠.

Usage

bebel_agent(
  model,
  greedy = FALSE,
  max_gen = NULL,
  max_context = NULL,
  max_think = NULL,
  temperature = NULL,
  top_k = NULL,
  repeat_penalty = NULL
)

Arguments

model

A BebelModel object.

greedy

Use deterministic greedy decoding.

max_gen, max_context, max_think

Optional generation limits.

temperature, top_k, repeat_penalty

Optional sampling settings.

Value

A BebelAgent object.


Configure a BebeLM agent

Description

Configure a BebeLM agent

Usage

bebel_agent_configure(
  agent,
  greedy = NULL,
  max_gen = NULL,
  max_context = NULL,
  max_think = NULL,
  temperature = NULL,
  top_k = NULL,
  repeat_penalty = NULL
)

Arguments

agent

A BebelAgent object.

greedy

Use deterministic greedy decoding.

max_gen, max_context, max_think

Optional generation limits.

temperature, top_k, repeat_penalty

Optional sampling settings.

Value

Updated agent info.


Generate a raw continuation from a BebeLM agent transcript

Description

Generate a raw continuation from a BebeLM agent transcript

Usage

bebel_agent_generate(
  agent,
  on_event = bebel_console_event(),
  check_interrupt = TRUE
)

Arguments

agent

A BebelAgent object.

on_event

Event callback, named list of event-specific handlers, or NULL. Event types are bebel_event_types(). Delta events contain delta, id, and index; final events contain accumulated content or text. Use bebel_console_event() for live console output.

check_interrupt

Check for Ctrl-C during prefill and before every decoded token.

Value

A classed generation result.


Inspect a BebeLM agent

Description

Inspect a BebeLM agent

Usage

bebel_agent_info(agent)

Arguments

agent

A BebelAgent object.

Value

Named list of state and configuration.


Create a stateful BebeLM agent loop

Description

bebel_agent_loop() is the UI-independent controller inspired by Pi's Agent/AgentSession versus InteractiveMode split. It owns lifecycle state, queues, policy, hooks, and tool dispatch. Consoles, RPC handlers, and TUIs should consume this loop rather than embedding agent business logic.

Usage

bebel_agent_loop(
  agent,
  tools = list(),
  context = new.env(parent = emptyenv()),
  policy = bebel_loop_policy(),
  hooks = list(),
  extensions = list(),
  session = TRUE,
  parse_tool_call = bebel_parse_tool_calls,
  on_event = NULL,
  check_interrupt = TRUE
)

Arguments

agent

An object implementing BebelAgentBackend.

tools

A list of bebel_tool() objects or named functions.

context

Private mutable context passed to tools and hooks.

policy

A bebel_loop_policy() object.

hooks

Optional named hooks. Loop hooks may observe state_change, queue_update, message_start, message_end, model_event, tool_request, tool_result, tool_error, tool_denied, observation, command_start, command_end, and loop_end.

extensions

Optional list of bebel_extension() objects.

session

Session persistence setting. TRUE creates an bebelSession under bebel_session_dir(), FALSE/NULL disables persistence, an bebelSession reuses that store, and a character path opens a JSONL session.

parse_tool_call

Function converting tool-call text into one or more call records.

on_event

Optional event callback or handler list for model stream events.

check_interrupt

Check for Ctrl-C during generation.

Value

A bebelAgentLoop environment.


Run a BebeLM agent with R tool dispatch

Description

This is an Agent-first orchestration loop. It observes tool_call_end events, parses tool calls, invokes matching R tools with private context, appends tool results to the agent transcript, and continues generation.

Usage

bebel_agent_run(
  agent,
  tools = list(),
  context = new.env(parent = emptyenv()),
  hooks = list(),
  parse_tool_call = bebel_parse_tool_calls,
  max_steps = 4,
  on_event = NULL,
  check_interrupt = TRUE
)

Arguments

agent

A BebelAgent object.

tools

A list of bebel_tool() objects or named functions.

context

Private run context passed to tools and hooks but not appended to the model transcript.

hooks

Optional named list of hooks: turn_start, event, tool_request, tool_result, tool_error, turn_end.

parse_tool_call

Function converting tool-call content to either one list(name, arguments, raw) or a list of such calls.

max_steps

Maximum assistant/tool iterations.

on_event

Optional event callback or handler list for model events.

check_interrupt

Check for Ctrl-C during generation.

Value

A bebelAgentRun list with turns, tool calls, and final agent info.


Create an Rbebelm agent tool specification

Description

This is a small metadata layer on top of bebel_tool(). It keeps a JSON-schema-like parameter specification next to the executable R function so the same tool catalog can be used by the console agent and the RPC surface.

Usage

bebel_agent_tool(name, description, params = list(), fun)

Arguments

name

Tool name.

description

Short description shown to the model and clients.

params

Named list of parameter specifications. Each entry may contain type, description, required, and enum.

fun

Function called as fun(args, context, call) or any subset of those names, following bebel_tool() conventions.

Value

A bebelAgentTool object.


Describe an Rbebelm agent tool catalog

Description

Describe an Rbebelm agent tool catalog

Usage

bebel_agent_tool_catalog(tools)

Arguments

tools

A tool list accepted by bebel_r_agent().

Value

A data frame with tool names and descriptions.


Append raw text to a BebeLM agent transcript

Description

Append raw text to a BebeLM agent transcript

Usage

bebel_append(agent, text)

Arguments

agent

A BebelAgent object.

text

Raw text to append.

Value

Invisibly returns agent.


Append an upstream BebeLM system turn to an agent transcript

Description

Delegates ChatML system-turn rendering to upstream BebeLM. When tools are supplied, their schemas are rendered in upstream's ⁠List of tools: [...]⁠ system-block preamble before message.

Usage

bebel_append_system(agent, message, tools = NULL)

Arguments

agent

A BebelAgent object.

message

System instruction text.

tools

Optional list of bebel_tool() objects or named functions to advertise.

Value

Invisibly returns agent.


Render and append a system prompt to an agent backend

Description

Render and append a system prompt to an agent backend

Usage

bebel_append_system_prompt(
  agent,
  provider,
  name = "system",
  data = list(),
  skill_provider = NULL,
  skills = character(),
  tools = NULL
)

Arguments

agent

Object implementing BebelAgentBackend.

provider

Object implementing BebelPromptTemplateProvider.

name

Prompt template name.

data

Template data.

skill_provider

Optional object implementing BebelSkillProvider.

skills

Character vector of skill names to append.

tools

Optional backend-native tool declarations.

Value

agent, invisibly.


Append token ids to a BebeLM agent transcript

Description

Append token ids to a BebeLM agent transcript

Usage

bebel_append_tokens(agent, ids)

Arguments

agent

A BebelAgent object.

ids

Integer token ids.

Value

Invisibly returns agent.


Append a ChatML tool result turn to a BebeLM agent transcript

Description

Append a ChatML tool result turn to a BebeLM agent transcript

Usage

bebel_append_tool_result(agent, content)

Arguments

agent

A BebelAgent object.

content

Tool result content to append.

Value

Invisibly returns agent.


Append a ChatML user turn to a BebeLM agent transcript

Description

Append a ChatML user turn to a BebeLM agent transcript

Usage

bebel_append_user(agent, message)

Arguments

agent

A BebelAgent object.

message

User message.

Value

Invisibly returns agent.


Generate and close an assistant ChatML turn from a BebeLM agent

Description

Generate and close an assistant ChatML turn from a BebeLM agent

Usage

bebel_assistant_turn(
  agent,
  on_event = bebel_console_event(),
  check_interrupt = TRUE
)

Arguments

agent

A BebelAgent object.

on_event

Event callback, named list of event-specific handlers, or NULL. Event types are bebel_event_types(). Delta events contain delta, id, and index; final events contain accumulated content or text. Use bebel_console_event() for live console output.

check_interrupt

Check for Ctrl-C during prefill and before every decoded token.

Value

A classed generation result.


Open an assistant turn and stop when a tool call closes

Description

This low-level variant mirrors upstream BebeLM's tool driver stop semantics: generation stops with stop == "tool_call" after ⁠<|tool_call_end|>⁠ so the caller can execute the requested tool(s) and append one tool-result turn. Most users should prefer bebel_agent_run().

Usage

bebel_assistant_turn_tool_stop(
  agent,
  on_event = bebel_console_event(),
  check_interrupt = TRUE
)

Arguments

agent

A BebelAgent object.

on_event

Event callback, named list of event-specific handlers, or NULL. Event types are bebel_event_types(). Delta events contain delta, id, and index; final events contain accumulated content or text. Use bebel_console_event() for live console output.

check_interrupt

Check for Ctrl-C during prefill and before every decoded token.

Value

A bebelAssistantTurnResult list.


Append a system message to an agent backend

Description

Append a system message to an agent backend

Usage

bebel_backend_append_system(agent, message, tools = NULL)

Arguments

agent

An object implementing BebelAgentBackend.

message

System message text.

tools

Optional backend-native tool declarations.


Append a tool result to an agent backend

Description

Append a tool result to an agent backend

Usage

bebel_backend_append_tool_result(agent, content)

Arguments

agent

An object implementing BebelAgentBackend.

content

Tool result content.


Append a user message to an agent backend

Description

Append a user message to an agent backend

Usage

bebel_backend_append_user(agent, message)

Arguments

agent

An object implementing BebelAgentBackend.

message

User message text.


Run one assistant turn on an agent backend

Description

Run one assistant turn on an agent backend

Usage

bebel_backend_assistant_turn(
  agent,
  on_event = NULL,
  check_interrupt = TRUE,
  stop_on_tool_call = FALSE
)

Arguments

agent

An object implementing BebelAgentBackend.

on_event

Optional stream event callback.

check_interrupt

Check for Ctrl-C during generation.

stop_on_tool_call

Stop after a tool-call delimiter when supported.


Clear an agent backend

Description

Clear an agent backend

Usage

bebel_backend_clear(agent)

Arguments

agent

An object implementing BebelAgentBackend.


Return agent backend information

Description

Return agent backend information

Usage

bebel_backend_info(agent)

Arguments

agent

An object implementing BebelAgentBackend.


Return agent backend transcript text

Description

Return agent backend transcript text

Usage

bebel_backend_transcript(agent)

Arguments

agent

An object implementing BebelAgentBackend.


Generate a single ChatML assistant reply

Description

Generate a single ChatML assistant reply

Usage

bebel_chat(
  model,
  message,
  greedy = FALSE,
  on_event = bebel_console_event(),
  check_interrupt = TRUE,
  max_gen = NULL,
  max_context = NULL,
  max_think = NULL,
  temperature = NULL,
  top_k = NULL,
  repeat_penalty = NULL
)

Arguments

model

A BebelModel object.

message

User message.

greedy

Use deterministic greedy decoding.

on_event

Event callback, named list of event-specific handlers, or NULL. Event types are bebel_event_types(). Delta events contain delta, id, and index; final events contain accumulated content or text. Use bebel_console_event() for live console output.

check_interrupt

Check for Ctrl-C during prefill and before every decoded token.

max_gen, max_context, max_think

Optional generation limits.

temperature, top_k, repeat_penalty

Optional sampling settings.


Clear a BebeLM agent transcript and caches

Description

Clears the conversation state while keeping the loaded model weights and the agent's generation configuration. This is the helper form of agent$clear().

Usage

bebel_clear(agent)

Arguments

agent

A BebelAgent object.

Value

Updated agent info.


Console event handler for generated text and thinking

Description

Returns an event handler suitable for on_event. Thinking blocks are printed with ⁠<think>⁠ markers, text deltas are printed as they arrive, and done events add a trailing newline.

Usage

bebel_console_event()

Value

A function accepting one generation event list.


Built-in R session tools for the Rbebelm agent layer

Description

The default catalog is intentionally small. It exposes read-only file and R session inspection tools plus optional R evaluation and plot rendering. These are ordinary R functions and run in the current R process. Plot rendering is device-backed: options(Rbebelm.graphics.device=) or the RBEBELM_GRAPHICS_DEVICE environment variable may be "auto", "native", "png", "jgd", or "devout-ascii".

Usage

bebel_default_r_tools(
  env = .GlobalEnv,
  cwd = getwd(),
  allow_eval = FALSE,
  max_chars = 4000L
)

Arguments

env

Environment used by r_objects, r_eval, and r_plot.

cwd

Working directory for file and plot tools.

allow_eval

Whether to include the r_eval and r_plot tools. If FALSE, code-evaluation tools are not advertised to the model.

max_chars

Maximum characters returned from a single tool.

Value

A named list of bebelAgentTool objects.


Decode BebeLM token ids

Description

Decode BebeLM token ids

Usage

bebel_detokenize(model, ids)

Arguments

model

A BebelModel object.

ids

Integer token ids.

Value

Decoded text.


Build a BebeLM generation event handler

Description

bebel_event_handler() creates a single on_event callback from handlers for individual event types. Current event types are returned by bebel_event_types().

Usage

bebel_event_handler(
  start = NULL,
  thinking_start = NULL,
  thinking_delta = NULL,
  thinking_end = NULL,
  text_start = NULL,
  text_delta = NULL,
  text_end = NULL,
  tool_list_start = NULL,
  tool_list_delta = NULL,
  tool_list_end = NULL,
  tool_call_start = NULL,
  tool_call_delta = NULL,
  tool_call_end = NULL,
  done = NULL,
  default = NULL
)

Arguments

start, thinking_start, thinking_delta, thinking_end, text_start, text_delta, text_end

Optional functions called for the corresponding stream event.

tool_list_start, tool_list_delta, tool_list_end

Optional handlers for BebeLM tool-list delimiter blocks.

tool_call_start, tool_call_delta, tool_call_end

Optional handlers for BebeLM tool-call delimiter blocks.

done

Function called for the final done event, or NULL.

default

Function called for events without a type-specific handler, or NULL.

Value

A function accepting one generation event list.


Return BebeLM stream event types.

Description

Return BebeLM stream event types.

Usage

bebel_event_types()

Define an agent-loop extension

Description

Extensions contribute tools, commands, hooks, and optional UI metadata to the agent loop. They are registered into bebel_agent_loop() and are deliberately UI-independent: the standalone ⁠tui/⁠ Rust frontend can consume the same command/metadata catalog without owning business logic.

Usage

bebel_extension(
  name,
  tools = list(),
  commands = list(),
  hooks = list(),
  skill_providers = list(),
  prompt_template_providers = list(),
  keybindings = list(),
  widgets = list(),
  metadata = list()
)

Arguments

name

Extension name.

tools

Optional list of bebel_tool() objects or named functions.

commands

Optional list of bebel_loop_command() objects or named functions.

hooks

Optional named hook list.

skill_providers

Optional named list of objects implementing BebelSkillProvider.

prompt_template_providers

Optional named list of objects implementing BebelPromptTemplateProvider.

keybindings

Optional metadata for TUI consumers.

widgets

Optional metadata for TUI consumers.

metadata

Optional extension metadata.

Value

A bebelExtension object.


Return commands contributed by an extension

Description

Return commands contributed by an extension

Usage

bebel_extension_commands(extension)

Arguments

extension

An object implementing BebelAgentExtension.


Return hooks contributed by an extension

Description

Return hooks contributed by an extension

Usage

bebel_extension_hooks(extension)

Arguments

extension

An object implementing BebelAgentExtension.


Return an extension manifest

Description

Return an extension manifest

Usage

bebel_extension_manifest(extension)

Arguments

extension

An object implementing BebelAgentExtension.


Return prompt-template providers contributed by an extension

Description

Return prompt-template providers contributed by an extension

Usage

bebel_extension_prompt_template_providers(extension)

Arguments

extension

An object implementing BebelAgentExtension.


Return skill providers contributed by an extension

Description

Return skill providers contributed by an extension

Usage

bebel_extension_skill_providers(extension)

Arguments

extension

An object implementing BebelAgentExtension.


Return tools contributed by an extension

Description

Return tools contributed by an extension

Usage

bebel_extension_tools(extension)

Arguments

extension

An object implementing BebelAgentExtension.


Create a native fuzzy file finder

Description

bebel_file_finder() creates a persistent native FFF/fff-c-based file index for a project directory. bebel_file_search() queries that index and returns a data frame suitable for consoles, RPC clients, and the standalone ⁠tui/⁠ file picker.

Usage

bebel_file_finder(
  root = getwd(),
  frecency_db_path = "",
  history_db_path = "",
  enable_mmap_cache = FALSE,
  enable_content_indexing = FALSE,
  watch = FALSE,
  ai_mode = TRUE,
  wait_timeout_ms = 10000
)

bebel_file_search(
  finder = getwd(),
  query = "",
  current_file = "",
  max_threads = 0,
  offset = 0,
  limit = 50,
  combo_boost_score_multiplier = 100,
  min_combo_count = 3,
  wait_timeout_ms = 10000
)

Arguments

root

Project directory to index.

frecency_db_path

Optional FFF frecency database path. Empty string disables frecency persistence.

history_db_path

Optional FFF query-history database path. Empty string disables query-history persistence.

enable_mmap_cache

Enable FFF mmap cache warmup.

enable_content_indexing

Enable FFF content indexing.

watch

Start FFF's filesystem watcher for live updates.

ai_mode

Use FFF's AI-agent mode.

wait_timeout_ms

Milliseconds to wait for initial indexing or query readiness.

finder

A BebelFileFinder object, or a root path from which a temporary finder should be created for one search.

query

Fuzzy query string.

current_file

Optional currently focused file for FFF scoring.

max_threads

Maximum FFF search threads; 0 means auto.

offset

Result offset for pagination.

limit

Maximum number of rows to return.

combo_boost_score_multiplier

FFF combo boost multiplier.

min_combo_count

Minimum combo count before boost.

Details

The FFF backend is native-only. In webR/wasm this API is present but creating a finder raises an explicit unsupported error so the rest of the package can still load.

Value

A BebelFileFinder object.


Generate a raw continuation from a prompt

Description

Generate a raw continuation from a prompt

Usage

bebel_generate(
  model,
  prompt,
  greedy = FALSE,
  on_event = bebel_console_event(),
  check_interrupt = TRUE,
  max_gen = NULL,
  max_context = NULL,
  max_think = NULL,
  temperature = NULL,
  top_k = NULL,
  repeat_penalty = NULL
)

Arguments

model

A BebelModel object.

prompt

Prompt text.

greedy

Use deterministic greedy decoding.

on_event

Event callback, named list of event-specific handlers, or NULL. Event types are bebel_event_types(). Delta events contain delta, id, and index; final events contain accumulated content or text. Use bebel_console_event() for live console output.

check_interrupt

Check for Ctrl-C during prefill and before every decoded token.

max_gen, max_context, max_think

Optional generation limits.

temperature, top_k, repeat_penalty

Optional sampling settings.

Value

A classed list with generated text, token ids, stop reason, and timing statistics.


Return a BebeLM agent token transcript

Description

Returns the full token transcript currently held by the agent. This is the helper form of agent$history().

Usage

bebel_history(agent)

Arguments

agent

A BebelAgent object.

Value

Integer token ids.


Live terminal console for BebeLM chats

Description

Start an interactive terminal chat loop. If x is a BebelModel, a new BebelAgent is created. If x is a BebelAgent, its existing transcript and caches are reused. Type ⁠/quit⁠ or ⁠/exit⁠ to leave the loop.

Usage

bebel_live_console(
  x,
  prompt = ">>> ",
  exit_commands = c("/quit", "/exit"),
  on_event = bebel_console_event(),
  check_interrupt = TRUE,
  greedy = FALSE,
  max_gen = NULL,
  max_context = NULL,
  max_think = NULL,
  temperature = NULL,
  top_k = NULL,
  repeat_penalty = NULL
)

Arguments

x

A BebelModel or BebelAgent.

prompt

Prompt displayed before reading each user message.

exit_commands

Character vector of commands that exit the console.

on_event

Event handler used for assistant output.

check_interrupt

Check for Ctrl-C during generation.

greedy

Use deterministic greedy decoding.

max_gen, max_context, max_think

Optional generation limits.

temperature, top_k, repeat_penalty

Optional sampling settings.

Value

Invisibly returns the BebelAgent used by the console.


Cancel an agent loop

Description

Cancel an agent loop

Usage

bebel_loop_cancel(loop)

Arguments

loop

A bebelAgentLoop.

Value

Invisibly returns loop.


Return a loop's frontend catalog

Description

Return a loop's frontend catalog

Usage

bebel_loop_catalog(loop)

Arguments

loop

A bebelAgentLoop.

Value

A list with tool, command, extension, skill-provider, and prompt-template-provider catalogs.


Clear queued steering and follow-up messages

Description

Clear queued steering and follow-up messages

Usage

bebel_loop_clear_queue(loop)

Arguments

loop

A bebelAgentLoop.

Value

A list containing cleared steering and followUp messages.


Define an agent-loop command

Description

Commands are UI-independent loop actions. A TUI or console can render the command catalog, but execution happens against the bebelAgentLoop.

Usage

bebel_loop_command(name, fun, description = NULL, usage = NULL)

Arguments

name

Command name without a leading slash.

fun

Function called as fun(args, loop, context).

description

Optional human-readable description.

usage

Optional usage string.

Value

A bebelLoopCommand object.


Return a loop's command catalog

Description

Return a loop's command catalog

Usage

bebel_loop_command_catalog(loop)

Arguments

loop

A bebelAgentLoop.

Value

A data frame of commands.


Return agent-loop events

Description

Return agent-loop events

Usage

bebel_loop_events(loop, since = 0L)

Arguments

loop

A bebelAgentLoop.

since

Return events with sequence number greater than since.

Value

A list of event records.


Execute a loop command

Description

Execute a loop command

Usage

bebel_loop_execute_command(loop, text)

Arguments

loop

A bebelAgentLoop.

text

Command text such as "/help".

Value

TRUE if a command was handled, otherwise FALSE.


Return a loop's extension manifests

Description

Return a loop's extension manifests

Usage

bebel_loop_extensions(loop)

Arguments

loop

A bebelAgentLoop.

Value

A list of extension manifests.


Queue a follow-up message

Description

Follow-up messages mirror Pi's followUp() queue: they are delivered only when the loop would otherwise stop because there are no tool calls or steering messages left.

Usage

bebel_loop_follow_up(loop, message)

Arguments

loop

A bebelAgentLoop.

message

Text to queue.


Create an Agent-loop policy

Description

Policies configure the UI-independent loop. The queue mode names mirror Pi's core agent loop: queued steering/follow-up messages are drained either "one-at-a-time" or "all".

Usage

bebel_loop_policy(
  max_steps = 8L,
  steering_mode = c("one-at-a-time", "all"),
  follow_up_mode = c("one-at-a-time", "all"),
  before_tool_call = NULL
)

Arguments

max_steps

Maximum assistant/tool iterations per run.

steering_mode

How queued steering messages are drained.

follow_up_mode

How queued follow-up messages are drained.

before_tool_call

Optional function ⁠(call, context, loop)⁠ called before dispatching a tool. Return list(block = TRUE, message = "...") to block.

Value

A bebelLoopPolicy object.


Prompt an agent loop

Description

If the loop is idle, this appends the prompt and runs the loop. If the loop is already active, streaming_behavior must be "steer" or "followUp", matching Pi's prompt queue semantics.

Usage

bebel_loop_prompt(loop, text, streaming_behavior = NULL)

Arguments

loop

A bebelAgentLoop.

text

User prompt text.

streaming_behavior

NULL, "steer", or "followUp".

Value

A loop run result when idle, otherwise invisibly returns loop.


Register extensions on a running loop

Description

Adds one or more extension objects to an existing bebelAgentLoop, rebuilds the loop's tool/command/provider/hook catalogs, and emits extension/catalog events for frontends. This is normal R environment mutation, not a core reload command.

Usage

bebel_loop_register_extension(loop, extensions, replace = FALSE)

Arguments

loop

A bebelAgentLoop.

extensions

A bebel_extension() object or list of objects implementing BebelAgentExtension.

replace

Replace existing extensions with the same manifest name.

Value

Invisibly returns loop.


Serve a generic Rbebelm agent loop over HTTP(S)

Description

This optional SDK surface exposes a backend-agnostic bebel_agent_loop() over a transport endpoint with GET /stream NDJSON events, POST /command typed commands, and POST /rpc JSON-RPC compatibility. The endpoint may be local HTTP, remote HTTP, or HTTPS/TLS when nanonext is configured with TLS. External frontends such as the native rbebelm-tui binary call the loop protocol and never assume the backend is a concrete BebelAgent.

Usage

bebel_loop_rpc_server(loop, url = "http://127.0.0.1:8080", tls = NULL)

Arguments

loop

A bebelAgentLoop.

url

URL to listen on, e.g. "http://127.0.0.1:8080" or "https://0.0.0.0:8443".

tls

Optional TLS configuration from nanonext::tls_config() for HTTPS/WSS endpoints.

Value

A nanoServer object from nanonext.


Run an agent loop

Description

Run an agent loop

Usage

bebel_loop_run(loop, prompt = NULL, max_steps = NULL)

Arguments

loop

A bebelAgentLoop.

prompt

Optional user prompt to append before running.

max_steps

Optional per-call step cap. Defaults to loop$policy$max_steps.

Value

A bebelAgentLoopRun / bebelAgentRun result.


Inspect agent-loop state

Description

Inspect agent-loop state

Usage

bebel_loop_state(loop)

Arguments

loop

A bebelAgentLoop.

Value

A list snapshot of loop state.


Queue a steering message

Description

Steering messages mirror Pi's steer() queue: they are delivered after the current assistant/tool turn and before the next model call.

Usage

bebel_loop_steer(loop, message)

Arguments

loop

A bebelAgentLoop.

message

Text to queue.

Value

Invisibly returns loop.


Run one agent-loop assistant/tool step

Description

Run one agent-loop assistant/tool step

Usage

bebel_loop_step(loop)

Arguments

loop

A bebelAgentLoop.

Value

A list with turn, tool_blocks, and done.


Unregister an extension from a running loop

Description

Removes an extension by manifest name, rebuilds contributed catalogs, and emits extension/catalog events for frontends.

Usage

bebel_loop_unregister_extension(loop, name, missing_ok = FALSE)

Arguments

loop

A bebelAgentLoop.

name

Extension manifest name.

missing_ok

If TRUE, missing extensions are ignored.


Load a BebeLM GGUF model

Description

Load a BebeLM GGUF model

Usage

bebel_model_load(path, num_threads = NULL)

Arguments

path

Path to the GGUF weights file.

num_threads

Optional Rayon global thread-pool size. This can only be set once per R process.

Value

A BebelModel object.


Parse a single BebeLM tool call block

Description

This compatibility wrapper returns the first call from bebel_parse_tool_calls(). Prefer bebel_parse_tool_calls() when multiple calls may be present.

Usage

bebel_parse_tool_call(content)

Arguments

content

Accumulated content between BebeLM tool-call delimiters.

Value

A list with name, arguments, and raw.


Parse BebeLM tool calls

Description

Delegates Pythonic BebeLM tool-call parsing (⁠[name(arg='value')]⁠, including multiple calls) to upstream BebeLM. JSON call objects and legacy name({...}) calls are parsed with imported package yyjsonr.

Usage

bebel_parse_tool_calls(content)

Arguments

content

Accumulated content between BebeLM tool-call delimiters.

Value

A list of calls, each with name, arguments, and raw.


Define a prompt template

Description

Prompt templates are backend-agnostic named text templates. Rendering is kept deliberately small and portable: {{name}} placeholders are replaced by values in data.

Usage

bebel_prompt_template(
  name,
  template,
  description = NULL,
  metadata = list(),
  path = NULL
)

Arguments

name

Template name.

template

Template text.

description

Optional description.

metadata

Optional metadata list.

path

Optional source path.

Value

An bebelPromptTemplate object.


List prompt templates

Description

List prompt templates

Usage

bebel_prompt_template_list(provider)

Arguments

provider

A prompt-template provider.


Create a prompt-template provider

Description

Create a prompt-template provider

Usage

bebel_prompt_template_provider(
  templates = list(),
  paths = character(),
  name = "default"
)

Arguments

templates

bebelPromptTemplate objects or named character templates.

paths

Template files or directories to scan.

name

Provider name.

Value

An bebelPromptTemplateProvider implementing BebelPromptTemplateProvider.


Render a prompt template

Description

Render a prompt template

Usage

bebel_prompt_template_render(provider, name, data = list())

Arguments

provider

A prompt-template provider.

name

Template name.

data

Template data.


Create an R-native Rbebelm agent session

Description

bebel_r_agent() is a higher-level layer inspired by R console agents. It keeps one BebeLM agent, a private tool context, and a small R tool catalog together so the same object can be driven by a console loop or by the JSON-RPC server.

Usage

bebel_r_agent(
  model,
  system_prompt = NULL,
  tools = NULL,
  env = .GlobalEnv,
  cwd = getwd(),
  allow_eval = TRUE,
  prompt_detail = c("compact", "full"),
  greedy = FALSE,
  max_gen = 512,
  max_context = 4096,
  max_think = 64,
  temperature = 0.8,
  top_k = 50,
  repeat_penalty = 1.1
)

Arguments

model

A BebelModel object.

system_prompt

System prompt. NULL builds a default prompt including the tool catalog.

tools

Tool catalog. Defaults to bebel_default_r_tools().

env

Environment exposed to R tools.

cwd

Working directory for file tools.

allow_eval

Whether to include r_eval and r_plot tools that execute R code and render plots. Defaults to TRUE; set FALSE to start read-only.

prompt_detail

Tool prompt detail. "compact" is faster for console use; "full" includes descriptions for every argument.

greedy, max_gen, max_context, max_think, temperature, top_k, repeat_penalty

Generation options passed to bebel_agent().

Value

A bebelRAgent environment.


Clear an Rbebelm R agent session

Description

Clear an Rbebelm R agent session

Usage

bebel_r_agent_clear(session)

Arguments

session

A bebelRAgent.

Value

Invisibly returns session.


Start an interactive Rbebelm console agent

Description

Start an interactive Rbebelm console agent

Usage

bebel_r_agent_console(
  session,
  prompt = "bebel> ",
  max_steps = 4L,
  show_stats = TRUE,
  blank_limit = 10L
)

Arguments

session

A bebelRAgent.

prompt

Prompt string.

max_steps

Maximum assistant/tool iterations per user prompt.

show_stats

Whether to print token/timing stats after each turn.

blank_limit

Number of consecutive blank inputs before exiting. Set to Inf to never auto-exit on blanks.

Value

Invisibly returns session.


Create an agent loop from an R-native agent session

Description

Create an agent loop from an R-native agent session

Usage

bebel_r_agent_loop(
  session,
  policy = bebel_loop_policy(),
  hooks = list(),
  extensions = list(),
  agent_session = TRUE,
  parse_tool_call = bebel_parse_tool_calls,
  on_event = NULL,
  check_interrupt = TRUE
)

Arguments

session

A bebelRAgent from bebel_r_agent().

policy

A bebel_loop_policy() object.

hooks

Optional named hooks. Loop hooks may observe state_change, queue_update, message_start, message_end, model_event, tool_request, tool_result, tool_error, tool_denied, observation, command_start, command_end, and loop_end.

extensions

Optional list of bebel_extension() objects.

agent_session

Session persistence setting passed to bebel_agent_loop().

parse_tool_call

Function converting tool-call text into one or more call records.

on_event

Optional event callback or handler list for model stream events.

check_interrupt

Check for Ctrl-C during generation.

Value

A bebelAgentLoop environment.


Serve an Rbebelm R agent over JSON-RPC

Description

This optional SDK surface uses nanonext to expose the same bebelRAgent object used by the console. JSON parsing/serialization uses imported yyjsonr. It is intentionally small and not an OpenAI API: clients call JSON-RPC methods such as turn, tools/list, and session/transcript.

Usage

bebel_r_agent_rpc_server(session, url = "http://127.0.0.1:8080")

Arguments

session

A bebelRAgent.

url

URL to listen on, e.g. "http://127.0.0.1:8080".

Value

A nanoServer object from nanonext.


Launch an R-native Rbebelm console from weights

Description

Convenience wrapper for loading a model, creating a bebel_r_agent(), and entering bebel_r_agent_console(). This keeps the loaded model object local to the launcher while the agent tools, ⁠/r⁠, and ⁠/rplot⁠ commands share env.

Usage

bebel_r_agent_start(
  weights = Sys.getenv("BEBELM_WEIGHTS_FILE", "LFM2.5-8B-A1B-Q4_K_M.gguf"),
  num_threads = as.numeric(Sys.getenv("BEBELM_NUM_THREADS", "2")),
  env = .GlobalEnv,
  cwd = getwd(),
  allow_eval = TRUE,
  greedy = TRUE,
  max_gen = as.numeric(Sys.getenv("BEBELM_AGENT_MAX_GEN", "256")),
  max_context = 4096,
  max_think = as.numeric(Sys.getenv("BEBELM_AGENT_MAX_THINK", "48")),
  temperature = 0.8,
  top_k = 50,
  repeat_penalty = 1.1,
  prompt = "bebel> ",
  max_steps = 4L,
  show_stats = TRUE,
  blank_limit = 10L,
  prompt_detail = c("compact", "full")
)

Arguments

weights

GGUF weights file. Defaults to BEBELM_WEIGHTS_FILE, then "LFM2.5-8B-A1B-Q4_K_M.gguf" in the working directory.

num_threads

Optional Rayon thread count passed to bebel_model_load().

env

Environment shared by ⁠/r⁠, ⁠/rplot⁠, r_objects, and optional code-evaluation tools.

cwd

Working directory for file tools and ⁠/rplot⁠ output.

allow_eval

Whether to include r_eval and r_plot tools that the model can call.

greedy, max_gen, max_context, max_think, temperature, top_k, repeat_penalty

Generation options passed to bebel_r_agent().

prompt

Prompt string for bebel_r_agent_console().

max_steps

Maximum assistant/tool iterations per user prompt.

show_stats

Whether to print token/timing stats after each turn.

blank_limit

Number of consecutive blank inputs before exiting the console. Set to Inf to never auto-exit on blanks.

prompt_detail

Tool prompt detail passed to bebel_r_agent().

Value

Invisibly returns the bebelRAgent session after the console exits.


Run one user turn through an Rbebelm R agent

Description

Run one user turn through an Rbebelm R agent

Usage

bebel_r_agent_turn(
  session,
  prompt,
  max_steps = 4L,
  on_event = NULL,
  hooks = list(),
  check_interrupt = TRUE
)

Arguments

session

A bebelRAgent from bebel_r_agent().

prompt

User prompt.

max_steps

Maximum assistant/tool iterations.

on_event

Optional BebeLM event callback.

hooks

Optional hooks passed to bebel_agent_run().

check_interrupt

Check for Ctrl-C during generation.

Value

A bebelRAgentTurn list.


Append or clear a label on a session entry

Description

Append or clear a label on a session entry

Usage

bebel_session_append_label(session, target_id, label = NULL)

Arguments

session

An bebelSession.

target_id

Entry id to label.

label

Label text, or NULL/empty string to clear.


Append a message entry to an agent session

Description

Append a message entry to an agent session

Usage

bebel_session_append_message(session, role, content, message = NULL, ...)

Arguments

session

An bebelSession.

role

Message role, e.g. "user", "assistant", or "toolResult".

content

Message content. Strings or lists of content blocks are accepted.

message

Optional complete message object. If supplied, role, content, and ... are ignored.

...

Extra message fields such as provider, model, usage, stopReason, toolName, or details.

Value

The appended entry id.


Append model/thinking/compaction/branch metadata

Description

Append model/thinking/compaction/branch metadata

Usage

bebel_session_append_model_change(session, provider, model_id)

bebel_session_append_thinking_level_change(session, thinking_level)

bebel_session_append_compaction(
  session,
  summary,
  first_kept_entry_id,
  tokens_before,
  details = NULL,
  from_hook = FALSE
)

bebel_session_append_branch_summary(
  session,
  from_id,
  summary,
  details = NULL,
  from_hook = FALSE
)

Arguments

session

An bebelSession.

provider

Provider id.

model_id

Model id.

thinking_level

Thinking/reasoning level.

summary

Summary text.

first_kept_entry_id

First entry kept after compaction.

tokens_before

Number of tokens before compaction.

details

Optional metadata.

from_hook

Was the entry created by an extension hook?

from_id

Branch source entry id.

Value

The appended entry id.


Append session metadata and extension entries

Description

Append session metadata and extension entries

Usage

bebel_session_append_session_info(session, name)

bebel_session_append_custom(session, custom_type, data = NULL)

bebel_session_append_custom_message(
  session,
  custom_type,
  content,
  display = TRUE,
  details = NULL
)

Arguments

session

An bebelSession.

name

Session display name.

custom_type

Extension or custom entry type.

data

Extension state data. Custom entries do not enter model context.

content

Custom message content. Custom messages may enter model context.

display

Should a UI render the custom message?

details

Optional extension-specific metadata.

Value

The appended entry id.


Return the branch from root to a session entry

Description

Return the branch from root to a session entry

Usage

bebel_session_branch(session, from_id = bebel_session_leaf_id(session))

Arguments

session

An bebelSession.

from_id

Entry id. Defaults to the current leaf.

Value

A list of session entries in path order.


Move the current session leaf

Description

Move the current session leaf

Usage

bebel_session_checkout(session, entry_id = NULL)

Arguments

session

An bebelSession.

entry_id

Entry id to continue from, or NULL to reset before the root.

Value

The session, invisibly.


Build model context from the active session branch

Description

Build model context from the active session branch

Usage

bebel_session_context(session)

Arguments

session

An bebelSession.

Value

A list with messages, thinking_level, model, and branch entries.


Create an agent session JSONL store

Description

The store is backend-agnostic. It records framework/session information and message-shaped data; it does not assume a BebeLM transcript implementation.

Usage

bebel_session_create(
  cwd = getwd(),
  session_dir = NULL,
  id = NULL,
  parent_session = NULL,
  name = NULL,
  persist = TRUE
)

Arguments

cwd

Working directory stored in the session header.

session_dir

Optional concrete directory for the JSONL file. If NULL, bebel_session_dir() is used.

id

Optional session id.

parent_session

Optional parent session file path for forks/clones.

name

Optional display name stored as a session_info entry.

persist

If FALSE, keep the session in memory only.

Value

An bebelSession object.


Agent session storage directory

Description

Returns the directory used for backend-agnostic agent session JSONL files. By default sessions are stored under ⁠tools::R_user_dir("Rbebelm", "data")/sessions/<encoded-cwd>/⁠, inspired by Pi's per-working-directory session layout. Set RBEBELM_SESSION_DIR or pass session_dir to the creation/opening helpers to override it.

Usage

bebel_session_dir(cwd = getwd(), session_root = NULL, create = TRUE)

Arguments

cwd

Working directory represented by the session directory.

session_root

Optional root directory. Defaults to Sys.getenv("RBEBELM_SESSION_DIR") or the package user data directory.

create

Create the directory if needed?

Value

A session directory path.


Fork an agent session file into a new session file

Description

bebel_session_fork() copies all non-header entries from an existing JSONL file. bebel_session_clone_branch() copies only the path from the root to a selected leaf, matching Pi's active-branch clone behavior.

Usage

bebel_session_fork(source_path, cwd = getwd(), session_dir = NULL, id = NULL)

bebel_session_clone_branch(
  session,
  leaf_id = bebel_session_leaf_id(session),
  cwd = session$cwd,
  session_dir = session$session_dir,
  id = NULL
)

Arguments

source_path

Source JSONL session file.

cwd

Target working directory for the new session.

session_dir

Optional concrete target session directory.

id

Optional new session id.

session

Source bebelSession for branch cloning.

leaf_id

Leaf entry id to clone. Defaults to the source session leaf.

Value

The opened forked/cloned bebelSession.


Inspect agent session metadata

Description

Inspect agent session metadata

Usage

bebel_session_header(session)

bebel_session_entries(session)

bebel_session_leaf_id(session)

bebel_session_file(session)

bebel_session_get_entry(session, id)

Arguments

session

An bebelSession.

id

Entry id for bebel_session_get_entry().


List agent session files

Description

List agent session files

Usage

bebel_session_list(cwd = getwd(), session_dir = NULL)

Arguments

cwd

Working directory used for default session directory lookup.

session_dir

Optional concrete directory to scan.

Value

A data frame with basic session metadata.


Open an agent session JSONL file

Description

Open an agent session JSONL file

Usage

bebel_session_open(path, session_dir = NULL, cwd = NULL)

Arguments

path

Session JSONL file.

session_dir

Optional session directory for future derived sessions.

cwd

Optional working-directory override.

Value

An bebelSession object.


Return an agent session tree

Description

Return an agent session tree

Usage

bebel_session_tree(session)

Arguments

session

An bebelSession.

Value

A nested list of tree nodes with entry, children, and optional label.


Define a framework skill

Description

A skill is reusable instruction/context text plus metadata. Skill providers list and load skills; the loop or prompt-composition layer decides when to include them.

Usage

bebel_skill(name, content, description = NULL, metadata = list(), path = NULL)

Arguments

name

Skill name.

content

Skill content.

description

Optional description.

metadata

Optional metadata list.

path

Optional source path.

Value

An bebelSkill object.


List available skills

Description

List available skills

Usage

bebel_skill_list(provider)

Arguments

provider

A skill provider.


Load a skill by name

Description

Load a skill by name

Usage

bebel_skill_load(provider, name)

Arguments

provider

A skill provider.

name

Skill name.


Create a skill provider

Description

Create a skill provider

Usage

bebel_skill_provider(skills = list(), paths = character(), name = "default")

Arguments

skills

bebelSkill objects or named character skill bodies.

paths

Skill markdown files or directories to scan. SKILL.md files use their parent directory name as the skill name.

name

Provider name.

Value

An bebelSkillProvider implementing BebelSkillProvider.


Compose a system prompt from a prompt template and optional skills

Description

Compose a system prompt from a prompt template and optional skills

Usage

bebel_system_prompt(
  provider,
  name = "system",
  data = list(),
  skill_provider = NULL,
  skills = character()
)

Arguments

provider

Object implementing BebelPromptTemplateProvider.

name

Prompt template name.

data

Template data.

skill_provider

Optional object implementing BebelSkillProvider.

skills

Character vector of skill names to append.

Value

Rendered system prompt text.


Return BebeLM tokenizer special token ids.

Description

Return BebeLM tokenizer special token ids.

Usage

bebel_token_ids()

Tokenize text with a BebeLM model tokenizer

Description

Tokenize text with a BebeLM model tokenizer

Usage

bebel_tokenize(model, text, add_bos = TRUE)

Arguments

model

A BebelModel object.

text

Text to encode.

add_bos

Whether to prepend the BOS token.

Value

Integer token ids.


Define a BebeLM R tool

Description

Define a BebeLM R tool

Usage

bebel_tool(name, fun, description = NULL, schema = NULL)

Arguments

name

Tool name exposed to the tool dispatcher.

fun

Function to run. It is called as fun(args = ..., context = ..., call = ...) when it accepts those names, otherwise with progressively simpler fallbacks.

description

Optional human-readable description.

schema

Optional schema/metadata object for prompts or adapters.

Value

A bebelTool object.


Render a BebeLM tool schema

Description

Converts an R bebel_tool() declaration into BebeLM's JSON tool schema string for the system ⁠List of tools: [...]⁠ preamble using yyjsonr. This is normally called by bebel_append_system() when tools are supplied.

Usage

bebel_tool_schema_json(tool)

Arguments

tool

A bebelTool object created by bebel_tool().

Value

A character scalar containing the rendered tool schema.


Decode a BebeLM agent transcript

Description

Decodes the agent's full token transcript. This is the helper form of agent$transcript().

Usage

bebel_transcript(agent)

Arguments

agent

A BebelAgent object.

Value

Transcript text.


Persistent BebeLM conversation agent with transcript and decode caches.

Description

Persistent BebeLM conversation agent with transcript and decode caches.

Usage

BebelAgent

Format

An object of class Rbebelm::BebelAgent__bundle (inherits from savvy_Rbebelm__sealed) of length 1.


BebeLM agent backend interface

Description

Backends implement the minimal transcript/generation protocol consumed by bebel_agent_loop().

Usage

BebelAgentBackend

Format

An object of class s7contract::s7_interface (inherits from S7_object) of length 1.


BebeLM agent extension interface

Description

Extensions expose a manifest plus contributed tools, commands, and hooks.

Usage

BebelAgentExtension

Format

An object of class s7contract::s7_interface (inherits from S7_object) of length 1.


Persistent native FFF fuzzy file finder.

Description

Persistent native FFF fuzzy file finder.

Usage

BebelFileFinder

Format

An object of class Rbebelm::BebelFileFinder__bundle (inherits from savvy_Rbebelm__sealed) of length 1.


Loaded BebeLM GGUF model.

Description

Loaded BebeLM GGUF model.

Usage

BebelModel

Format

An object of class Rbebelm::BebelModel__bundle (inherits from savvy_Rbebelm__sealed) of length 1.


BebeLM prompt-template provider interface

Description

Prompt-template providers list and render named templates.

Usage

BebelPromptTemplateProvider

Format

An object of class s7contract::s7_interface (inherits from S7_object) of length 1.


BebeLM skill provider interface

Description

Skill providers list and load reusable instructions or workflow snippets.

Usage

BebelSkillProvider

Format

An object of class s7contract::s7_interface (inherits from S7_object) of length 1.


Print a BebeLM generation result

Description

Print a BebeLM generation result

Usage

## S3 method for class 'bebelGeneration'
print(x, ...)

Arguments

x

A result returned by bebel_generate() or bebel_chat().

...

Unused.

Value

Invisibly returns x.


Return feature information reported by the loaded Rust backend.

Description

Return feature information reported by the loaded Rust backend.

Usage

rbebelm_backend_features()

Inspect Rbebelm backend dispatch state

Description

Inspect Rbebelm backend dispatch state

Usage

rbebelm_backend_info()

Value

A named list describing installed, supported, requested, and selected backends, with class rbebelmBackendInfo.


Rbebelm agent framework contracts

Description

These S7/s7contract interfaces keep the loop, extension, skill, and prompt infrastructure independent from the concrete LLM backend. BebeLM implements BebelAgentBackend; other local or remote providers can implement the same generics later.


Inspect CPU SIMD support used by backend dispatch

Description

Inspect CPU SIMD support used by backend dispatch

Usage

rbebelm_cpuid_info()

Value

A named list of logical CPU feature checks with class rbebelmCpuidInfo.


Select the Rbebelm native backend

Description

Must be called before loading a model or querying backend features.

Usage

rbebelm_set_backend(backend = "auto")

Arguments

backend

One of "auto", "scalar", "avx2", "avx512", or "neon".

Value

The requested backend name.