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.3.0.tar.gz (8.9 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.3.0-py3-none-any.whl (13.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: afm_langchain-0.3.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using 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}

File hashes

Hashes for afm_langchain-0.3.0.tar.gz
Algorithm Hash digest
SHA256 24ba685e51245f48b285ace07c406d3932037c255601f377df281c003dca4b0c
MD5 ca3c384523384f0df2302e71cae14999
BLAKE2b-256 bf531ccae040e3dbd0fba0bede1f5d171efd9179306c7d3f8605a1f1d5d58112

See more details on using hashes here.

File details

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

File metadata

  • Download URL: afm_langchain-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 13.8 kB
  • Tags: Python 3
  • Uploaded using 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}

File hashes

Hashes for afm_langchain-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 52d46b6e1d8fefae619f1d81e30d5ade88efa413efb0fe619aa0ba9e32493197
MD5 f00fef8cb47b9b5a320ad93245b48a93
BLAKE2b-256 491ac97bec7954fbee018dc98a75bb05832e3b75dae602f262eb2e1e80e61029

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