muscles-ai
Framework-level AI package for the Muscles ecosystem.
Purpose
- Keep reusable AI/RAG contracts, runtimes, and actions in one framework package.
- Provide read-only primitives for question answering and retrieval.
- Stay transport-agnostic: transport adapters (HTTP/CLI/MCP/JSON-RPC/SSE) call
Muscles actions.
Ecosystem Position
muscles-ai is a framework extension, not an application template and not a
transport adapter. It registers AI-oriented actions in a Muscles app and lets
other packages project those actions through HTTP, CLI, MCP, JSON-RPC or SSE.
Related repositories:
muscles- core action contracts, dispatcher, inspect contract and canonical documentation.muscles-documents- document loading/parsing/chunking actions that AI flows can inspect or compose with.muscles-mcp- MCP projection for AI tools.muscles-sse- streaming projection for long AI output.muscles-benchmarks- regression coverage for AI extension contracts.
Installation
pip install muscles-ai
The canonical ecosystem install matrix lives in
muscles/docs/installation.md.
The package expects to be loaded as a Muscles module:
modules:
ai:
package: muscles.ai
provider: "noop"
transports: ["http", "cli", "mcp"]
Optional in-process providers are installed only when needed:
pip install "muscles-ai[openai]"
pip install "muscles-ai[llama-cpp]"
The application does not need Ollama or another model server. An adapter can call an external SDK/API directly or load a local model library in the current process.
Public API
Importing package symbols uses lazy __getattr__ to keep package startup lightweight:
AiPackage— package installer forinit_packageintegration.AiRuntime— runtime container for RAG execution.SearchQuery,RetrievedChunk,ContextBlock,Citation,RetrievalPolicy.SearchResult,ContextResult,AskResult,SearchHit,SourceChunk.VectorSearchPort,KeywordSearchPort,ParentFetchPort,IndexRequestPort,LLMProvider.InMemoryRagSource,FakeLLMProvider,NoopLLMProviderfor tests and examples.ModelGateway,ModelProviderCatalog,ModelCapabilityand typed requests/results for text, image and embedding capabilities.PythonModelAdapterfor project-owned models andopenai/llama_cppoptional providers.AiConfig.init_package(app, config)entry point for Muscles.
Default actions
The package registers the following actions:
ai.askai.searchai.retrieve_contextai.sources.listai.source.inspectai.documents.inspectai.index.requestai.inspectai.doctor
AI architecture contract
inspect_application(app)["capabilities"]["ai"]["architecture"] publishes a
machine-readable implementation contract for developers and coding agents. It
contains the package role, preferred/allowed/forbidden patterns and stable
deterministic rules with id, severity and summary fields.
Every ai.* action also declares three metadata namespaces:
metadata["ai"]describes the AI/RAG operation;metadata["architecture"]describes side effects, state changes and confirmation;metadata["mcp"]describes MCP exposure and read-only safety.
ai.index.request is state-changing and requires explicit confirmation. The
package doctor validates these invariants without loading an AI model or making
provider network calls. An AI model may consume the contract to guide code
generation, but it is not used to enforce the rules.
RAG Toolkit
muscles-ai owns RAG orchestration, not project data storage:
query -> retrieval -> merge -> deterministic rerank -> context -> prompt -> LLM -> answer + citations
Projects register sources/adapters on AiRuntime:
from muscles.ai import InMemoryRagSource, RetrievedChunk
runtime.register_source(
"kb",
InMemoryRagSource(
"kb",
chunks=[
RetrievedChunk(
chunk_id="flowwow-1",
text="Flowwow backend used PostgreSQL and Kafka.",
source="kb",
parent_id="flowwow",
title="Flowwow",
)
],
),
)
Real projects can implement the same ports over Qdrant, PostgreSQL, Elasticsearch or another store. This package does not own DSNs, collections, mappings, migrations or document parsing.
Model Gateway
ModelGateway is the universal in-process model facade. It routes typed
requests to named models without exposing provider SDKs to business actions:
from muscles.ai import ImageGenerationRequest, ModelGateway, TextGenerationRequest
gateway = ModelGateway.from_config(
providers={
"local": {"type": "llama_cpp", "options": {"model_path": "models/model.gguf"}},
"images": {"type": "openai", "options": {"api_key_env": "OPENAI_API_KEY"}},
},
models={
"text.local": {
"provider": "local",
"model": "local-text",
"capabilities": ["text.generate"],
},
"image.remote": {
"provider": "images",
"model": "dall-e-3",
"capabilities": ["image.generate"],
},
},
defaults={"text.generate": "text.local"},
)
text = gateway.invoke(TextGenerationRequest(prompt="Explain RAG"))
image = gateway.invoke(
ImageGenerationRequest(prompt="A simple framework diagram"),
model="image.remote",
)
The public facade is shared, while request and response types remain specific to
the capability. New local runtimes can be registered through
ModelProviderCatalog or PythonModelAdapter; no model server is required.
Images and other binary results are returned as Artifact values containing
bytes or a provider reference. The project decides whether to persist them.
Notes
muscles-aiintentionally does not open HTTP routes.- Runtime clients must be registered in DI and used from actions/context, not kept in
ApplicationRegistry. - Transport packages should discover
ai.*actions throughinspect_application(app)and execute throughActionDispatcher. - Document ingestion belongs in
muscles-documents; AI should consume document contracts instead of duplicating parsers. - Telemetry is resolved through the neutral Muscles
TelemetryProvider; this package does not importmuscles-oteldirectly.
Telemetry
When a project registers a TelemetryProvider, muscles-ai emits safe spans:
muscles.ai.embedmuscles.ai.retrievemuscles.ai.rerankmuscles.ai.prompt.buildmuscles.ai.generatemuscles.ai.answer
Allowed attributes include provider/model names, retriever name, retrieved document count and citation count. Raw queries, prompts, answers, excerpts, chunks, request bodies and API keys must not be stored in span attributes.
Examples
Direct package initialization
Run an end-to-end smoke scenario with muscles.ai actions:
PYTHONPATH=src python examples/run_ai_smoke.py
Action calls through a dispatcher
PYTHONPATH=src python examples/run_ai_configured.py
Both examples:
- initialize the package via
init_package(app, config); - register all ai actions;
- call actions through
ActionDispatcher; - demonstrate the neutral telemetry provider hook without requiring
muscles-otel.
Metadata
Release files for muscles-ai 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| muscles_ai-0.2.0.tar.gz | 34.5 kB | With provenance | Details for muscles_ai-0.2.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| muscles_ai-0.2.0-py3-none-any.whl | Python 3 | none | any | Details for muscles_ai-0.2.0-py3-none-any.whl |
Total release size: 65.5 kB
Release files / muscles_ai-0.2.0.tar.gz
| Download URL | muscles_ai-0.2.0.tar.gz |
|---|---|
| Size | 34.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
1986a9920e1999a34a894f17e368d71b1422f48ad5343f672a4cbaf020d0f5c9
|
|
BLAKE2b-256 checksum How to use checksums |
7371f485252d6fdf739a171ae67deeee1f852291811c54360d822ba635409b11
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 4, 2026.
Transparency logRelease files / muscles_ai-0.2.0-py3-none-any.whl
| Download URL | muscles_ai-0.2.0-py3-none-any.whl |
|---|---|
| Size | 31.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
c019e8986613482f58405b9b4ac9dcc1f2625f921894adb05d97c55a4912c988
|
|
BLAKE2b-256 checksum How to use checksums |
2650688d14351603dd8149d73b96260d8818f35a3f72ae8f35369c542a3be078
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.16
|
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 Nov 4, 2026.
Transparency logSecurity for muscles-ai 0.2.0
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.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for muscles_ai-0.2.0.tar.gz
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 Nov 4, 2026.
Transparency logA 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.