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(), andextract()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
BudgetExceedederrors 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 withcomplete(),run(),stream(),extract()methods
Protocol
AIProvider— Runtime-checkable protocol that AI backend implementations must satisfy
Tool Scope
ToolScope— Deny-by-default tool visibility builder withonly(),tagged(),group(),functions()factory methods
Types
AIResult— Result of an AI run containingoutput,tool_calls,usage, andduration_msTokenUsage— Token usage statistics (prompt_tokens,completion_tokens,total_tokens,cost_usd)ToolDef— Provider-agnostic tool definition with name, description, and parameters schemaAILimits— 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 configuredBudgetExceeded— Raised when cumulative spend reaches the budget limitToolNotPermitted— Raised when a tool call is not permitted by the current ToolScope
Events
AI_CALL_STARTED— Emitted when an AI call beginsAI_CALL_COMPLETED— Emitted when an AI call completes successfullyAI_CALL_FAILED— Emitted when an AI call failsAI_BUDGET_EXCEEDED— Emitted when budget is exceededAI_TOOL_CALLED— Emitted when a tool is called during a run
Testing
MockAI— Pattern-matching AI mock for deterministic testingMockAICall— Record of a single MockAI call (prompt, response_model, response)
Provider Discovery
discover_ai_providers()— Discover available AI provider entry pointsselect_ai_provider()— Select a provider by name from discovered providersresolve_ai_provider()— Resolve and instantiate the configured AI provider
State Fallback
EphemeralStateBackend— In-memory state backend for when no persistent state is availableStrictStateBackendWrapper— Wrapper enforcing strict key access on a state backendresolve_ai_state_backend()— Resolve the AI state backend from context
Development
Run plugin tests:
uv run pytest plugins/functualize-ai/tests/ -v
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file functualize_ai-0.1.0.tar.gz.
File metadata
- Download URL: functualize_ai-0.1.0.tar.gz
- Upload date:
- Size: 22.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7fc8ae5fee7c0474a3504830d618dcdd99c440fb42608b276fa51a839d4c29e2
|
|
| MD5 |
ceeec5c1ef062e3c3cf753703db818c6
|
|
| BLAKE2b-256 |
f866d9d7ee6b258a4c6c208bc1594db2371a515cf8cf359bd40510c4ac64c730
|
File details
Details for the file functualize_ai-0.1.0-py3-none-any.whl.
File metadata
- Download URL: functualize_ai-0.1.0-py3-none-any.whl
- Upload date:
- Size: 25.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6dd65e1a84b939b3d8b0eea06bbff5efe0d9284e7baa8653116838ada2250d11
|
|
| MD5 |
8efc3a3fa624c7a93ec36baa61c0b998
|
|
| BLAKE2b-256 |
8801fc5d68005dbcfff1c12d79369b088e51ded674e1aed5f1aea89d2c0382a5
|