Skip to content

Codex-Backed LangChain Graph

Source:

This example demonstrates the helper-to-adapter path for LangChain:

  • codex-auth-helper builds a Codex-backed ChatOpenAI
  • langchain.agents.create_agent(...) owns the graph
  • langchain-acp exposes that graph through ACP

The model factory call must pass instructions= explicitly:

model = create_codex_chat_openai(
    "gpt-5.4",
    instructions="You are a helpful coding assistant.",
)

Run it:

uv run python -m examples.langchain.codex_graph

Required local state:

~/.codex/auth.json

Override the default model when needed:

CODEX_MODEL=gpt-5.4-mini uv run python -m examples.langchain.codex_graph

If you have not logged in yet:

codex login

Install the helper with LangChain support:

uv add "codex-auth-helper[langchain]"
pip install "codex-auth-helper[langchain]"