agentleFS
dhruvanbhalaradhruvanbhalara/skills/skills/dart/dart-genkit/SKILL.md

dart-genkit

Skill30 starsChanged 9 months agoMITView on GitHub

Use when building AI workflows, tool calling agents, structured outputs, or LLM pipelines using the Genkit Dart SDK.

  • Reads credentials

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Add the Genkit package to your Dart project's pubspec.yaml:

    line 25
  2. Very specific:

    Exhaustive Schema Definitions: Always define explicit inputSchema and outputSchema for tools and flows to ensure the LLM generates …

    line 138
  3. Distinctive:

    Environment Isolation: Do not hardcode API keys. Use environment variables or secure credential storage.

    line 139

≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

AI Engineering with Genkit Dart

Build structured, type-safe, and observable AI-powered workflows and agents using the Genkit Dart SDK.

Contents

  • Project Setup
  • Defining Prompts & Models
  • Creating Custom Tools
  • Orchestrating Flows
  • Best Practices

Project Setup

  1. Add the Genkit package to your Dart project's pubspec.yaml:
    dependencies:
      genkit: ^0.1.0-preview  # Replace with the latest version
      google_generative_ai: ^0.4.0
  2. Set up your API credentials (e.g., Gemini API key) in your environment:
    export GEMINI_API_KEY="your_api_key_here"

Defining Prompts & Models

Genkit separates model invocation and prompt structure from core application logic using structured prompts.

import 'package:genkit/genkit.dart';
import 'package:google_generative_ai/google_generative_ai.dart';

void main() async {
  // Initialize Genkit
  final ai = Genkit(
    model: 'gemini-1.5-flash',
    apiKey: String.fromEnvironment('GEMINI_API_KEY'),
  );

  // Invoke the model with a simple prompt
  final response = await ai.generate(
    prompt: 'Explain the concept of monads in Dart.',
  );
  
  print(response.text);
}

Creating Custom Tools

Genkit agents utilize Tools to execute tasks (e.g., database queries, web scraping, mathematical calculations).

import 'package:genkit/genkit.dart';

// 1. Define schemas for input and output
final additionInputSchema = Schema.object({
  'a': Schema.number(description: 'First number'),
  'b': Schema.number(description: 'Second number'),
});

// 2. Define the tool
final addTool = ai.defineTool(
  name: 'addNumbers',
  description: 'Adds two numbers together.',
  inputSchema: additionInputSchema,
  action: (input) async {
    final a = input['a'] as num;
    final b = input['b'] as num;
    return {'result': a + b};
  },
);

Orchestrating Flows

Flows are executable pipelines that support structured input and output schemas, built-in telemetry, and error handling.

import 'package:genkit/genkit.dart';

// Define the input and output schemas
final jokeRequestSchema = Schema.object({
  'topic': Schema.string(description: 'The topic for the joke'),
});

final jokeResponseSchema = Schema.object({
  'setup': Schema.string(),
  'punchline': Schema.string(),
});

// Define the Flow
final jokeFlow = ai.defineFlow(
  name: 'jokeFlow',
  inputSchema: jokeRequestSchema,
  outputSchema: jokeResponseSchema,
  action: (input) async {
    final topic = input['topic'] as String;
    
    final response = await ai.generate(
      prompt: 'Tell me a structured joke about $topic.',
      responseSchema: jokeResponseSchema,
    );
    
    return response.structuredOutput!;
  },
);

void main() async {
  // Run the flow
  final result = await jokeFlow.run({'topic': 'coding'});
  print('Setup: ${result['setup']}');
  print('Punchline: ${result['punchline']}');
}

Best Practices

  • Exhaustive Schema Definitions: Always define explicit inputSchema and outputSchema for tools and flows to ensure the LLM generates correctly structured arguments.
  • Environment Isolation: Do not hardcode API keys. Use environment variables or secure credential storage.
  • Trace Observability: Enable Genkit's trace observability in development to inspect agent decision trees and tool invocations.
  • Error Handling: Wrap tool execution in standard try-catch blocks and return error details gracefully so the agent can self-correct.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.