Index of every page on this site: llms.txt
All skills
genkit-ai avatar

/developing-genkit-js

@d12c988
by Genkitgenkit-ai/skills40 stars
13
Run it yourself

Provides guidance on developing AI-powered applications using Genkit in Node.js/TypeScript. Use when the user asks about Genkit, AI agents, flows, or tools in JavaScript/TypeScript, or when encountering Genkit errors, validation issues, type errors, or API problems. Don't use for Genkit in Python, Go, or Dart.

Use this Skill: https://skilld.dev/gh/genkit-ai/skills/developing-genkit-js

Nothing lands on disk. Nothing to clean up.

Fork this Skill

Edit a local copy. It keeps the author and licence.

referencesagents-artifacts.md

≈963 tokens on demand. Your agent reads this file only when SKILL.md points to it.

Working with Artifacts (Beta)

Beta / preview API. The artifacts() middleware comes from @genkit-ai/middleware; the Artifact type from genkit/beta. Read agents.md first.

Artifacts are named, content-bearing deliverables an agent produces during a session — files, reports, code, etc. They live in the session (deduplicated by name) and are returned in res.artifacts / tracked on the client's chat.artifacts.


Give the model artifact tools

The artifacts() middleware (see using middleware) adds write_artifact and read_artifact tools and injects an <artifacts> listing into the system prompt each turn (names + sizes, not full content). No custom tool code needed.

import { artifacts } from '@genkit-ai/middleware';
import { ai } from './genkit.js';

export const workspaceAgent = ai.defineAgent({
  name: 'workspaceAgent',
  system: `You are a code generation assistant. Use write_artifact to create
files (pass the filename as "name" and the full content as "content"). Use
read_artifact to review or modify a previously created file.`,
  use: [artifacts()],
});

Run it; artifacts are produced via the tool and returned in the response:

const chat = workspaceAgent.chat();
const res = await chat.send('Write poem.txt with a poem about Genkit');
console.log(res.artifacts); // Artifact[]

Options:

  • readonly (default false): when true, only read_artifact is provided — the model can read but not create/update artifacts. Useful on an orchestrator that should review (but not produce) sub-agent artifacts.

The Artifact shape

import type { Artifact } from 'genkit/beta';

// An artifact's content lives in `parts` (text parts). `metadata` is optional.
const artifact: Artifact = {
  name: 'poem.txt',
  parts: [{ text: 'Roses are red…' }],
  metadata: { source: 'workspaceAgent' }, // optional
};

Writing the same name again replaces the artifact (dedup by name).

Programmatic access (inside tools and custom agents)

Use the active session. ai.currentSession() throws when there's no active session, so only call it inside an agent turn.

const session = ai.currentSession();

// Read all artifacts:
const all = session.getArtifacts(); // Artifact[]
const found = all.find((a) => a.name === 'poem.txt');

// Create / replace artifacts:
session.addArtifacts([{ name: 'notes.md', parts: [{ text: '# Notes' }] }]);

Reading artifacts on the client

The remoteAgent client tracks artifacts on chat.artifacts (and each response exposes res.artifacts):

import { remoteAgent } from 'genkit/beta/client';

const agent = remoteAgent({ url: '/api/workspaceAgent' });
const chat = agent.chat();
const res = await chat.send('Create index.html and styles.css');
console.log(res.artifacts); // Artifact[] produced this turn
console.log(chat.artifacts); // all artifacts tracked for the session

Sharing artifacts across agents

In multi-agent orchestration, set the agents() middleware's artifactStrategy: 'session' so sub-agent artifacts are merged into the parent session (namespaced by invocation ID), and add artifacts({ readonly: true }) to the orchestrator so it can read_artifact them:

use: [
  agents({ agents: ['researcher', 'coder'], artifactStrategy: 'session' }),
  artifacts({ readonly: true }),
];

Source: SKILL.md on GitHub

skilld matched fixed text patterns in SKILL.md and file names. Patterns miss obfuscated code.

skilld run checks every file with the same patterns. It asks for approval before it loads a Skill with a behavior marked Needs approval.

No alerts13d5 checks · Risk SAFE
  • Gen Agent Trust Hub14d

    The skill is a comprehensive development guide for the Genkit JS framework. It provides technical instructions, code examples, and troubleshooting steps. All referenced tools and packages are official or standard industry dependencies. No security risks were identified.

  • Socket13d

    No alerts

  • Snyk14d

    Risk: LOW · No issues

  • Runlayer8mo

    6 files scanned · No issues

  • ZeroLeaks7mo

    Score: 93/100 · 2 sections analyzed

Signed by skilld at d12c988. This ties the file your Agent reads to that commit on GitHub. It does not review the instructions.

Last checked against GitHub 4 days ago.

Activeupdated 2 weeks ago
metadata
{
  "version": "1.0.0",
  "category": "AiAndMachineLearning"
}
  • TypeScript
  • genkit
  • nodejs
  • ai-agents
  • flows
  • llm
  • google-ai
  • openai
  • anthropic

README badge

README badge for genkit-ai/skills/developing-genkit-js

Develop AI-powered applications using Genkit in Node.js and TypeScript, including flows, tools, and multi-model integrations. Covers Genkit CLI setup, flow definition with schema validation, provider selection (Google AI, OpenAI, Anthropic, Ollama), and error troubleshooting for version 1.29.0 and later.

Generated from the current SKILL.md.

What Genkit CLI version does this skill require?
Minimum CLI version 1.29.0. Verify with `genkit --version` and upgrade with `npm install -g genkit-cli@^1.29.0` if needed.
Does this skill cover pre-1.0 Genkit or older versions?
No. Genkit went through a major breaking API change. This skill assumes v1.x (1.29.0+) and will not reliably handle pre-1.0 code or deprecated APIs.
What AI providers does this skill support?
Genkit is provider-agnostic and supports Google AI, OpenAI, Anthropic, Ollama, and others. The skill defaults to Google AI if no provider is specified.
How should I troubleshoot Genkit errors?
Always read the Common Errors reference first to identify known patterns and their fixes. Use `genkit docs:search` only if the error is not documented there.
Does this skill work with Next.js, Firebase, or Express?
Yes. The skill detects your framework via package.json and adapts the implementation to framework-specific patterns like @genkit-ai/next or @genkit-ai/firebase.

Generated from the current SKILL.md. These answers refresh after source changes.