RagLeap
PyPI package · Alpha

ragleap-agents

version — loading live from PyPI…

A small agent loop over ragleap-tools Tool objects. The model proposes one action at a time and you bring it as a plain callable, or use the included adapter for OpenAI-compatible chat APIs; there is no database.

pypi license
pip install ragleap-agents

Highlights

  • Every proposal is checked against the tool's JSON Schema; an invalid proposal stops the run and no tool executes
  • Tool results are untrusted: capped, fenced in <observation> tags, with lookalike tags neutralised case-insensitively
  • Taint rule: after a tool declared taints=True has run, every later outbound=True tool needs approval. A tool with no declared policy counts as both, so it fails closed
  • Pause and resume through a pluggable StateStore; a replayed or mismatched approval raises ResumeError
  • Two stores ship: InMemoryStateStore and, from 0.4.0, SQLiteStateStore(path) (one SQLite file, standard library only, JSON text only, created with mode 0600, not encrypted). Both offer save_if_status, an atomic compare-and-set that resume() uses so two workers cannot both claim one paused run; a custom store with only save() and load() keeps the old, non-atomic claim.
  • New in 0.5.1 (from its release notes, 2026-11-14): tenant scope for runs, approvals and audit, a security fix for shared multi-tenant use. The gap, reproduced by the authors with 0.5.0 from PyPI: with one shared Agent and one shared state store, tenant B knowing only a run id could call resume(run_id, {call_id: True}) on tenant A's paused run and the tool executed with A's arguments. Single-tenant use was not affected. Now run(task, *, scope=None, tainted=False) and resume(run_id, decisions, *, scope=None): a run saves its scope and resume continues it only for exactly the same scope; a wrong scope, an unknown run and a damaged state raise the same ResumeError("unknown run"). Also Agent(..., require_scope=True), audit=AuditLog(...) (ids, tool names and sizes, never text) and rate_limiter=RateLimiter(...) per scope; sub-agents inherit the parent's scope. Behaviour changes: new run ids are 22-character URL-safe tokens (128 bits) instead of 12 hex characters (old ids still load and resume), and the new dependency is ragleap-security 0.2.0 or newer. If you run one agent for several tenants with 0.5.0, upgrade and pass a scope.
  • New in 0.6.0 (from its changelog, 2026-11-23): opt-in nested approvals (nested_approval=False by default, so nothing changes unless you set it). A pause anywhere in the delegation tree appears at the top-level run as one pending approval, and one resume on the top run decides it after checking every run on the path (same scope, same call, tool and arguments). Steps a child had already run before the pause are listed in executed_before_pause; those effects are not undone. Does not defend: who may approve stays the business of the caller (decided_by is not verified), and every agent in the tree needs a store that survives until the decision. Not verified: a real model provider (all tests use a scripted model), Windows, macOS, and store files on network file systems.

Tech stack

Python 3.10 to 3.12. One dependency: ragleap-tools. No database; the OpenAI-compatible adapter uses only the standard library.

Testing

204 test functions across 12 test files, verified directly from the repo (parametrised cases count once). CI runs 151 test cases on Python 3.10, 3.11 and 3.12, mostly with a scripted model or a local fake server and no external network.

Verification status

  • Verified in 0.4.0 (from its changelog): 151 tests (123 in 0.3.0); CI on PR #793 passed on Python 3.10, 3.11 and 3.12. The new resume and corrupt-row tests failed before the change and pass after it. The SQLite store has 24 tests, including four separate processes racing to claim one paused run (exactly one wins); five mutations of it (status check removed, run-id and state validation skipped, a 0644 file mode, corrupt-row checks skipped, a deferred BEGIN instead of BEGIN IMMEDIATE) are each caught by at least one test.
  • Verified in 0.5.0 (from its changelog): all 208 tests pass on Python 3.10, and CI is green on Python 3.10, 3.11 and 3.12 for the delegate-tool change. A live delegation check with one model (Groq, openai/gpt-oss-20b, native mode, 8 runs): the parent delegated in 8 of 8 runs and send_message never ran; in 3 runs the parent proposed it after a child had read the note, and the taint rule held it for approval. Not verified in 0.5.0: prompt-injection resistance through a sub-agent (only 2 of the 8 runs read the injected note without a prompt that asked for an action, and the model proposed no send in either), the child-side stop with a real model, any other provider or model, resuming a run saved by 0.4.x, and a published 0.5.0 wheel on Python 3.11.
  • Verified in 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 (wording not switched, style not read from the callable, explicit style ignored, unknown style accepted, repair note not style-aware, JSON sentence dropped, native wording asking for JSON, adapter not advertising its mode, adapter always advertising json).
  • Verified in 0.2.0: 112 tests on Python 3.10, 3.11 and 3.12, mostly with a scripted model or a local fake server. Mutation-checked: removing the taint rule, the fence, the exception-text rule, the resume claim, the hard cap, the fail-closed default or the bool-is-not-integer check each fails at least one test, and 19 of 19 adapter and 19 of 20 runner mutations are caught. The published 0.2.0 wheel installs fresh on 3.10, 3.11 and 3.12 and finished a live run against Groq (openai/gpt-oss-20b, 5 tasks in each mode) 10 of 10.
  • Observed with 0.2.0 and a real model (Groq, openai/gpt-oss-20b, 2026-10-11, one run of 20 tasks per configuration; not a benchmark): in JSON mode the provider rejected 3 of 20 tasks with HTTP 400 tool_use_failed when the model answered in its own function-call format, so prefer native mode with models that have one; in native mode 2 of 46 saved runs across three models failed because the model called a tool named json; models sometimes returned an empty reply or invented a refusal action, and repair fixed 4 of the 5 runs where it fired.
  • Not verified: the taint rule against a real model (16 runs on three models read the injected note and none proposed the injected send, so the rule was never triggered), any provider other than Groq (Gemini has not been tried), long runs, concurrent resumes across processes, whether repair improves pass rates, and equivalence with RagLeap Core's agent loop.
  • Verified in 0.5.1 (from its release notes, not run by us): 251 tests passed on the author's VPS (Python 3.10.12) and in the sandbox on Python 3.12.3 and 3.10.20; GitHub CI 55 of 55 checks on the code PR and on the date-fix PR; a mutation check of only the 0.5.1 changes killed 34 of 34; the cross-tenant attack is refused with the published wheel. Not verified: Windows and macOS, a real model provider (all tests use a scripted model), store files on network file systems, and the mutation run on the VPS.

Limits to know about

  • 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.
  • Sub-agents since 0.5.0, opt-in: make_delegate_tool lets an agent hand one task to a named child agent. Depth, the number of delegations and the steps of the children are limited per run. By default, children cannot pause for approval: a child that reaches an action needing approval is stopped and the action does not run. Since 0.6.0 you can opt in to nested approvals (nested_approval=True), and a pause in a child then appears as one pending approval at the top-level run (updated 2026-11-24: this said that children cannot pause for approval in this release). Before 0.5.0 it was a single agent only. Crews beyond this delegation are planned, not built.
  • Behaviour change from 0.1.0: a model reply that is not a single JSON object now stops the run (unparseable_reply) instead of reporting done.
  • Behaviour change in 0.4.0: a run with no tools, or with an empty task, now returns status="stopped" with stop_reason="no_task_or_tools". 0.3.0 and earlier returned status="done" for it, so code that checked only status == "done" will now see stopped in this case. Also fixed in 0.4.0: a stored run state that a store refuses as corrupt makes resume() raise ResumeError and nothing runs.
  • Not verified in 0.4.0: SQLite on a network filesystem (file locking there is unreliable; use a local disk), throughput and long-running use; stores other than the two shipped ones (a custom store with only save() and load() cannot make the claim atomic). The file is not encrypted. The prompt wording was not touched, so the real-model results of 0.3.0 were not re-run for this release: JSON mode on the model tested is still intermittent, and the taint rule has still never been triggered by a real model.
  • Behaviour change in 0.3.0: the instruction at the end of the prompt now depends on prompt_style ("json", the default, or "native"). In native mode the model is told to call exactly one of the provided tools by its own name, and to answer in plain text when finished or when it cannot or will not do the task. By default the style is read from the model callable, an explicit Agent(prompt_style=...) wins, and any other value raises ValueError.
  • Limits of the 0.5.1 tenant scope (from its release notes): the caller must pass the right scope, because the library does not log users in; a tool that reads another tenant's data by itself is not stopped; a shared store file shows every tenant to anyone with access to the file (use one store per tenant for stronger separation); an in-memory rate limiter is lost on restart. No independent security review has happened.

Quickstart

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)
Full documentation PyPI page Source