Agent Framework MLX
This library provides an Apple MLX LM backend for the Agent Framework. It allows you to run Language Models locally on macOS with Apple Silicon using the mlx-lm library.
Features
- Local Inference: Run models directly on your Mac using Apple Silicon
- Tool Calling: Native support for agentic tool invocation.
- Observability: Built-in OpenTelemetry tracing, metrics, and token usage tracking.
- Streaming Support: Full support for streaming responses.
- Configurable Generation: Fine-tune generation parameters like temperature, top-p, repetition penalty, and more.
- Message Preprocessing: Hook into the pipeline to modify messages before they are converted to prompts.
- Agent Framework Integration: Seamlessly plugs into the Agent Framework's
BaseChatClientinterface.
Installation
Ensure you have Python 3.9+ and are running on macOS with Apple Silicon.
pip install agent-framework-mlx
Or install from source:
git clone https://github.com/filipw/agent-framework-mlx.git
cd agent-framework-mlx
pip install -e .
Usage
Basic Example
import asyncio
from agent_framework import ChatMessage, Role, ChatOptions
from agent_framework_mlx import MLXChatClient, MLXGenerationConfig
# Initialize the client
client = MLXChatClient(
model_path="mlx-community/Phi-4-mini-instruct-4bit",
generation_config=MLXGenerationConfig(
temp=0.7,
max_tokens=500
)
)
# Create messages
messages = [
ChatMessage(role=Role.SYSTEM, text="You are a helpful assistant."),
ChatMessage(role=Role.USER, text="Why is the sky blue?")
]
# Get response
response = await client.get_response(messages=messages)
print(response.text)
Agent with Tools
You can easily create agents capable of calling tools (Python functions) using the client:
from typing import Annotated
def calculate_bmi(weight: float, height: float) -> str:
"""Calculates BMI."""
return f"{weight / (height ** 2):.2f}"
# Create an agent with the tool
agent = client.as_agent(
name="HealthAssistant",
instructions="You are a helpful assistant.",
tools=[calculate_bmi]
)
response = await agent.run("Calculate BMI for 70kg and 1.75m")
print(response)
Workflow Integration
You can use the client as backbone for Agent Framework agents when building agentic workflows:
from agent_framework import ChatAgent
# notice the client constructed in the previous example now backs the local agent
local_agent = client.as_agent(
name="Local_MLX",
instructions="You are a helpful assistant."
)
remote_agent = ChatAgent(
name="Cloud_LLM",
instructions="You are a fallback expert. The previous assistant was unsure. Provide a complete answer.",
chat_client=azure_client
)
builder = WorkflowBuilder()
builder.set_start_executor(local_agent)
builder.add_edge(
source=local_agent,
target=remote_agent,
condition=should_fallback_to_cloud
)
workflow = builder.build()
Streaming
async for update in client.get_streaming_response(messages=messages):
print(update.text, end="", flush=True)
Configuration
You can configure the client using environment variables or a .env file. Using environment variables like MLX_MODEL_PATH allows you to omit arguments in code.
export MLX_MODEL_PATH="mlx-community/Phi-4-mini-instruct-4bit"
# No arguments needed if env vars are set
client = MLXChatClient()
Advanced Configuration
You can configure generation parameters globally via MLXGenerationConfig or per-request via MLXChatOptions.
config = MLXGenerationConfig(
temp=0.7,
top_p=0.9,
repetition_penalty=1.1,
seed=42
)
Message Preprocessing
You can intercept and modify messages before they are sent to the model. This is useful for injecting instructions or formatting content.
def inject_instruction(messages):
if messages:
messages[-1]["content"] += "\nIMPORTANT: Be concise."
return messages
client = MLXChatClient(
model_path="...",
message_preprocessor=inject_instruction
)
Requirements
- macOS
- Apple Silicon
- Python 3.9+
License
This project is licensed under the MIT License. See the LICENSE file for details.
Metadata
Release files for agent-framework-mlx 0.7.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 |
|---|---|---|---|---|
| agent_framework_mlx-0.7.0.tar.gz | 15.3 kB | With provenance | Details for agent_framework_mlx-0.7.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| agent_framework_mlx-0.7.0-py3-none-any.whl | Python 3 | none | any | Details for agent_framework_mlx-0.7.0-py3-none-any.whl |
Total release size: 25.8 kB
Release files / agent_framework_mlx-0.7.0.tar.gz
| Download URL | agent_framework_mlx-0.7.0.tar.gz |
|---|---|
| Size | 15.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a83d6ff4ba27136e50136b37675f540173e5c4108ae00198f6fd7e5031330fef
|
|
BLAKE2b-256 checksum How to use checksums |
add69ba7bb6eaa9bd7be6950a048b70fd2d7bb05328cd6cfa7cb53a75cf419a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.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 Jul 29, 2026.
Transparency logRelease files / agent_framework_mlx-0.7.0-py3-none-any.whl
| Download URL | agent_framework_mlx-0.7.0-py3-none-any.whl |
|---|---|
| Size | 10.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0fa1d5852e3a9aa4bf262740e2204f3a41d9524c3756f234153a75d338f3790f
|
|
BLAKE2b-256 checksum How to use checksums |
b3a65a1ca9119c461d6366ce3a7ff37a17ee3a40c4edfff4bf045fb08d793a85
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.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 Jul 29, 2026.
Transparency logSecurity for agent-framework-mlx 0.7.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 agent_framework_mlx-0.7.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 Jul 29, 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.