Skip to main content

LangChain integration layer for the Ape AI-first programming language

Reason this release was yanked:

Wrong Author name

Project description

ape-langchain

LangChain integration layer for the Ape AI-first programming language

License: MIT Python 3.11+

What is this?

ape-langchain bridges the Ape programming language with LangChain, enabling you to:

  • Use Ape tasks as LangChain tools with deterministic execution
  • Eliminate AI hallucination in tool invocation through strict validation
  • Build reliable AI agents with formally defined, constraint-validated workflows

Ape is a deterministic AI-first language designed to remove ambiguity from AI-generated code. ape-langchain makes Ape tasks seamlessly callable from LangChain agents.

Installation

pip install ape-langchain

This will automatically install ape-lang and langchain as dependencies.

Quick Start

1. Write an Ape Task

Create pricing.ape:

task calculate_total_price
  inputs:
    base_price: String
    tax_rate: String
  outputs:
    total: String
  constraints:
    - base_price must be numeric
    - tax_rate must be between 0 and 1
  steps:
    - Parse base_price as decimal
    - Multiply by (1 + tax_rate)
    - Return as string

2. Use it in LangChain

from ape_langchain import ApeTool
from langchain.agents import initialize_agent, AgentType
from langchain.llms import OpenAI

# Wrap Ape task as LangChain tool
pricing_tool = ApeTool(
    ape_file="pricing.ape",
    function="calculate_total_price",
    description="Calculate total price with tax"
)

# Create agent with deterministic tool
llm = OpenAI(temperature=0)
agent = initialize_agent(
    tools=[pricing_tool],
    llm=llm,
    agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
    verbose=True
)

# Execute - AI decides when to call, but execution is deterministic
result = agent.run("What's the total for $99.99 with 21% tax?")
print(result)

3. Or Use ApeChain Directly

For simpler workflows without full agent orchestration:

from ape_langchain import ApeChain

chain = ApeChain.from_ape_file("pricing.ape", function="calculate_total_price")

result = chain.run(base_price="99.99", tax_rate="0.21")
print(result)  # Deterministic, validated output

Why Use This?

Problem: AI Tool Invocation is Unreliable

# Traditional approach - AI can hallucinate parameters, miss constraints
def calculate_price(base, tax):
    return base * (1 + tax)  # What if base is negative? What if tax > 1?

Solution: Ape + LangChain

# Ape approach - constraints enforced, no ambiguity
pricing_tool = ApeTool("pricing.ape", "calculate_total_price")
# - Input validation automatic
# - Constraints checked before execution
# - No hallucination possible

API Overview

ApeTool

LangChain BaseTool adapter for Ape tasks.

from ape_langchain import ApeTool

tool = ApeTool(
    ape_file="path/to/module.ape",
    function="task_name",
    description="Optional description for LLM"
)

# Use in LangChain agents
agent = initialize_agent(tools=[tool], llm=llm, ...)

ApeChain

High-level wrapper for direct execution.

from ape_langchain import ApeChain

chain = ApeChain.from_ape_file("module.ape", function="task_name")
result = chain.run(param1="value", param2="value")

ApeTask

Low-level task representation with JSON Schema export.

from ape_langchain import ApeTask
from ape import compile

module = compile("module.ape")
task = ApeTask.from_module(module, "task_name")

# Get JSON Schema for OpenAI/Anthropic function calling
schema = task.to_json_schema()

Features

  • Deterministic execution - Ape constraints prevent invalid inputs
  • Type-safe - Full type checking before execution
  • LangChain native - Works with all LangChain agent types
  • JSON Schema export - Compatible with OpenAI/Anthropic function calling
  • Error handling - Clear exception types for debugging

Requirements

  • Python 3.11+
  • ape-lang >=0.2.0
  • langchain >=0.1.0

Development Status

v0.1.0 - Initial release

Currently supports:

  • Basic Ape task wrapping
  • LangChain tool integration
  • Simple type mapping (all parameters as strings for now)

Roadmap:

  • Advanced type system (int, float, list, dict)
  • Async execution support
  • Multi-task orchestration
  • Native Ape control flow support

Contributing

Contributions welcome! See the main Ape repository for guidelines.

License

MIT License - see LICENSE file for details.

Links


Built with Ape 🦍 - Because AI should execute deterministically, not approximately.

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

ape_langchain-0.1.1.tar.gz (14.0 kB view details)

Uploaded Source

Built Distribution

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

ape_langchain-0.1.1-py3-none-any.whl (11.6 kB view details)

Uploaded Python 3

File details

Details for the file ape_langchain-0.1.1.tar.gz.

File metadata

  • Download URL: ape_langchain-0.1.1.tar.gz
  • Upload date:
  • Size: 14.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for ape_langchain-0.1.1.tar.gz
Algorithm Hash digest
SHA256 135a88d4762b22dcc670d587cacae065cc3fbddaaf386fd8678d2d3bb63eff3d
MD5 3a775e1a479e4522df8dbda1fce5d45c
BLAKE2b-256 0423d9bf58018165c7f78435a052415c16c477bef0e78a1a8e8a0ce615f5c423

See more details on using hashes here.

File details

Details for the file ape_langchain-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: ape_langchain-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 11.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.9

File hashes

Hashes for ape_langchain-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 65b8418486ee0e9d06dcceac44f9293d33771d4d727f562768b9e41235561390
MD5 e9a16ea9819cefc616571e47607ccbe2
BLAKE2b-256 931190ce17a85ec6d1082d09abb7d68684ef59a2663815434f50c8e5243e5375

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