Skip to main content

AFM LangChain Backend

PyPI version Python version License

LangChain execution backend for Agent-Flavored Markdown (AFM) agents.

This package implements the AgentRunner protocol from afm-core, providing LLM orchestration using the LangChain framework.

Features

  • AgentRunner Protocol Implementation: Pluggable backend for AFM agents
  • LLM Provider Support: OpenAI and Anthropic models
  • MCP Tool Integration: Connect external tools via Model Context Protocol
  • Conversation Management: Session history and state management
  • Plugin Registration: Auto-discovered via Python entry points

Installation

This package is typically installed as part of afm-cli. For LangChain-specific use:

pip install afm-langchain

Supported Providers

OpenAI

model:
  provider: openai
  name: gpt-4o  # or other OpenAI models

Requires: OPENAI_API_KEY environment variable

Anthropic

model:
  provider: anthropic
  name: claude-sonnet-4-5  # or other Claude models

Requires: ANTHROPIC_API_KEY environment variable

Development

Setup

This project uses uv for dependency management.

# Clone the repository
git clone https://github.com/wso2/reference-implementations-afm.git
cd python-interpreter

# Install dependencies
uv sync

# Activate the virtual environment
source .venv/bin/activate

Running Tests

# Run afm-langchain tests
uv run pytest packages/afm-langchain/tests/

# Run with coverage
uv run pytest packages/afm-langchain/tests/ --cov=afm_langchain

Code Quality

# Format code
uv run ruff format

# Lint code
uv run ruff check

Project Structure

packages/afm-langchain/src/afm_langchain/
├── __init__.py
├── backend.py          # LangChainRunner implementation
├── model_factory.py    # LLM provider factory
├── mcp_manager.py      # MCP tool management
└── tools_adapter.py    # Tool calling adapter

Usage

The LangChain backend is automatically registered and used when you run an AFM agent:

from afm.runner import get_runner

# Get the LangChain runner
runner = get_runner("langchain")

# Run an agent
result = await runner.run(agent, user_input)

Documentation

For comprehensive documentation, see the project README.

License

Apache-2.0

Metadata

Release files for afm-langchain 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for afm-langchain 0.3.0
File Size Uploaded Provenance Actions
afm_langchain-0.3.0.tar.gz 8.9 kB Without provenance Details for afm_langchain-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for afm-langchain 0.3.0
File Interpreter ABI Platform Actions
afm_langchain-0.3.0-py3-none-any.whl Python 3 none any Details for afm_langchain-0.3.0-py3-none-any.whl

Total release size: 22.6 kB

Release files / afm_langchain-0.3.0.tar.gz

Download URL afm_langchain-0.3.0.tar.gz
Size 8.9 kB
Tags Source
SHA-256 checksum
How to use checksums
24ba685e51245f48b285ace07c406d3932037c255601f377df281c003dca4b0c
BLAKE2b-256 checksum
How to use checksums
bf531ccae040e3dbd0fba0bede1f5d171efd9179306c7d3f8605a1f1d5d58112
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / afm_langchain-0.3.0-py3-none-any.whl

Download URL afm_langchain-0.3.0-py3-none-any.whl
Size 13.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
52d46b6e1d8fefae619f1d81e30d5ade88efa413efb0fe619aa0ba9e32493197
BLAKE2b-256 checksum
How to use checksums
491ac97bec7954fbee018dc98a75bb05832e3b75dae602f262eb2e1e80e61029
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.11.6 {"installer":{"name":"uv","version":"0.11.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for afm-langchain 0.3.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.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A 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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page