一键导入
dart-genkit
Guide for utilizing the Genkit Dart SDK to build full-stack, AI-powered agentic applications.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
Guide for utilizing the Genkit Dart SDK to build full-stack, AI-powered agentic applications.
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
| name | dart-genkit |
| description | Guide for utilizing the Genkit Dart SDK to build full-stack, AI-powered agentic applications. |
| metadata | {"platforms":"dart","languages":"dart","category":"ai"} |
Build structured, type-safe, and observable AI-powered workflows and agents using the Genkit Dart SDK.
pubspec.yaml:
dependencies:
genkit: ^0.1.0-preview # Replace with the latest version
google_generative_ai: ^0.4.0
export GEMINI_API_KEY="your_api_key_here"
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);
}
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};
},
);
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']}');
}
inputSchema and outputSchema for tools and flows to ensure the LLM generates correctly structured arguments.try-catch blocks and return error details gracefully so the agent can self-correct.Audit and rewrite project changelogs to adhere strictly to Keep a Changelog and Semantic Versioning standards. Use when reviewing, drafting, or refining project changelogs.
Guide for utilizing Dart 3.0+ up to 3.12 syntax updates (private named parameters, extension types, records, pattern matching, wildcard variables, and primary constructors).
Optimize Dart code for performance, type safety, and runtime error prevention. Use when profiling hot paths, enforcing sound typing, handling null safety, or debugging type mismatches and runtime failures.
Run Dart tooling workflows for static analysis, dependency conflict resolution, and test migration to package:checks. Use when fixing analyzer errors, resolving pub dependency conflicts, or modernizing test assertions.
Configure and run integration tests using the integration_test package with Flutter Driver. Use when testing complete user flows, verifying navigation, or running end-to-end tests on devices or CI.
Configure app flavors (dev, staging, prod) with environment-specific settings via dart-define-from-file. Use when setting up build variants, per-flavor Firebase projects, or platform-specific configuration.