RagLeap Packages
151 tests passing in CI on Python 3.10, 3.11 and 3.12 — mostly scripted models and a local fake server; also run against Groq with three models, and the taint rule has not been triggered by a real model

ragleap-agents

A small act-observe agent loop over ragleap-tools Tool objects. The model proposes one action at a time and you bring it as a plain callable. No database. Bring your own model callable, or use the included OpenAI-compatible adapter.

0.4.0
PyPI version (alpha)
151
Tests passing
3
Python versions in CI
1
Runtime dependency (ragleap-tools)

Install

pip install ragleap-agents
# or, with uv
uv add ragleap-agents

Quickstart

The model returns one JSON action per step: {"tool": "<name or done>", "arguments": {...}}.

from ragleap_tools import CALCULATOR_TOOL
from ragleap_agents import Agent, Policy, TRUSTED

def my_llm(prompt: str) -> str:
    ...  # call any model, return its text

agent = Agent(llm=my_llm, tools=[CALCULATOR_TOOL],
              policy=Policy(max_steps=4, tools={"calculator": TRUSTED}))
result = agent.run("What is 6 * 7?")
print(result.status, result.answer)

Behaviour change from 0.1.0

A model reply that is not a single JSON object (prose, truncated JSON, an empty reply) now stops the run with stop_reason="unparseable_reply". 0.1.0 reported these as done, so a model failure looked like success. Nothing executed in either case.

Using a real model

openai_compatible returns the llm(prompt) -> str callable for any provider that speaks the OpenAI chat-completions API. Standard library only. You pass the key in; it is never read from the environment and never printed.

from ragleap_agents import Agent, Policy, TRUSTED, openai_compatible

tools = [CALCULATOR_TOOL]
llm = openai_compatible(
    "https://api.groq.com/openai/v1", api_key, "openai/gpt-oss-20b",
    mode="native", tools=tools,   # or mode="json": the model replies with the JSON action as text
)
agent = Agent(llm, tools, Policy(tools={"calculator": TRUSTED}))
  • https is required (allow_insecure_http=True is for local testing), redirects are refused, responses are size-capped, and 408/429/5xx and network errors are retried with backoff (at most 5 retries, Retry-After honoured up to 30 s).
  • Errors are ProviderError and carry only a status code or an exception type, never a response body, URL or key. error_detail=True adds the first 300 characters of the error body (key scrubbed) to diagnose a provider; it is off by default.
  • The base URL is yours to set. There is no address check, so do not build it from untrusted input.
  • In native mode the first tool call becomes the JSON action, and a reply with no tool call becomes an explicit done. Agent still validates, taints and gates every proposal.
  • Policy(repair_attempts=1) asks the model once more after an unusable reply, with a short note that never repeats the bad reply. It is off by default, and a repaired proposal goes through the same checks.

Observed with a real model

Groq, openai/gpt-oss-20b, 2026-10-11: one run of 20 labeled tasks per configuration with scripts/live_runner.py. One model on one provider (two more models were tried on the injection tasks only). Not a benchmark.

  • JSON mode: the provider rejected the request with HTTP 400 tool_use_failed on 3 of 20 tasks (the same three in both sweeps) when the model answered in its own function-call format. Prefer mode="native" with models that have one.
  • Native mode: 2 of 46 saved native runs (three models) failed with HTTP 400 because the model called a tool named json that was not offered.
  • Models sometimes returned an empty reply (4 runs), or invented an action name such as refusal to decline (5 runs). With repair on, 4 of the 5 runs where it fired ended with a valid action. Repair cannot help when the provider rejects the request, because no reply exists.
  • Tasks done, out of 20: json 15, native 17, json+repair 16, native+repair 20. These are single runs, and the differences between configurations are within the run-to-run variation seen.
  • 16 runs on three models read the injected note; none proposed the injected send_message.

Approval gates: pause and resume

from ragleap_agents import ToolPolicy
policy = Policy(tools={"write_file": ToolPolicy(taints=False, outbound=True, requires_approval=True)})
agent = Agent(my_llm, tools, policy, store=my_store)
result = agent.run("save the report")
if result.status == "awaiting_approval":
    call = result.pending   # {"call_id", "tool", "arguments", "forced"}
    result = agent.resume(result.run_id, {call["call_id"]: True})   # False rejects

A paused run is a plain JSON dict in a StateStore. InMemoryStateStore is included, and from 0.4.0 so is SQLiteStateStore(path) (one SQLite file, standard library only, not encrypted); both offer save_if_status, an atomic compare-and-set that resume() uses when a store has it. resume() raises ResumeError for an unknown run, a run not awaiting approval, or a decision that does not match the pending call, so an approval cannot be replayed.

From 0.4.0 a run with no tools, or with an empty task, returns status="stopped" with stop_reason="no_task_or_tools"; 0.3.0 and earlier returned "done" for it.

The safety model

  • Every proposal is checked. The tool must exist and the arguments must fit its JSON Schema (required keys, unknown keys, type and enum only). Anything else stops the run with invalid_plan; no tool runs.
  • Tool results are untrusted. Capped at 1,500 characters each (4,000 in the prompt), fenced in <observation> tags, and lookalike tags are neutralised case-insensitively.
  • Taint rule. After a tool declared taints=True has run, every later outbound=True tool needs approval. The policy can only tighten.
  • Fail closed. A tool with no declared policy counts as both tainting and outbound. Use TRUSTED only for tools that neither return external content nor act outside.
  • Limits. max_steps default 4, hard cap 8; duplicate-action stop; a wall-clock deadline checked between calls. A tool's exception text never reaches the model or the result, only its type.

What this does not do

It does not stop prompt injection. It limits what an injected instruction can do, and only as far as your ToolPolicy declarations are accurate. Tool descriptions (capped at 300 characters) are shown to the model, so tools from an untrusted source can inject through them.

Verified

  • 0.4.0 (from its changelog): 151 tests (123 in 0.3.0); the ragleap-agents tests passed in CI on Python 3.10, 3.11 and 3.12. The SQLite store has 24 tests, including four separate processes racing to claim one paused run (exactly one wins); five mutations of it are each caught by a test.
  • 0.3.0 (from its changelog): 123 tests pass on Python 3.10, 3.11 and 3.12, and 9 of 9 mutations of the new prompt behaviour are caught.
  • 0.2.0: 112 tests pass in CI on Python 3.10, 3.11 and 3.12, mostly with a scripted model or a local fake server. Mutation-checked: 19 of 19 adapter and 19 of 20 runner mutations caught; the survivor cannot matter.
  • Every safety property of the loop has a test that fails if the property is broken (mutation-checked).
  • The published 0.2.0 wheel installs fresh on 3.10, 3.11 and 3.12 with pip check clean, its file digests match the publish log, and a live run against Groq (openai/gpt-oss-20b, 5 tasks in each mode) finished 10 of 10 runs.

Not verified

  • The taint rule against a real model: no real run proposed the injected send_message, so the rule was never triggered. It is tested with scripted models only.
  • Any provider other than Groq (Gemini has not been tried), long runs, and concurrent resumes across processes for a custom store (0.4.0 tests four processes racing on the SQLite store; a store must make resume atomic).
  • Whether repair improves pass rates: five firings on one model do not show that.
  • The SQLite store (0.4.0) on a network filesystem (file locking there is unreliable; use a local disk), its throughput and long-running use. The file is not encrypted. The prompt wording was not touched in 0.4.0, so the real-model results above were not re-run for this release.
  • Native mode in 0.2.0 asked for a JSON object while real tools were offered, and two models answered by calling a tool named json. 0.3.0 changes the wording (native mode now asks the model to call one of the provided tools by its own name); its changelog reports no re-run against a real model.
  • Equivalence with RagLeap Core's own agent loop, which this mirrors as of core commit 59fd555.