26382a7ac6
CI / Clippy (push) Failing after 15m13s
CI / Test (ubuntu-latest) (push) Failing after 16m1s
CI / Test (macos-latest) (push) Has been cancelled
CI / Test (windows-latest) (push) Has been cancelled
CI / Build (no embeddings / no ORT) (push) Has been cancelled
CI / Format (push) Has been cancelled
CI / Cookbook (Node) (push) Has been cancelled
CI / Pi Extension (Node) (push) Has been cancelled
CI / Rust SDK (lean-ctx-client) (push) Has been cancelled
CI / Embed SDK (lean-ctx-sdk) (push) Has been cancelled
CI / Python SDK (leanctx) (push) Has been cancelled
CI / Hermes Plugin (Python) (push) Has been cancelled
CI / SDK Conformance Matrix (push) Has been cancelled
CI / Coverage (push) Has been cancelled
CI / cargo-deny (push) Has been cancelled
CI / Adversarial Safety (push) Has been cancelled
CI / Benchmarks (push) Has been cancelled
CI / Output-Quality Gate (eval A/B) (push) Has been cancelled
CI / Documentation (push) Has been cancelled
CI / CI Green (push) Has been cancelled
JetBrains Plugin / Actionlint (push) Has been cancelled
CodeQL / Analyze (actions) (push) Has been cancelled
CodeQL / Analyze (javascript-typescript) (push) Has been cancelled
CodeQL / Analyze (rust) (push) Has been cancelled
JetBrains Plugin / Validation (push) Has been cancelled
JetBrains Plugin / Build (push) Has been cancelled
JetBrains Plugin / Test (push) Has been cancelled
Security Check / Security Scan (push) Has been cancelled
37 lines
1.2 KiB
Python
37 lines
1.2 KiB
Python
"""LangChain adapter (EPIC 12.6).
|
|
|
|
Exposes lean-ctx tools as LangChain `Tool`s. The framework is an optional
|
|
dependency, imported lazily so the SDK has no hard coupling.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from typing import Any, List
|
|
|
|
from ..client import LeanCtxClient
|
|
from ._common import make_json_runner, normalized_tool_specs
|
|
|
|
|
|
def to_langchain_tools(client: LeanCtxClient) -> List[Any]:
|
|
"""Return lean-ctx tools as `langchain_core.tools.Tool` instances.
|
|
|
|
Each tool accepts a JSON object string of arguments — the most portable
|
|
shape across LangChain versions.
|
|
"""
|
|
try:
|
|
from langchain_core.tools import Tool
|
|
except ImportError as exc: # pragma: no cover - exercised only without dep
|
|
raise ImportError(
|
|
"LangChain is required for this adapter: pip install langchain-core"
|
|
) from exc
|
|
|
|
tools: List[Any] = []
|
|
for spec in normalized_tool_specs(client):
|
|
runner = make_json_runner(client, spec.name)
|
|
description = (
|
|
f"{spec.description} "
|
|
"Input: a JSON object string matching this tool's argument schema."
|
|
).strip()
|
|
tools.append(Tool(name=spec.name, description=description, func=runner))
|
|
return tools
|