SDK & framework integrations

Drop-in shims route an agent’s tool calls through kya evaluation in-process (inside the agent’s own process): no gateway, no daemon, no network required. Evaluation uses the same path as kya wrap (offline sample evaluate by default; an explicit ResolvedConfig with a hosted plane is honored when passed). Every call (allowed, reviewed, or denied) lands on the local record (trail): see kya receipt. The SDK shims also honor KYA_SEND_PREVIEWS=0 for those local record fields (summary/targetPath/diffPreview are omitted). That is slightly stricter than kya wrap’s local record today, which records them regardless.

Decision semantics at the boundary:

Decision Behavior
ALLOW function runs, the record stores the call
REQUIRE_APPROVE observe semantics: function runs, the record stores the review (no Hold ticket in-process)
DENY function never runs: TS throws KyaDeniedError, Python raises KyaDenied

Tier 1: shipped adapters and shims

TypeScript (import { ... } from "@shield-agent/kya/sdk")

All adapters are structural: they take the framework’s tool shape and return the same shape with a gated execution path. No framework packages are imported; pass the tool object you already built. With server: "<id>", the evaluated toolId becomes <server>__<toolName> so the top-20 MCP taxonomy and the receipt’s server facet apply.

Framework Adapter Tool shape
LangGraph.js governLangGraphTool(tool, { server?, irreversible?, config? }) { name, description, schema, func }
Vercel AI SDK governVercelAiTool(tool, { name, server?, ... }) { description, parameters, execute }
Mastra governMastraTool(tool, { server?, ... }) { id, description, inputSchema, execute }
OpenAI Agents TS governOpenAiAgentsTool(tool, { server?, ... }) { name, description, parameters, invoke }
Claude Agent SDK governClaudeAgentTool(tool, { server?, ... }) { name, description, inputSchema, handler }

Anything not matching one of these shapes can use the core directly:

import { governed, KyaDeniedError } from "@shield-agent/kya/sdk";

const run = governed({
  toolId: "write_file",
  server: "filesystem",
  fn: (args) => fs.writeFile(args.path, args.content),
});
await run({ path: "out.txt", content: "hi" }); // throws KyaDeniedError on DENY

Runnable scripts per adapter live in examples/sdk/.

Python (PyPI shield-kya)

The shield-kya package on PyPI ships agent-wide hooks for LangChain / LangGraph, Pydantic AI, CrewAI, Google ADK, Microsoft Agent Framework and OpenAI Agents SDK. Install the extra for your framework, for example pip install 'shield-kya[langchain]'. The hooks follow the same rules as kya hook: advisory, fails open on errors (an error lets the call through), and the never-list still blocks. The Python recipes in Tier 1b pin shield-kya 0.17.0.

Tier 1b: framework recipes

Each recipe below runs a small agent with a scripted model (no API key). The check asserts three things: a never-list tool does not run, an allowed tool runs, and the trail holds one row per call. The Python recipes use the published shield-kya 0.17.0 package and the published kya CLI (0.32.7). The TypeScript recipes use the published @shield-agent/kya 0.32.7 in-process. CI runs all six.

LangChain (Python)

from langchain.agents import create_agent
from shield_kya.integrations.langchain import KyaMiddleware

agent = create_agent(model, tools, middleware=[KyaMiddleware()])

DENY: the tool is skipped. The model gets an error tool message with the reason. Install the shield-kya package with the langchain extra.

OpenAI Agents SDK (Python)

from shield_kya.integrations.openai_agents import attach

agent = attach(agent)  # one KYA tool input guardrail per function tool

DENY: the tool output is the KYA reason, and the run continues.

CrewAI (Python)

from shield_kya.integrations import crewai as kya_crewai

kya_crewai.register()  # one global pre-tool hook for every crew in the process

DENY: the tool does not run. The model sees the reason and the crew continues.

LlamaIndex (Python)

No shipped adapter. Wrap each tool function with shield_kya.decide() before you build the FunctionTool. A DENY returns the reason as the tool output, and the function does not run.

import shield_kya
from llama_index.core.tools import FunctionTool

def gated(name, fn):
    def run(**kwargs):
        decision = shield_kya.decide(name, kwargs)
        return fn(**kwargs) if decision.allowed else decision.reason
    return FunctionTool.from_defaults(fn=run, name=name, description=fn.__doc__)

Mastra (TypeScript)

import { governMastraTool } from "@shield-agent/kya/sdk";

tools: { postgres__drop_table: governMastraTool(dropTable) }

DENY: KyaDeniedError is thrown before execute runs.

Vercel AI SDK (TypeScript)

import { governVercelAiTool } from "@shield-agent/kya/sdk";

const tools = {
  postgres__drop_table: governVercelAiTool(dropTable, { name: "postgres__drop_table" }),
};

DENY: the tool body does not run. The model gets the error as the tool result.

Tier 2: recipes (no shipped adapter)

The pattern is always the same: wrap the callable the framework invokes for a tool with governed() (TS) or the @governed decorator (Python) at the tool boundary, and let the framework see the same-shaped callable.

Agent-to-agent (A2A)

Two levels, complementary:

import { governA2aSend } from "@shield-agent/kya/sdk";

const gate = await governA2aSend({
  peerId: "payments-agent",
  peerUrl: "https://a2a.example/payments",
  action: "refund",
  payloadSummary: "refund $42 to customer 9182",
  irreversible: true,
});
if (!gate.allow) throw new Error(`A2A blocked: ${gate.verdict}`);
// … perform the send