Skip to content

Native Core

Goal: use native prompt and dialog primitives without coupling callers to a model provider or agent loop.

Prerequisites

python -m pip install -e ".[dev]"

Files Used

examples/native_dialog/
  demo.py
tests/
  test_native_core.py
  test_native_adapter.py

The same native dialog shape is available as an executable example at examples/native_dialog/demo.py.

Dialog

from lllm.runtimes.native import Dialog, Prompt, Role


system = Prompt(path="agent/system", prompt="You are a {style} assistant.")
task = Prompt(path="agent/task", prompt="Plan the next checkpoint for {project}.")

dialog = Dialog(owner="agent")
dialog.put_prompt(system, prompt_args={"style": "careful"}, role=Role.SYSTEM)
dialog.put_prompt(task, prompt_args={"project": "LLLM"})

retry = dialog.fork(last_n=1, first_k=1)

Dialog keeps append-only messages and serializable lineage metadata. fork() copies the selected context into a child dialog and links the child back to its parent.

assert retry.parent is dialog
assert retry.depth == 1
assert retry.tree_node.parent_id == dialog.dialog_id

Tools

Tools are schema records with optional local Python implementations:

from lllm.runtimes.native import FunctionCall, tool


@tool(description="Add two numbers")
def add(left: int, right: int) -> int:
    return left + right


call = add(FunctionCall(name="add", arguments={"left": 2, "right": 3}))
assert call.result == 5

Parser

Prompts can also carry small parser objects. The default tag parser extracts XML blocks, fenced markdown blocks, and signal tags without depending on a model provider:

from lllm.parsers import DefaultTagParser
from lllm.runtimes.native import Prompt


prompt = Prompt(
    path="agent/parse",
    prompt="Return <answer>...</answer> and a ```json block.",
    parser=DefaultTagParser(
        required_xml_tags=["answer"],
        required_md_tags=["json"],
        signal_tags=["DONE"],
    ),
)

parsed = prompt.parse("<answer>Hello</answer>\n```json\n{}\n```\n<DONE>")
assert parsed["signal_tags"]["DONE"] is True

When native objects need to be reused outside this runtime, expose them through NativeTacticAdapter so remote callers only depend on the Tactic protocol.

Verify

python -m pytest tests/test_native_core.py tests/test_native_adapter.py -q

Expected output:

... passed

Next, use NativeTacticAdapter when a prompt/dialog workflow needs the normal LLLM service or package boundary.