Skip to main content

functualize-ai

Status: Published — Independently installable from PyPI.

AI Domain SDK for functualize — provider-agnostic LLM interaction capabilities.

Provides the AI capability class with structured output, tool calling, streaming, and extraction methods backed by a pluggable AIProvider protocol. Includes deny-by-default tool visibility via ToolScope, cumulative budget enforcement, lifecycle event emission, and a deterministic MockAI testing double for unit testing without network calls or API keys.

Installation

pip install functualize-ai

Quick Start

from functualize_ai import AI, ToolScope, AILimits
from functualize_ai.testing import MockAI

# Use MockAI for deterministic testing (no API key needed)
ai = MockAI(responses={"*summarize*": "A brief summary of the document."})

# Simple text completion
result = ai.complete("Please summarize this text")
print(result)  # "A brief summary of the document."

# Run with tool scope and budget limits
scope = ToolScope.only(["search", "calculate"])
limits = AILimits(budget_usd=1.00, max_tool_calls=5)
ai_result = ai.run("Find the answer", tools=scope, limits=limits)
print(ai_result.output)

Features

  • Provider-agnostic AI class with complete(), run(), stream(), and extract() methods for text, structured output, tool calling, and streaming
  • ToolScope builder implementing deny-by-default tool visibility — restrict tools by name, tag, group, or plain callables with composable + operator
  • Budget enforcement tracking cumulative USD spend across calls with automatic BudgetExceeded errors when limits are reached
  • Structured output validation with automatic retry (up to 3 attempts) against Pydantic models or dataclasses
  • MockAI testing double using glob-pattern matching for deterministic, network-free testing with full call recording
  • Lifecycle event emission (AI_CALL_STARTED, AI_CALL_COMPLETED, AI_CALL_FAILED, AI_BUDGET_EXCEEDED, AI_TOOL_CALLED) for observability and audit logging
  • AIProvider protocol enabling custom backend implementations (PydanticAI, LiteLLM, or any LLM SDK)

API Reference

Public classes and functions exported by this plugin:

Capability

  • AI — Provider-agnostic LLM interaction class with complete(), run(), stream(), extract() methods

Protocol

  • AIProvider — Runtime-checkable protocol that AI backend implementations must satisfy

Tool Scope

  • ToolScope — Deny-by-default tool visibility builder with only(), tagged(), group(), functions() factory methods

Types

  • AIResult — Result of an AI run containing output, tool_calls, usage, and duration_ms
  • TokenUsage — Token usage statistics (prompt_tokens, completion_tokens, total_tokens, cost_usd)
  • ToolDef — Provider-agnostic tool definition with name, description, and parameters schema
  • AILimits — Budget and constraint caps (max_tool_calls, max_tokens, budget_usd, timeout_seconds)
  • ToolCallRecord — Record of a single tool call with name, args, result, and duration

Configuration

  • AIConfig — Pydantic model for AI domain configuration (provider, model, max_tokens, budget_usd, timeout_seconds)

Errors

  • AINotAvailable — Raised when no AI provider is configured
  • BudgetExceeded — Raised when cumulative spend reaches the budget limit
  • ToolNotPermitted — Raised when a tool call is not permitted by the current ToolScope

Events

  • AI_CALL_STARTED — Emitted when an AI call begins
  • AI_CALL_COMPLETED — Emitted when an AI call completes successfully
  • AI_CALL_FAILED — Emitted when an AI call fails
  • AI_BUDGET_EXCEEDED — Emitted when budget is exceeded
  • AI_TOOL_CALLED — Emitted when a tool is called during a run

Testing

  • MockAI — Pattern-matching AI mock for deterministic testing
  • MockAICall — Record of a single MockAI call (prompt, response_model, response)

Provider Discovery

  • discover_ai_providers() — Discover available AI provider entry points
  • select_ai_provider() — Select a provider by name from discovered providers
  • resolve_ai_provider() — Resolve and instantiate the configured AI provider

State Fallback

  • EphemeralStateBackend — In-memory state backend for when no persistent state is available
  • StrictStateBackendWrapper — Wrapper enforcing strict key access on a state backend
  • resolve_ai_state_backend() — Resolve the AI state backend from context

Development

Run plugin tests:

uv run pytest plugins/domains/functualize-ai/tests/ -v

Release files for functualize-ai 0.4.0

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

Source distribution (sdist)

Source distribution for functualize-ai 0.4.0
File Size Uploaded
functualize_ai-0.4.0.tar.gz 30.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for functualize-ai 0.4.0
File Interpreter ABI Platform
functualize_ai-0.4.0-py3-none-any.whl Python 3 none any Details

Total release size: 63.1 kB

Release files / functualize_ai-0.4.0.tar.gz

Download URL functualize_ai-0.4.0.tar.gz
Size 30.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b1a25ad58631699ffe18c5e941b68037bdd125597470d204d1fc69b0d7067b14
BLAKE2b-256 checksum
How to use checksums
1373b444a70d277f06c3d951d0e5c66796df9b1fac93d6bd3750e928b8675e0d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release files / functualize_ai-0.4.0-py3-none-any.whl

Download URL functualize_ai-0.4.0-py3-none-any.whl
Size 32.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
c6afd8575d2c8890a6d5c3d8ae20a8c2c5cfdda1f6d7c2567109d745ffeaa4e2
BLAKE2b-256 checksum
How to use checksums
83cf09666b0254ae9e396c698a0f20363a24942de95ec5074a90f3fc126ebec2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 25, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.4.0 This release

2 release files

0.3.0

2 release files

0.2.3

2 release files

0.2.2

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

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