LangChain Integration

The LangChain runner wraps any LangChain Runnable (chains, AgentExecutor, LangGraph graphs) with ACE learning. The runner extracts execution traces and learns strategies from them.

Installation

uv add ace-framework[langchain]

Quick Start

from ace import LangChain

runner = LangChain.from_model(your_chain, ace_model="gpt-4o-mini")

results = runner.run([
    {"input": "Summarize this document"},
    {"input": "Extract key entities"},
])

runner.save("chain_expert.json")

Parameters

from_model()

ParameterTypeDefaultDescription
runnableAnyLangChain Runnable (chain, AgentExecutor, graph)
ace_modelstr"gpt-4o-mini"Model for Reflector + SkillManager
ace_max_tokensint2048Max tokens for ACE LLM responses
ace_temperaturefloat0.0Sampling temperature for ACE roles

from_roles()

ParameterTypeDefaultDescription
runnableAnyLangChain Runnable
reflectorReflectorLikeReflector instance
skill_managerSkillManagerLikeSkillManager instance
skillbook_pathstrNoneLoad saved skillbook
output_parserCallableNoneCustom output extraction
dedup_configDeduplicationConfigNoneDeduplication config
checkpoint_dirstrNoneCheckpoint directory

Methods

results = runner.run(inputs, epochs=1)      # Run with learning
results = runner.invoke(single_input)       # Single input convenience
runner.save("path.json")                    # Save skillbook
runner.wait_for_background()                # Wait for async learning

How It Works

  1. INJECT — Skillbook strategies are added to the chain input
  2. EXECUTE — LangChain runs the chain normally
  3. Extract trace — ACE extracts intermediate steps, tool calls, and reasoning
  4. LEARN — Reflector analyzes the trace, SkillManager updates the skillbook

The runner handles simple chains, AgentExecutor (with intermediate_steps), and LangGraph graphs automatically.

Input Types

The runner accepts any input your chain expects:

# String input
runner.run(["What is ACE?"])

# Dict input
runner.run([{"input": "query", "context": "..."}])

# Message list
runner.run([[HumanMessage(content="Hello")]])

Resuming from a Saved Skillbook

runner = LangChain.from_model(
    your_chain,
    ace_model="gpt-4o-mini",
    skillbook_path="chain_expert.json",
)

What to Read Next