Skip to main content

agentbuild

Tools to make agent research easier.

Install

pip install agentbuild

Jupyter: %load_cells

Copy the code of cells from another notebook into the current cell, the way %load does for files.

%load_ext agentbuild.jupyter

%load_cells other.ipynb                            # list the notebook's cells, IDs and titles
%load_cells other.ipynb --cells 7f3a9c21 b2e4d0aa  # copy those cells into this cell
%load_cells "my export.ipynb" -c "Import Libraries" 7f3a
%load_cells other.ipynb -c 7f3a9c21 --run          # run those cells instead of copying them
%load_cells other.ipynb -c 7f3a9c21 --print        # print their code instead of copying it

Each cell after --cells (or -c) can be:

  • a cell ID: the Jupyter cell ID, or for notebooks exported from Databricks, the Databricks cell ID (nuid);
  • the start of a cell ID, such as the 8 characters the listing shows;
  • a Databricks cell title, matched exactly or ignoring case. Quote titles that contain spaces.

If a value matches more than one cell, the magic stops with an error instead of guessing.

Running the magic with --cells replaces the current cell with a commented-out copy of the magic line, followed by the code of the chosen cells in the order given. Run the cell again to execute that code. Relative paths are resolved from the kernel's working directory, which is normally the notebook's folder.

  • --run runs the chosen cells' code in the current session instead of copying it. Magics in that code, such as %pip, work as they would in a cell.
  • --print prints the code instead of replacing the current cell, for notebook apps that can't replace a cell's contents. This is the default on Databricks, whose notebooks can't (it's detected through the DATABRICKS_RUNTIME_VERSION environment variable).

To load the extension in every session, add this to ~/.ipython/profile_default/ipython_config.py:

c.InteractiveShellApp.extensions = ["agentbuild.jupyter"]

LLM calls: agentbuild.leanllm

One small client for OpenAI, Anthropic, Gemini and any OpenAI-compatible server (Azure OpenAI, Ollama, vLLM, OpenRouter), with retries, failover, load balancing and an on-disk response cache. Install the SDKs of the providers you use:

pip install "agentbuild[openai,anthropic,gemini]"

Keys come from OPENAI_API_KEY, ANTHROPIC_API_KEY and GEMINI_API_KEY.

from agentbuild.leanllm import LLM, Deployment

reply = LLM("openai/gpt-4o-mini").chat("Summarize this chunk: ...")
print(reply.text)

llm = LLM(
    route=[
        # Tier 1: two deployments of one model share the load
        [
            "openai/gpt-4o-mini",
            Deployment(
                "openai/gpt-4o-mini",
                base_url="https://my-azure.openai.azure.com/openai/v1",
                api_key_env="AZURE_OPENAI_KEY",
            ),
        ],
        # Later tiers are used only when every deployment above has failed
        ["anthropic/claude-haiku-4-5"],
        ["gemini/gemini-2.5-flash"],
    ],
    cache="./.llm_cache",  # None disables caching
    retries=2,  # per deployment, before moving on
    timeout=120,  # seconds per request
    cooldown=60,  # seconds a failing deployment is skipped
)
reply = llm.chat(
    [
        {"role": "system", "content": "Answer only from the context."},
        {"role": "user", "content": prompt},
    ],
    temperature=0,
    max_tokens=500,
)
reply.text, reply.finish_reason, reply.served_by, reply.cached, reply.usage, reply.attempts

vectors = LLM("openai/text-embedding-3-small", cache="./.llm_cache").embed(chunks)
  • A deployment's key can also be given directly, as Deployment(..., api_key=key); it is kept out of reprs and logs.
  • For an Azure OpenAI resource that cannot use the v1 endpoint yet, pass the same values as openai.AzureOpenAI: Deployment("openai/<deployment name>", base_url=<azure_endpoint>, api_version="2024-10-21", api_key=key).
  • await llm.achat(...) and await llm.aembed(...) behave the same, asynchronously.
  • cache=False skips the cache for one call; cache="refresh" calls the provider and overwrites the entry. A cached answer comes back even at a temperature above 0. Embeddings are cached one text at a time, so only new texts are sent. Keep the cache on a local disk: on Databricks, not under /dbfs or /Volumes.
  • provider_options={"gemini": {"thinking_config": {"thinking_budget": 0}}} passes options to one provider's API and is ignored by the others. Gemini 2.5 models think by default, and thinking counts against max_tokens.
  • A BadRequest (400, 422) is raised at once, with no failover. When every deployment fails, AllProvidersFailed.attempts lists each try: a.deployment, a.error, a.duration_s.
  • Each attempt is logged on the agentbuild.leanllm logger; on_attempt=callback receives it too.

See docs/leanllm_submodule.md for the full behaviour.

Development

Requires uv and make.

make install       # install the package + dev tools, set up git hooks
make help          # list all commands

Common commands:

make test          # run tests
make test-matrix   # run tests on Python 3.11-3.15 (override with PYTHONS="3.11 3.12")
make cov           # run tests with a coverage report
make lint          # lint + format check
make format        # auto-fix lint issues and format
make check         # run the same checks as CI

Release

make publish       # build and upload to PyPI (needs a PyPI token)

Metadata

Release files for agentbuild 0.0.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for agentbuild 0.0.3
File Size Uploaded Provenance
agentbuild-0.0.3.tar.gz 133.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for agentbuild 0.0.3
File Interpreter ABI Platform
agentbuild-0.0.3-py3-none-any.whl Python 3 none any Details

Total release size: 158.6 kB

Release files / agentbuild-0.0.3.tar.gz

Download URL agentbuild-0.0.3.tar.gz
Size 133.5 kB
Tags Source
SHA-256 checksum
How to use checksums
a4abf7887452b57a8f9f9601680bee4990e652bee71033389437046ee37c6a4e
BLAKE2b-256 checksum
How to use checksums
800caeb47fc782153280e9420564c5b50387d7ac3cfa463ebbc46de3122b6479
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / agentbuild-0.0.3-py3-none-any.whl

Download URL agentbuild-0.0.3-py3-none-any.whl
Size 25.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
aa364ac8f3ef9dcf462e1bc0d6bf13681eced714b497353741d67534b24bfd3c
BLAKE2b-256 checksum
How to use checksums
6a5cdc7d4289f466fbaeed0921939dad032d5eb0c7982cf90c64f0b48c0271f7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for agentbuild 0.0.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page