Unified multi-provider AI client, orchestration, and tool system
Project description
matrx-ai
Unified multi-provider AI client, orchestration, and tool system for Python. One UnifiedAIClient that speaks to 12+ provider SDKs (OpenAI, Anthropic, Google, Groq, Cerebras, xAI, Together, ElevenLabs, Hugging Face, Cohere, Fireworks, Replicate) through a common UnifiedConfig / UnifiedMessage / UnifiedResponse contract, with streaming, tool calls, agents, and an orchestrator that runs a model until its task is complete.
Install
pip install matrx-ai
Python 3.13+ required. Depends on matrx-utils, matrx-connect, matrx-graph, plus the provider SDKs. Host applications inject their own ORM models at startup via matrx_ai.configure(...).
What's in the box
- Unified client (
UnifiedAIClient): one async interface over every supported provider; request translation + response normalization handled by per-provider adapters. - Config + message types:
UnifiedConfig,UnifiedMessage,MessageList,UnifiedResponse, enums (Provider,Role,ContentType,FinishReason), usage trackers (TokenUsage,TimingUsage,ToolCallUsage). - Orchestrator:
AIMatrixRequest,CompletedRequest,execute_until_complete(...)— autonomous multi-turn execution with tool loops. - Agents (
matrx_ai.agents): template + session-based agent system; caching; services. - Tools (
matrx_ai.tools): registry + built-in implementations (ctx_patch,ctx_create, shell, code, …). All host-specific integration points (ContextManifest, writeback persistence, test helpers) come in viaconfigure(). - Context (
matrx_ai.context): re-exportsAppContext+Emitterfrommatrx-connect. - Persistence (
matrx_ai.db): Supabase-backed conversation/request storage. ORM models are host-injected. - Providers (
matrx_ai.providers): per-provider translators, request shaping, streaming adapters, parameter modifiers (e.g. GPT-5 stripstemperature/top_p).
Usage
One-shot call
from matrx_ai import UnifiedAIClient, UnifiedConfig, UnifiedMessage, Provider, Role
client = UnifiedAIClient()
config = UnifiedConfig(
provider=Provider.ANTHROPIC,
ai_model="claude-sonnet-4-6",
messages=[UnifiedMessage(role=Role.USER, content="Summarize the Magna Carta.")],
stream=False,
)
response = await client.run(config)
print(response.text)
Streaming
config = UnifiedConfig(
provider=Provider.OPENAI,
ai_model="gpt-4o",
messages=[UnifiedMessage(role=Role.USER, content="Explain RAFT.")],
stream=True,
)
async for chunk in client.stream(config):
print(chunk.delta, end="", flush=True)
Autonomous execution (tools + multi-turn)
from matrx_ai import execute_until_complete, AIMatrixRequest
request = AIMatrixRequest(
config=config,
tools=["web_search", "code_executor"],
max_iterations=10,
)
completed = await execute_until_complete(request)
print(completed.final_response.text)
print(completed.timing_usage, completed.token_usage)
Host integration — matrx_ai.configure(...)
matrx-ai is designed to be embedded in a larger application (like aidream) that supplies ORM models, settings, and context-object classes. It is also designed to run without any of that configuration — most features work on their own; the DB-dependent ones raise ExtNotConfiguredError at call time if the host didn't wire them up.
import matrx_ai
matrx_ai.configure(
db_models={"AiModel": AiModel, "CxConversation": CxConversation, ...},
db_bases={"CxConversationBase": CxConversationBase, ...},
db_instances={"guest_executions_manager": guest_manager},
db_extras={"ContentBlocksDTO": ContentBlocksDTO},
settings=settings,
get_supabase_client=get_async_supabase_client,
file_handler_class=FileHandler,
# Context-object model classes (used by ctx_patch / ctx_create tools)
context_object_cls=ContextObject,
context_object_type_cls=ContextObjectType,
context_source_cls=ContextSource,
persist_mode_cls=PersistMode,
context_manifest_cls=ContextManifest,
load_manifest_from_ctx=load_manifest_from_ctx,
schedule_context_writeback=schedule_writeback,
# …anything else the host wants to make available
)
This is the reference implementation of the "capability-within, injection-without" pattern used throughout the Matrx family — the package stores injected values in a module-level _ext registry; feature code retrieves them at call time via get_ext("…"). import matrx_ai always works in a minimal environment; only features that need a specific injection will raise if it's missing.
Dependency posture
Hard deps: matrx-utils, matrx-connect, matrx-graph, plus the provider SDKs (Anthropic, OpenAI, Google GenAI, Groq, Cerebras, xAI, Together, Cohere, Fireworks, Replicate, Tiktoken) and core libs (pydantic, httpx, aiohttp, supabase, asyncpg, json-repair, numpy, rich).
matrx-ai does not depend on matrx-orm. The host app that embeds matrx-ai may use matrx-orm (aidream does), but matrx-ai itself accepts ORM model classes through configure(db_models=..., db_bases=..., ...) rather than importing them.
Replaces
The old root-level ai/ folder in the aidream monorepo. matrx-ai is now the canonical AI layer.
Contributing
See CLAUDE.md for package-specific rules (including the _ext injection pattern and the forbidden-imports list). Deep per-subsystem docs live in matrx_ai/MODULE_README.md. This package lives in the aidream monorepo at github.com/AI-Matrix-Engine/aidream-current.
License
MIT.
Project details
Release history Release notifications | RSS feed
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 matrx_ai-0.4.18.tar.gz.
File metadata
- Download URL: matrx_ai-0.4.18.tar.gz
- Upload date:
- Size: 2.5 MB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a9648ac0f9f982c81b1b39810db9d7af20ee22f626362fb45bc7452aa5d198e
|
|
| MD5 |
2f2b016a6b76148f4e529bafdc2ccc80
|
|
| BLAKE2b-256 |
183d58593debcc10e919ef6c7967586c27559dab9939cb2864331c7ebf834791
|
Provenance
The following attestation bundles were made for matrx_ai-0.4.18.tar.gz:
Publisher:
publish-package.yml on AI-Matrix-Engine/aidream
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
matrx_ai-0.4.18.tar.gz -
Subject digest:
3a9648ac0f9f982c81b1b39810db9d7af20ee22f626362fb45bc7452aa5d198e - Sigstore transparency entry: 2194328896
- Sigstore integration time:
-
Permalink:
AI-Matrix-Engine/aidream@99e36cf0b84f35134d4edc08e31f0621bb4c3840 -
Branch / Tag:
refs/tags/matrx-ai/v0.4.18 - Owner: https://github.com/AI-Matrix-Engine
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package.yml@99e36cf0b84f35134d4edc08e31f0621bb4c3840 -
Trigger Event:
push
-
Statement type:
File details
Details for the file matrx_ai-0.4.18-py3-none-any.whl.
File metadata
- Download URL: matrx_ai-0.4.18-py3-none-any.whl
- Upload date:
- Size: 2.5 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4731f1aa0cd362c273335b217d15693876267f9cf3cdd9f2e8333dfa277e6f69
|
|
| MD5 |
7eaaf8b51c51bc16878fc49939d2ca71
|
|
| BLAKE2b-256 |
147b54f64b2af2833a9ebff5bc7cdea4fa84dc3ba800fd0606ab0bca6ca5e52c
|
Provenance
The following attestation bundles were made for matrx_ai-0.4.18-py3-none-any.whl:
Publisher:
publish-package.yml on AI-Matrix-Engine/aidream
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
matrx_ai-0.4.18-py3-none-any.whl -
Subject digest:
4731f1aa0cd362c273335b217d15693876267f9cf3cdd9f2e8333dfa277e6f69 - Sigstore transparency entry: 2194328903
- Sigstore integration time:
-
Permalink:
AI-Matrix-Engine/aidream@99e36cf0b84f35134d4edc08e31f0621bb4c3840 -
Branch / Tag:
refs/tags/matrx-ai/v0.4.18 - Owner: https://github.com/AI-Matrix-Engine
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-package.yml@99e36cf0b84f35134d4edc08e31f0621bb4c3840 -
Trigger Event:
push
-
Statement type: