Skip to content

feat(examples): add Genkit Guard example - #201

Merged
davidmytton merged 5 commits into
mainfrom
david/cursor/genkit-agent-example
Sep 1, 2026
Merged

feat(examples): add Genkit Guard example#201
davidmytton merged 5 commits into
mainfrom
david/cursor/genkit-agent-example

Conversation

@davidmytton

Copy link
Copy Markdown
Collaborator

Adds examples/genkit-agent: a Genkit JS genkit() + ai.defineTool + ai.generate() support agent protected by Arcjet Guard, alongside mastra-agent / langgraph-agent / claude-agent. Registered in the root README and scripts/prepare-to-publish.ts.

This is JS Genkit only, not Go / Python. Import path is @arcjet/guard/genkit/v1@arcjet/guard/genkit does not resolve.

const lookupOrder = guardTool(
  arcjet,
  ai.defineTool(
    {
      name: "lookup_order",
      description: "Look up an order",
      inputSchema: z.object({ orderNumber: z.string(), note: z.string().optional() }),
    },
    async ({ orderNumber, note }) => ({ orderNumber, note, status: "shipped" }),
  ),
  {
    action: "order.looked-up",
    onGuardError: "deny",
    rules: (input) => [
      lookupLimit({ key: `order:${input.orderNumber}`, requested: 1 }),
      ...(input.note ? [detectPii(input.note)] : []),
    ],
  },
);

// Screen inbound before generate(). Middleware `model` is not Guard.
const decision = await arcjet.guard({
  label: "message.received",
  rules: [inbound(userText)],
  ...genkitContext({ context: appContext }),
});
if (decision.conclusion === "DENY" || decision.hasFailedOpen()) return blocked();

await ai.generate({
  prompt: userText,
  tools: [lookupOrder, notifyWarehouse],
  use: [guardMiddleware(arcjet, { sessionId: conversationId })],
  context: appContext,
});

guardTool wraps the returned ToolAction, not the inner handler, and overwrites the registry key. DENY is a completed toolResponse.output with arcjetDenied: true — it does not throw, call interrupt(), or set finishReason: "interrupted". guardMiddleware is a { name, instantiate } object whose tool hook gates unwrapped / MCP tools; branded tools are skipped. interrupt() / toolApproval is HITL, not a policy gate. Correlation is the browser-generated conversation id copied onto { sessionId } — never minted on the server.

Vendor pin. @arcjet/guard/genkit/v1 is not on main or npm. @arcjet/guard is pinned to file:./vendor/arcjet-guard built from arcjet-js david/cursor/guard-genkit-v1-8e4b at f7619e4c1c2a4f48a3342b7f8ab74a928ceb7309 (no PR number). SHA is in vendor/SOURCE.txt. Draft until that ships.

Verified. npm run typecheck passes. Node 24+, ARCJET_KEY + AI_GATEWAY_API_KEY.

Open in Web Open in Cursor 

cursoragent and others added 2 commits August 20, 2026 21:40
Vendors unpublished @arcjet/guard/genkit/v1 from
arcjet-js@f7619e4c1c2a4f48a3342b7f8ab74a928ceb7309
(david/cursor/guard-genkit-v1-8e4b). Shows inbound screening before
generate(), guardTool on lookup_order, and guardMiddleware on an
unwrapped tool.

Co-authored-by: David Mytton <davidmytton@users.noreply.github.com>
Drop extra comments, page diagnostics, and README sections so the
demo matches mastra-agent's shape.

Co-authored-by: David Mytton <davidmytton@users.noreply.github.com>
@davidmytton
davidmytton marked this pull request as ready for review August 25, 2026 20:36

@arcjet-review arcjet-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arcjet Review — 🔴 High Risk

Decision: Cannot Assess

Rationale: Review failed due to an internal error: unknown error. Escalating to human reviewers.

Review: c41f937c | Powered by Arcjet Review

@socket-security

socket-security Bot commented Aug 25, 2026

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addednpm/​@​genkit-ai/​compat-oai@​1.41.09910010099100
Addednpm/​genkit@​1.41.010010010099100

View full report

@socket-security

socket-security Bot commented Aug 25, 2026

Copy link
Copy Markdown

All alerts resolved. Learn more about Socket for GitHub.

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring alerts on:

  • npm/@genkit-ai/ai@1.41.0
  • npm/@genkit-ai/compat-oai@1.41.0
  • npm/@genkit-ai/core@1.41.0
  • npm/@genkit-ai/firebase@1.41.0
  • npm/@genkit-ai/google-cloud@1.41.0
  • npm/@google-cloud/common@6.1.0
  • npm/@google-cloud/logging@11.4.0
  • npm/@google-cloud/logging-api@0.2.0
  • npm/@google-cloud/logging-winston@6.0.2
  • npm/@google-cloud/modelarmor@0.4.1
  • npm/@google-cloud/opentelemetry-cloud-monitoring-exporter@0.19.0
  • npm/@google-cloud/opentelemetry-cloud-trace-exporter@2.4.1
  • npm/@google-cloud/opentelemetry-resource-util@2.4.0
  • npm/@opentelemetry/api-logs@0.52.1
  • npm/@opentelemetry/auto-instrumentations-node@0.49.2
  • npm/@opentelemetry/context-async-hooks@1.25.1
  • npm/@opentelemetry/exporter-trace-otlp-grpc@0.52.1
  • npm/@opentelemetry/exporter-trace-otlp-http@0.52.1
  • npm/@opentelemetry/exporter-trace-otlp-proto@0.52.1
  • npm/@opentelemetry/exporter-zipkin@1.25.1
  • npm/@opentelemetry/instrumentation@0.52.1
  • npm/@opentelemetry/instrumentation-amqplib@0.41.0
  • npm/@opentelemetry/instrumentation-aws-lambda@0.43.0
  • npm/@opentelemetry/instrumentation-aws-sdk@0.43.1
  • npm/@opentelemetry/instrumentation-bunyan@0.40.0
  • npm/@opentelemetry/instrumentation-cassandra-driver@0.40.0
  • npm/@opentelemetry/instrumentation-connect@0.38.0
  • npm/@opentelemetry/instrumentation-cucumber@0.8.0
  • npm/@opentelemetry/instrumentation-dataloader@0.11.0
  • npm/@opentelemetry/instrumentation-dns@0.38.0
  • npm/@opentelemetry/instrumentation-express@0.41.1
  • npm/@opentelemetry/instrumentation-fastify@0.38.0
  • npm/@opentelemetry/instrumentation-fs@0.14.0
  • npm/@opentelemetry/instrumentation-generic-pool@0.38.1
  • npm/@opentelemetry/instrumentation-graphql@0.42.0
  • npm/@opentelemetry/instrumentation-grpc@0.52.1
  • npm/@opentelemetry/instrumentation-hapi@0.40.0
  • npm/@opentelemetry/instrumentation-http@0.52.1
  • npm/@opentelemetry/instrumentation-ioredis@0.42.0
  • npm/@opentelemetry/instrumentation-kafkajs@0.2.0
  • npm/@opentelemetry/instrumentation-knex@0.39.0
  • npm/@opentelemetry/instrumentation-koa@0.42.0
  • npm/@opentelemetry/instrumentation-lru-memoizer@0.39.0
  • npm/@opentelemetry/instrumentation-memcached@0.38.0
  • npm/@opentelemetry/instrumentation-mongodb@0.46.0
  • npm/@opentelemetry/instrumentation-mongoose@0.41.0
  • npm/@opentelemetry/instrumentation-mysql@0.40.0
  • npm/@opentelemetry/instrumentation-mysql2@0.40.0
  • npm/@opentelemetry/instrumentation-nestjs-core@0.39.0
  • npm/@opentelemetry/instrumentation-net@0.38.0
  • npm/@opentelemetry/instrumentation-pg@0.43.0
  • npm/@opentelemetry/instrumentation-pino@0.41.0
  • npm/@opentelemetry/instrumentation-redis@0.41.0
  • npm/@opentelemetry/instrumentation-redis-4@0.41.1
  • npm/@opentelemetry/instrumentation-restify@0.40.0
  • npm/@opentelemetry/instrumentation-router@0.39.0
  • npm/@opentelemetry/instrumentation-socket.io@0.41.0
  • npm/@opentelemetry/instrumentation-tedious@0.13.0
  • npm/@opentelemetry/instrumentation-undici@0.5.0
  • npm/@opentelemetry/instrumentation-winston@0.39.0
  • npm/@opentelemetry/otlp-exporter-base@0.52.1
  • npm/@opentelemetry/otlp-grpc-exporter-base@0.52.1
  • npm/@opentelemetry/otlp-transformer@0.52.1
  • npm/@opentelemetry/propagation-utils@0.30.16
  • npm/@opentelemetry/propagator-aws-xray@1.26.2
  • npm/@opentelemetry/propagator-b3@1.25.1
  • npm/@opentelemetry/propagator-jaeger@1.25.1
  • npm/@opentelemetry/redis-common@0.36.2
  • npm/@opentelemetry/resource-detector-alibaba-cloud@0.29.7
  • npm/@opentelemetry/resource-detector-aws@1.12.0
  • npm/@opentelemetry/resource-detector-azure@0.2.12
  • npm/@opentelemetry/resource-detector-container@0.4.4
  • npm/@opentelemetry/resource-detector-gcp@0.29.13
  • npm/@opentelemetry/resources@1.25.1
  • npm/@opentelemetry/sdk-logs@0.52.1
  • npm/@opentelemetry/sdk-metrics@1.25.1
  • npm/@opentelemetry/sdk-node@0.52.1
  • npm/@opentelemetry/sdk-trace-base@1.25.1
  • npm/@opentelemetry/sdk-trace-node@1.25.1
  • npm/@opentelemetry/sql-common@0.40.1
  • npm/@tootallnate/once@2.0.1
  • npm/@types/aws-lambda@8.10.122
  • npm/@types/bunyan@1.8.9
  • npm/@types/memcached@2.2.10
  • npm/@types/mysql@2.15.22
  • npm/@types/pg@8.6.1
  • npm/@types/pg-pool@2.0.4
  • npm/@types/shimmer@1.2.0
  • npm/@types/tedious@4.0.14
  • npm/async-mutex@0.5.0
  • npm/dotprompt@1.1.2
  • npm/genkit@1.41.0
  • npm/googleapis@137.1.0
  • npm/import-in-the-middle@1.15.0
  • npm/lodash.mapvalues@4.6.0
  • npm/lodash.merge@4.6.2
  • npm/module-details-from-path@1.0.4
  • npm/partial-json@0.1.7
  • npm/pumpify@2.0.1
  • npm/require-in-the-middle@7.5.2
  • npm/shimmer@1.2.1
  • npm/uri-templates@0.2.0
  • npm/@types/node@20.19.43
  • npm/zod@3.25.76
  • npm/color-name@2.1.1
  • npm/dot-prop@6.0.1
  • npm/pump@3.0.4
  • npm/jose@6.2.10
  • npm/uuid@9.0.1
  • npm/uuid@10.0.0
  • npm/@types/connect@3.4.36
  • npm/@fastify/busboy@3.2.2
  • npm/@firebase/app-check-interop-types@0.3.5
  • npm/@firebase/app-types@0.9.6
  • npm/@firebase/auth-interop-types@0.2.6
  • npm/@firebase/component@0.7.5
  • npm/@firebase/database@1.1.5
  • npm/@firebase/database-compat@2.1.7
  • npm/@firebase/database-types@1.0.22
  • npm/@firebase/logger@0.5.2
  • npm/@firebase/util@1.15.3
  • npm/gaxios@7.3.1
  • npm/@google-cloud/firestore@8.7.1
  • npm/@google-cloud/precise-date@4.0.0
  • npm/google-auth-library@10.9.1
  • npm/google-gax@5.0.8
  • npm/retry-request@8.0.4
  • npm/teeny-request@10.1.4
  • npm/@google-cloud/storage@7.22.0
  • npm/gcp-metadata@8.1.4
  • npm/@opentelemetry/core@1.25.1
  • npm/@opentelemetry/semantic-conventions@1.25.1
  • npm/@opentelemetry/semantic-conventions@1.43.0
  • npm/cjs-module-lexer@1.4.3
  • npm/fast-xml-builder@1.3.1
  • npm/fast-xml-parser@5.11.1
  • npm/firebase-admin@14.3.0
  • npm/googleapis-common@7.2.0
  • npm/http-proxy-agent@5.0.0
  • npm/http-proxy-agent@7.0.2
  • npm/is-unsafe@2.0.2
  • npm/jwks-rsa@4.1.0
  • npm/lru-memoizer@3.0.0
  • npm/pg-protocol@1.16.0
  • npm/strnum@2.4.2
  • npm/openai@7.8.0

View full report

@davidmytton

Copy link
Copy Markdown
Collaborator Author

@SocketSecurity ignore npm/@types/pg@8.6.1

@davidmytton
davidmytton enabled auto-merge August 25, 2026 20:42
@davidmytton

Copy link
Copy Markdown
Collaborator Author

@SocketSecurity ignore-all

* deps(genkit-agent): override openai to 7.8.0

Socket blocks PR 201 on a medium "potential vulnerability" in
openai@4.104.0, pulled in by @genkit-ai/compat-oai@1.41.0.

genkit and @genkit-ai/compat-oai are already latest and still declare
openai@^4.95.0, so override the transitive pin to the current openai
release. The example uses non-streaming ai.generate(), which maps to
client.chat.completions.create — still present on 7.x.

Co-authored-by: David Mytton <davidmytton@users.noreply.github.com>

* docs: record genkit-agent openai override

Add OVERRIDES.md so the Socket pin on openai@4.104.0 is documented:
why we cannot bump Genkit, what 7.8.0 is compatible with, and when
to remove the override. Link it from CONTRIBUTING and the example
README.

Co-authored-by: David Mytton <davidmytton@users.noreply.github.com>

---------

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: David Mytton <davidmytton@users.noreply.github.com>
davidmytton and others added 2 commits August 31, 2026 09:57
@arcjet/guard@1.11.0 exports ./genkit/v1, so drop the vendored
build from david/cursor/guard-genkit-v1-8e4b. npm ci now installs
from the registry; Docker no longer copies vendor/.

Co-authored-by: Cursor Agent <cursoragent@cursor.com>
Co-authored-by: David Mytton <davidmytton@users.noreply.github.com>
Keep both the Genkit and LangChain agent listings in README.md and
scripts/prepare-to-publish.ts after #199 landed on main.

Co-authored-by: David Mytton <davidmytton@users.noreply.github.com>
@arcjet-review arcjet-review Bot added the needs review Awaiting human review label Aug 31, 2026
@davidmytton
davidmytton disabled auto-merge September 1, 2026 11:25
@davidmytton
davidmytton merged commit a3128ae into main Sep 1, 2026
23 checks passed
@arcjet-review arcjet-review Bot removed the needs review Awaiting human review label Sep 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants