Skip to main content

Runtime toolkit for explicit-parameter registration, inspection, replacement, listing, and removal of Swarmauri tools during agent execution.

Project description

Swarmauri Logo

PyPI - Downloads Hits PyPI - Python Version PyPI - License PyPI - swarmauri_toolkit_runtime Discord

Swarmauri Toolkit RuntimeToolkit

RuntimeToolkit is a Swarmauri runtime-management toolkit for agents that need to register, inspect, list, replace, and remove tools during execution. It keeps tool mutation inside the active toolkit instance and requires both explicit parameter declarations and an explicit __call__ implementation when a new runtime tool is introduced.

Features

  • Bundles agent-callable CRUD operations for toolkit members.
  • Accepts serialized runtime tool specs with type, parameters, and __call__ fields.
  • Enforces a non-empty declared parameters list and a non-empty __call__ body for runtime tool registration and replacement.
  • Evaluates runtime __call__ bodies through a restricted expression rail rather than unrestricted Python execution.
  • Returns agent-friendly dictionaries for reads, lists, and mutation results.
  • Protects the toolkit's own management tools from accidental overwrite or removal.
  • Supports Python 3.10 through 3.12.

Support

  • Python 3.10
  • Python 3.11
  • Python 3.12

Installation

uv

uv add swarmauri_toolkit_runtime

pip

pip install swarmauri_toolkit_runtime

Usage

Use RuntimeToolkit when an agent needs to mutate its own tool surface safely at runtime. The expected workflow is:

  1. Start with the management toolkit.
  2. Register a runtime tool using an explicit parameter contract and explicit callable body.
  3. Inspect or list the available runtime tools.
  4. Execute the registered tool.
  5. Replace or unregister the tool when the runtime surface changes.

Instantiate the toolkit and hand it to an agent or tool-capable model. The toolkit starts with only its management tools, then grows as the agent adds tools.

from swarmauri_toolkit_runtime import RuntimeToolkit

toolkit = RuntimeToolkit()

toolkit.get_tool_by_name("RegisterRuntimeTool")(
    {
        "type": "RuntimeAdditionTool",
        "name": "RuntimeAdditionTool",
        "description": "Adds two integers during the active agent session.",
        "parameters": [
            {
                "name": "x",
                "input_type": "integer",
                "description": "The left operand",
                "required": True,
            },
            {
                "name": "y",
                "input_type": "integer",
                "description": "The right operand",
                "required": True,
            },
        ],
        "__call__": '{"sum": str(x + y)}',
    }
)

result = toolkit.get_tool_by_name("RuntimeAdditionTool")(2, 3)
print(result)

Agent Workflow

  1. Call ListRuntimeTools to inspect the current runtime surface.
  2. Call RegisterRuntimeTool with a tool spec to extend the toolkit.
  3. Call InspectRuntimeTool to inspect the hydrated tool metadata.
  4. Call ReplaceRuntimeTool when the agent needs to replace a tool with a revised spec.
  5. Call UnregisterRuntimeTool when a runtime tool should no longer be available.

Tool Spec Contract

Mutation tools accept a serialized tool specification. At minimum, provide:

  • a non-empty type field that names the runtime tool surface
  • a non-empty parameters list that explicitly declares the runtime callable contract
  • a non-empty __call__ string that evaluates as a safe Python expression over the declared parameters and approved builtins

The runtime evaluator permits only a constrained expression subset and approved builtins such as str, int, float, len, sum, min, max, and abs. Imports, attribute traversal, and arbitrary function calls are rejected.

{
    "type": "RuntimeAdditionTool",
    "name": "RuntimeAdditionTool",
    "description": "Adds two integers.",
    "parameters": [
        {
            "name": "x",
            "input_type": "integer",
            "description": "The left operand",
            "required": True,
        },
        {
            "name": "y",
            "input_type": "integer",
            "description": "The right operand",
            "required": True,
        },
    ],
    "__call__": '{"sum": str(x + y)}',
}

The __call__ value is evaluated against the declared parameter names. A body such as {"sum": str(x + y)} is valid. A body that tries to import modules, access attributes, or reference undeclared names is rejected.

Failure Modes

  • Registration fails when the tool spec omits parameters.
  • Registration fails when the tool spec omits __call__.
  • Registration fails when the __call__ body uses unsafe syntax or disallowed names.
  • Registration fails when the tool name collides with a protected management tool.
  • Execution failures inside an accepted runtime tool return a structured error payload instead of propagating a hard exception or terminating the host process.
  • Replacement fails when the target tool is missing, reserved, or renamed to an existing tool.
  • Unregistration fails when the target is reserved or absent.

License

swarmauri_toolkit_runtime is released under the Apache 2.0 License. See LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

swarmauri_toolkit_runtime-0.11.0.dev1.tar.gz (12.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

swarmauri_toolkit_runtime-0.11.0.dev1-py3-none-any.whl (16.0 kB view details)

Uploaded Python 3

File details

Details for the file swarmauri_toolkit_runtime-0.11.0.dev1.tar.gz.

File metadata

  • Download URL: swarmauri_toolkit_runtime-0.11.0.dev1.tar.gz
  • Upload date:
  • Size: 12.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_toolkit_runtime-0.11.0.dev1.tar.gz
Algorithm Hash digest
SHA256 aef3653dbf0f70eb5fdecab60e00fda3c97b0f120257ab0626ceb591a7b7dc62
MD5 a4307fe2a7fe14a9f9f39a99e9bc7911
BLAKE2b-256 24129a9e944a162e5caa15997936b23f5608f8ac8b655541cefb2805cd2e468d

See more details on using hashes here.

File details

Details for the file swarmauri_toolkit_runtime-0.11.0.dev1-py3-none-any.whl.

File metadata

  • Download URL: swarmauri_toolkit_runtime-0.11.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 16.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.11.26 {"installer":{"name":"uv","version":"0.11.26","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for swarmauri_toolkit_runtime-0.11.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 167a3c36d2ed9075a34d8bc0b72bd8eb3f82eccb50ec73bdc1bb118baefe177f
MD5 7f6b6e2d455727220c54ee870169f2e7
BLAKE2b-256 c1f62c291534673657e23c0096a630e4e18f173aaac85711877b47613ce547e0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page