langchain-idemcore
LangChain chat model for the Idemcore API. Every answer
comes with a signed, independently verifiable, bit-exact receipt, stored on
AIMessage.response_metadata.
Install guide: https://idemcore.net/integrations/langchain
Install
pip install langchain-idemcore
export IDEMCORE_API_KEY=ick_...
Requires idemcore>=0.3.1 (r2 receipts). Optional: pip install "langchain-idemcore[verify]" adds the open verifier idemcore-verify>=0.4.0 to check format v2 logs.
Quickstart
from langchain_core.messages import HumanMessage
from langchain_idemcore import ChatIdemcore, IdemcoreReceiptHandler, verify_langchain_receipt
llm = ChatIdemcore(model="your-model-id", max_tokens=64)
handler = IdemcoreReceiptHandler()
msg = llm.invoke(
[HumanMessage(content="Name the three primary colours.")],
config={"callbacks": [handler]},
)
print(msg.content)
print(msg.response_metadata["receipt_id"]) # rcpt_...
print(handler.to_jsonl())
# Local check of the signed receipt (and of a public token log, if you have one):
# bundle = verify_langchain_receipt(msg, log_text=log_text)
# print(bundle.ok, bundle.verification.levels)
Streaming works the same way: text arrives in chunks, and the receipt is
attached to a later chunk's response_metadata once the answer is complete.
Merging the AIMessageChunks (or using IdemcoreReceiptHandler) preserves it.
for chunk in llm.stream([HumanMessage(content="Write one short sentence.")]):
print(chunk.content, end="")
Tool calling
Since 0.1.3, bind_tools sends OpenAI-format tools to every hosted model.
Tool calls come back on AIMessage.tool_calls, and every answer, including
one that calls a tool, still carries a signed receipt.
from langchain_core.messages import HumanMessage, ToolMessage
from langchain_core.tools import tool
from langchain_idemcore import ChatIdemcore, verify_langchain_receipt
@tool
def get_weather(city: str) -> str:
"""Get the current weather for a city."""
return '{"city": "Hanoi", "temp_c": 24, "condition": "light rain"}'
llm = ChatIdemcore(model="qwen3.6-35b-a3b-idna", max_tokens=128).bind_tools([get_weather])
history = [HumanMessage(content="What is the weather in Hanoi right now?")]
ai = llm.invoke(history)
print(ai.tool_calls) # [{'name': 'get_weather', 'args': {'city': 'Hanoi'}, 'id': 'call_…', ...}]
history += [ai, ToolMessage(content=get_weather.invoke(ai.tool_calls[0]["args"]),
tool_call_id=ai.tool_calls[0]["id"])]
final = llm.invoke(history)
print(final.content)
print(verify_langchain_receipt(final).ok) # True
tool_choiceaccepts"auto","none","required"("any"orTruemean the same) or a tool name.- Streaming yields
tool_call_chunks; merged chunks givetool_calls, and the receipt arrives on the last chunk. - A call whose arguments are not valid JSON lands in
invalid_tool_calls. - In
automode a model may occasionally answer a live-data question itself instead of calling your tool. Usetool_choice="required"(or the tool name) when a call must happen.
Receipt metadata
AIMessage.response_metadata (and ChatResult.llm_output) contains:
receipt_id,receipt(the full signed r2 receipt)salt(forhash_onlyreceipts; store it with the conversation)privacy,model,finish_reason,id,usage- for requests sent with tools:
prompt_messages(the exact prompt the model saw, with the tool definitions) andoutput_token_ids; the verify helper uses them automatically
IdemcoreReceiptHandler collects those payloads for a whole run and can write
them as JSONL.
verify_langchain_receipt runs idemcore.verify_receipt (signature, optional
token-log chain, optional prompt/answer commitments). When log_text is
a format v2 log and the [verify] extra is installed, it also runs the open
idemcore-verify log check.
Sampling
Idemcore decoding is greedy: temperature is fixed at 0. Passing any other
temperature, or sampling settings such as top_p, top_k, penalties, seed,
n, or stop sequences, raises an error before a request is made. The legacy
functions / function_call API is not supported; use bind_tools.
max_tokens must be a whole number from 1 to 2048. privacy is hash_only
(default) or full. Auth is IDEMCORE_API_KEY (or api_key=). Billing is
measured server-side in tokens.
Tests
pip install -e ".[dev]"
pytest
Unit tests mock the SDK. A live smoke test runs only when IDEMCORE_API_KEY
is set in the environment.
Metadata
Release files for langchain-idemcore 0.1.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| langchain_idemcore-0.1.4.tar.gz | 18.9 kB | Without provenance | Details for langchain_idemcore-0.1.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| langchain_idemcore-0.1.4-py3-none-any.whl | Python 3 | none | any | Details for langchain_idemcore-0.1.4-py3-none-any.whl |
Total release size: 35.0 kB
Release files / langchain_idemcore-0.1.4.tar.gz
| Download URL | langchain_idemcore-0.1.4.tar.gz |
|---|---|
| Size | 18.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2b0421f08eed460d81ba25f5d3d32ab9b50c7ea3edf85923c43dfe0e564d6036
|
|
BLAKE2b-256 checksum How to use checksums |
0702f7cfa956491a9e9bbe2aff4c613b6ae1017540fef46b56c691a485348dda
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Release files / langchain_idemcore-0.1.4-py3-none-any.whl
| Download URL | langchain_idemcore-0.1.4-py3-none-any.whl |
|---|---|
| Size | 16.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
84e35c025b2892a9c5be574755fe0201c8a9be85d6a40f208e5cb95a4123987f
|
|
BLAKE2b-256 checksum How to use checksums |
3f45350f48d5b6cf04fc602eab8be78c5e35a7fcf25e485b60a4f32903ccf832
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.5
|
Security for langchain-idemcore 0.1.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.