Skip to main content

Library-friendly agents that work directly with your existing Python codebase.

Project description

agex: Library-Friendly Agents

agex (a portmanteau of agent execution) is a Python library for building AI agents that work directly with your code.

You define a typed Python function with @task and the agent fills it in. It writes sandboxed Python that calls into the modules you've whitelisted, returning real Python objects (DataFrames, Plotly figures, your Pydantic models) that flow back into your code unchanged. There's no JSON serialization at the boundary and no separate runtime to deploy: agex runs inside your application's Python process.

Because the sandbox is pure-Python AST rewriting, the same agent code runs in-process, in a subprocess, in a kernel-isolated worker, or (via Pyodide) entirely in a browser tab. agex-studio is the proof-of-concept: pandas, scikit-learn, plotly, and a chat agent all running client-side with no backend.

import pandas as pd
from agex import Agent

agent = Agent()
agent.module(pd)

@agent.task
def summarize(df: pd.DataFrame) -> dict[str, float]:
    """Return summary statistics for the numeric columns."""
    pass

stats = summarize(my_dataframe)  # real dict[str, float]

Demo of an agex agent returning pandas DataFrames and plotly figures in an IPython REPL

What you get

  • Typed function tasks - @task declares the input/output contract; the agent fulfills it.
  • Curated Python environment - whitelist exactly which modules and classes the agent can use, with per-member visibility.
  • Versioned workspace - virtual filesystem, the agent's session memory, and event log are all kvgit-backed, with checkpoints and time-travel.
  • Multi-agent orchestration - coordinate agents with regular Python control flow; sub-agents are just functions.
  • Flexible execution - in-process by default; subprocess, kernel-isolated, browser (Pyodide), or remote (Modal, HTTP) when you need them.

For a deeper dive, see the agex101 tutorial or the geospatial routing example for multi-library integration. For a NiceGUI integration demo, see agex-ui.

Documentation

Complete documentation is hosted at ashenfad.github.io/agex.

Key sections:

Installation

Install agex with your preferred LLM provider:

pip install "agex[openai]"        # OpenAI models
pip install "agex[anthropic]"     # Anthropic Claude models
pip install "agex[gemini]"        # Google Gemini models

# Or with all providers
pip install "agex[all-providers]"

Project Status

This is a hobby project in active development. The core concepts are stabilizing but the API should be considered experimental.

If you're looking for a more battle-tested library built on the same "agents-that-think-in-code" idea, smolagents (Hugging Face) is the closest cousin and a good choice. agex explores a different shape: an embeddable library you import into your application, with typed function contracts and a pure-Python sandbox that runs anywhere Python runs (including the browser).

Built On

agex is composed of several focused libraries that can also be used independently:

Library Purpose
sandtrap In-process Python sandbox via AST rewriting
kvgit Versioned key-value store with git-like semantics
monkeyfs Filesystem interception via monkey-patching
termish Virtual terminal with shell-like commands
reprobate Budget-controlled repr for Python objects

Contributing

Bug reports, ideas, and pull requests welcome - see GitHub Issues or the Contributing Guide.

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

agex-0.12.3.tar.gz (269.2 kB view details)

Uploaded Source

Built Distribution

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

agex-0.12.3-py3-none-any.whl (327.6 kB view details)

Uploaded Python 3

File details

Details for the file agex-0.12.3.tar.gz.

File metadata

  • Download URL: agex-0.12.3.tar.gz
  • Upload date:
  • Size: 269.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for agex-0.12.3.tar.gz
Algorithm Hash digest
SHA256 a9d5cf50895fdcc17a3f05da163d3a2d2d8ecc3c8df40878d8a016ae75354305
MD5 5e76dd721d4b674b340223b213deea9b
BLAKE2b-256 db2cd56f4a76edfe165e57cce3b85e29751ca104624c1df7447fe41ba0b52cd5

See more details on using hashes here.

File details

Details for the file agex-0.12.3-py3-none-any.whl.

File metadata

  • Download URL: agex-0.12.3-py3-none-any.whl
  • Upload date:
  • Size: 327.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.13

File hashes

Hashes for agex-0.12.3-py3-none-any.whl
Algorithm Hash digest
SHA256 da178918444e5f1257492760c0347b7750564b0c4d282e224d33968e8ad6a1ea
MD5 f0b10afa0fe0f78aa26964d96c060d9b
BLAKE2b-256 9e1cacfba401c337f9e9dcdcb7ad2ff0e8a7823ad0557f849b98c6618f5562da

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