Skip to content

Instantly share code, notes, and snippets.

@achilliesbot
Created April 10, 2026 21:30
Show Gist options
  • Select an option

  • Save achilliesbot/180ce956722d11da9fd03b76516a2c3d to your computer and use it in GitHub Desktop.

Select an option

Save achilliesbot/180ce956722d11da9fd03b76516a2c3d to your computer and use it in GitHub Desktop.
EP AgentIAM — AgentKit Action Provider. Add pre-action risk scoring to any Coinbase AgentKit agent via x402 micropayments.
/**
* EP AgentIAM — AgentKit Action Provider
*
* Add pre-action risk scoring to any Coinbase AgentKit agent.
* Uses x402 USDC micropayments on Base — no API keys needed.
*
* Install: npm install @x402/fetch zod
*
* Usage:
* import { epActionProvider } from "./ep-agentkit-integration";
* const agent = new AgentKit({ actionProviders: [epActionProvider()] });
*/
import { z } from "zod";
import { customActionProvider } from "@coinbase/agentkit";
const EP_BASE = "https://achillesalpha.onrender.com";
// Schema definitions
const RiskCheckSchema = z.object({
action: z.string().describe("The action to risk-check (e.g., 'swap 500 USDC to ETH')"),
value: z.number().optional().describe("Dollar value of the action"),
agent_id: z.string().optional().describe("Your agent identifier"),
});
const FlowCoreSchema = z.object({
action: z.string().describe("The action to fully validate"),
value: z.number().optional().describe("Dollar value of the action"),
memory_hash: z.string().optional().describe("Hash of current agent memory state"),
agent_id: z.string().optional().describe("Your agent identifier"),
});
const MemGuardSchema = z.object({
memory_hash: z.string().describe("Hash of the memory state to verify"),
agent_id: z.string().optional().describe("Your agent identifier"),
});
// Helper: make x402 paid call
async function epCall(endpoint: string, body: Record<string, unknown>): Promise<string> {
try {
// For agents with x402 client:
// const { fetchWithPayment } = await import("@x402/fetch");
// const res = await fetchWithPayment(`${EP_BASE}${endpoint}`, {
// method: "POST",
// headers: { "Content-Type": "application/json" },
// body: JSON.stringify(body)
// }, { privateKey: process.env.PRIVATE_KEY });
// Direct call (for testing or when using AgentKit wallet for payment):
const res = await fetch(`${EP_BASE}${endpoint}`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
if (res.status === 402) {
const paymentHeader = res.headers.get("payment-required");
return `Payment required. x402 payment spec: ${paymentHeader ? "available in payment-required header" : "check response body"}. Use @x402/fetch for automatic payment.`;
}
const data = await res.json();
return JSON.stringify(data, null, 2);
} catch (error) {
return `EP call failed: ${error}`;
}
}
// Export the action provider
export const epActionProvider = () =>
customActionProvider([
{
name: "ep_risk_check",
description:
"Check the risk of an action before executing it. Returns a risk score (0-1), risk level, and recommendation. Use this BEFORE executing trades, transfers, or any high-value action. Costs $0.005 USDC via x402.",
schema: RiskCheckSchema,
invoke: async (args: z.infer<typeof RiskCheckSchema>) => {
return epCall("/x402/risk-check", {
agent_id: args.agent_id || "agentkit-agent",
action: args.action,
value: args.value || 0,
});
},
},
{
name: "ep_riskoracle",
description:
"Detailed pre-action risk scoring with multi-factor analysis. Use before trades, contract deployments, or large transfers. Returns risk score, factors, and proof hash. Costs $0.01 USDC via x402.",
schema: RiskCheckSchema,
invoke: async (args: z.infer<typeof RiskCheckSchema>) => {
return epCall("/x402/riskoracle", {
agent_id: args.agent_id || "agentkit-agent",
action: args.action,
value: args.value || 0,
});
},
},
{
name: "ep_flowcore",
description:
"Full security pipeline — runs risk scoring, execution integrity, memory verification, and tool security in one call. Use before critical operations. Costs $0.02 USDC via x402.",
schema: FlowCoreSchema,
invoke: async (args: z.infer<typeof FlowCoreSchema>) => {
return epCall("/x402/flowcore", {
agent_id: args.agent_id || "agentkit-agent",
action: args.action,
value: args.value || 0,
memory_hash: args.memory_hash,
});
},
},
{
name: "ep_memguard",
description:
"Verify agent memory state integrity. Detects drift, corruption, or unauthorized modifications. Use periodically to ensure memory hasn't been tampered with. Costs $0.01 USDC via x402.",
schema: MemGuardSchema,
invoke: async (args: z.infer<typeof MemGuardSchema>) => {
return epCall("/x402/memguard", {
agent_id: args.agent_id || "agentkit-agent",
memory_hash: args.memory_hash,
});
},
},
]);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment