# AgentGuard framework adapters

Thin adapters translate framework hook and middleware events into the shared AgentGuard Spend core. They do not proxy prompts, completions, provider keys, or signing keys.

## Vercel AI SDK

```ts
import { wrapLanguageModel } from 'ai';
import { agentguardAiSdkMiddleware } from '@agentguard-run/spend/frameworks/vercel-ai';

const governed = wrapLanguageModel({
  model,
  middleware: agentguardAiSdkMiddleware({ policy, scope }),
});
```

## Claude Code hooks

```ts
import { createClaudeCodeHooks } from '@agentguard-run/spend/frameworks/claude-code';

const hooks = createClaudeCodeHooks({ policy, scope });
await hooks.handleHookInput(JSON.parse(process.env.CLAUDE_HOOK_INPUT || '{}'));
```

## Hermes

```ts
import { createHermesPlugin } from '@agentguard-run/spend/frameworks/hermes';

export default createHermesPlugin({ policy, scope });
```

## OpenRouter

```ts
import OpenAI from 'openai';
import { withSpendGuardOpenRouter } from '@agentguard-run/spend/frameworks/openrouter';

const client = withSpendGuardOpenRouter(new OpenAI({
  baseURL: 'https://openrouter.ai/api/v1',
  apiKey: process.env.OPENROUTER_API_KEY,
}), { policy, scope });
```

## OpenAI SDK / OpenAI Agents SDK

Hook point: the OpenAI client's `chat.completions.create`. Wrap the client once
and every call the agent runner makes is governed.

```ts
import OpenAI from 'openai';
import { withSpendGuardOpenAI } from '@agentguard-run/spend/frameworks/openai';

const client = withSpendGuardOpenAI(new OpenAI(), { policy, scope });
```

```ts
// OpenAI Agents SDK — govern every model call the agent makes
import OpenAI from 'openai';
import { run, Agent, setDefaultOpenAIClient } from '@openai/agents';
import { withSpendGuardOpenAI } from '@agentguard-run/spend/frameworks/openai';

setDefaultOpenAIClient(withSpendGuardOpenAI(new OpenAI(), { policy, scope }));
```

## LangChain (JS)

Hook point: LangChain's `BaseCallbackHandler` lifecycle
(`handleChatModelStart` / `handleLLMStart` preflight `guard.decide()`,
`handleLLMEnd` settles real token usage). A blocked call throws
`AgentGuardBlockedError`.

```ts
import { ChatOpenAI } from '@langchain/openai';
import { createLangChainHandler } from '@agentguard-run/spend/frameworks/langchain';

const llm = new ChatOpenAI({ callbacks: [createLangChainHandler({ policy, scope })] });
```
