Skip to main content

LangChain chat model provider for Apple's on-device Foundation Models framework

Project description

langchain-apple-foundation-models

Use Apple's on-device Foundation Models as a drop-in LangChain chat model. Runs fully offline on macOS 26+ Apple Silicon -- no API key, no network call, no per-token cost.

demo

from langchain_apple_foundation_models import ChatAppleFoundationModels

llm = ChatAppleFoundationModels()
llm.invoke("What is the capital of France?")

Install

pip install git+https://github.com/rajanshxrma/langchain-apple-foundation-models.git

(Not yet on PyPI -- installing from source for now.)

Requires macOS 26+ with Apple Intelligence enabled and Apple Silicon.

Why

Apple shipped a Python SDK for its on-device model this year (apple-foundation-models), but there was no LangChain provider for it -- meaning none of LangChain's chains, agents, or tool-calling abstractions could target Apple's on-device model. This closes that gap.

Features

  • Tool calling: pass LangChain @tool-decorated functions via .bind_tools([...]), same as any other LangChain chat model.
  • Structured output: .with_structured_output(schema) for JSON-schema or Pydantic-constrained generation.
  • Streaming: .stream(...) yields tokens as they're generated.
  • Zero network calls -- generation happens entirely on-device via Apple's Neural Engine.

Architecture

flowchart LR
    App["Your LangChain code<br/>chains / agents / tools"] -->|".invoke() .stream() .bind_tools()"| Provider["ChatAppleFoundationModels"]
    Provider --> SDK["apple-foundation-models<br/>(Python SDK)"]
    SDK --> FM["Foundation Models framework<br/>on-device, Apple Silicon, Neural Engine"]
    FM -.->|"no network call, ever"| SDK

ChatAppleFoundationModels implements LangChain's standard chat model interface, so it drops into any existing chain, agent, or tool-calling setup as a swap-in for a cloud provider -- the only difference is generation happens on-device.

Example: tool calling

from langchain_core.tools import tool
from langchain_apple_foundation_models import ChatAppleFoundationModels

@tool
def get_weather(city: str) -> str:
    """Get the current weather for a city."""
    return f"The weather in {city} is sunny and 72F."

llm = ChatAppleFoundationModels().bind_tools([get_weather])
llm.invoke("What's the weather in Austin?")

Known limitations

  • Multi-turn history is owned by the underlying Session, not LangChain's message list. Each ChatAppleFoundationModels instance lazily creates one on-device Session and reuses it across calls; if you pass a message list that diverges from what the session itself has tracked, the two can get out of sync. Fresh chains work naturally; manually-edited history does not yet.
  • Built on the apple-foundation-models unofficial Python bindings (alpha), which itself wraps Apple's Foundation Models framework -- both inherit Apple's current 4,096-token context window.
  • No support (yet) for Apple's newer multi-model / Private Cloud Compute routing announced at WWDC26 -- that requires an OS/SDK combination not yet stable enough to depend on. See the repo issues for status.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

langchain_apple_foundation_models-0.1.0.tar.gz (47.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

File details

Details for the file langchain_apple_foundation_models-0.1.0.tar.gz.

File metadata

File hashes

Hashes for langchain_apple_foundation_models-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f931d9a76d9492ad1b5434e649e154eed6c03f41e4a953f7e7861f64fd8a3371
MD5 2520931aacaa090584a5f4a9b755e148
BLAKE2b-256 ea3118e115f56b304ccc4edd155fc505db5ff99a6e2aee3edb3e202eb0eb9242

See more details on using hashes here.

File details

Details for the file langchain_apple_foundation_models-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for langchain_apple_foundation_models-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 97dabcf56599a6d5fa7b67159a729f1d7b2b3892b3760b704f8c12b2d600d953
MD5 ee08e4c43edcfbc49e982be1cc7cb4ea
BLAKE2b-256 55afdfa264beeed38b0b47b3d4b99e8525b6b12138b5a515a1f715f65c6974bb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page