Skip to main content

AFM LangChain execution backend

Project description

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

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

afm_langchain-0.2.0.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

afm_langchain-0.2.0-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file afm_langchain-0.2.0.tar.gz.

File metadata

  • Download URL: afm_langchain-0.2.0.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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}

File hashes

Hashes for afm_langchain-0.2.0.tar.gz
Algorithm Hash digest
SHA256 4efc01184bd34af47ecb0ccb998779e24821ddb9f1efffef5c0a3265abcbae32
MD5 2b9489b9b8cdd40971314b5f3cc8ceb2
BLAKE2b-256 be52556b0a09ba10d2b454b1ddf733befcb174a5f31431f4001c8debcff54ba1

See more details on using hashes here.

File details

Details for the file afm_langchain-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: afm_langchain-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.7 {"installer":{"name":"uv","version":"0.10.7","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}

File hashes

Hashes for afm_langchain-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1ebf4f5a9756e3d91e6b2e2ab546be94d9d23bb0b216f6767f138651f8179a8b
MD5 82b1e920f483c65e7390e4544a11b0e6
BLAKE2b-256 948436ae5ec58f0daab17e2b1e29db1d0f7b2c0d040113712f9d6d3720a40744

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