LangChain and LangGraph Integration

LangChain and LangGraph are among the most widely used agent frameworks. The managed-agents package wraps governance around every tool call your chain or graph makes — evaluated before execution, recorded in your audit trail.

Installation

pip install managed-agents

LangChain — governing tool calls

Create a harness with platform="langchain" and call govern() inside each tool’s _run method before the tool logic executes:

python

from managed_agents import NomoticHarness, GovernanceDenied
from langchain.tools import BaseTool

harness = NomoticHarness(
    api_key="nm_live_...",
    agent_id="nmc-...",
    platform="langchain",
)

class GovernedSearchTool(BaseTool):
    name = "web_search"
    description = "Search the web for information"

    async def _arun(self, query: str) -> str:
        await harness.govern("web_search", {"query": query})
        return await self.perform_search(query)

    def _run(self, query: str) -> str:
        import asyncio
        asyncio.run(harness.govern("web_search", {"query": query}))
        return self.perform_search(query)

LangGraph — governing node execution

For LangGraph, govern at the node level before the node logic runs:

python

from managed_agents import NomoticHarness, GovernanceDenied

harness = NomoticHarness(
    api_key="nm_live_...",
    agent_id="nmc-...",
    platform="langchain",
)

async def governed_node(state: dict) -> dict:
    try:
        await harness.govern(
            state["action_type"],
            state.get("parameters", {})
        )
    except GovernanceDenied as e:
        state["blocked"]       = True
        state["denial_reason"] = str(e)
        return state

    return await your_node_logic(state)

Handling verdicts

By default, DENY raises GovernanceDenied and ESCALATE routes to your human review queue without blocking. To block on escalation as well:

python

harness = NomoticHarness(
    api_key="nm_live_...",
    agent_id="nmc-...",
    platform="langchain",
    block_on_escalate=True,
)

What gets governed

Every tool call and node execution that goes through harness.govern() is scored across 20 dimensions, assigned a verdict, and recorded in your audit trail. The platform="langchain" tag lets you filter these evaluations in Governance → Audit Trail.

Was this article helpful?

On this page