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

/developing-genkit-go

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

Provides guidance on developing AI-powered applications using Genkit in Go. Use when the user asks to build AI features, agents, flows, or tools in Go using Genkit, or when working with Genkit Go code involving generation, prompts, streaming, tool calling, or model providers. Don't use for Genkit in JavaScript/TypeScript, Python, or Dart.

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

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencesagents-artifacts.md

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

Working with Artifacts (Experimental)

Experimental / preview API. The Artifacts middleware comes from plugins/middleware/exp; the Artifact type from ai/exp. 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 on out.Artifacts.

import (
	aix "github.com/firebase/genkit/go/ai/exp"
	middlewarex "github.com/firebase/genkit/go/plugins/middleware/exp"
)

Give the model artifact tools

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

workspaceAgent := genkitx.DefineAgent[any](g, "workspaceAgent",
	aix.InlinePrompt{
		ai.WithModelName("googleai/gemini-flash-latest"),
		ai.WithSystem(`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.`),
		ai.WithUse(&middlewarex.Artifacts{}),
	},
)

No session store is needed to produce artifacts — they are returned on out.Artifacts either way (this agent is client-managed, hence the explicit [any] type parameter). Add a store (e.g. localstore.NewFileSessionStore) only when artifacts should persist across turns or sessions. See sessions.

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

out, _ := workspaceAgent.RunText(ctx, "Write poem.txt with a poem about Genkit")
for _, a := range out.Artifacts {
	fmt.Println(a.Name)
}

middlewarex.Artifacts option:

  • 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.
ai.WithUse(&middlewarex.Artifacts{Readonly: true})

The Artifact shape

// An artifact's content lives in Parts (text/media parts). Metadata is optional.
artifact := &aix.Artifact{
	Name:     "poem.txt",
	Parts:    []*ai.Part{ai.NewTextPart("Roses are red…")},
	Metadata: map[string]any{"source": "workspaceAgent"}, // optional
}

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

Programmatic access (inside tools and custom agents)

Use the session's artifact store. aix.ArtifactStoreFromContext(ctx) returns a State-agnostic view (so tools don't need to know the agent's State type), or nil when there is no active session.

store := aix.ArtifactStoreFromContext(ctx)
if store == nil {
	// not inside an agent session
}

// Read all artifacts:
for _, a := range store.Artifacts() {
	if a.Name == "poem.txt" {
		// ...
	}
}

// Create / replace artifacts:
store.AddArtifacts(&aix.Artifact{
	Name:  "notes.md",
	Parts: []*ai.Part{ai.NewTextPart("# Notes")},
})

From a custom agent you can also stream an artifact to the client with resp.SendArtifact(a), which forwards it and adds it to the session in one call.

Sharing artifacts across agents

In multi-agent orchestration, set the Agents middleware's ArtifactStrategy: middlewarex.ArtifactStrategySession so sub-agent artifacts are merged into the parent session (namespaced by invocation ID), and add &middlewarex.Artifacts{Readonly: true} to the orchestrator so it can read_artifact them:

ai.WithUse(
	&middlewarex.Agents{
		Agents:           []aix.AgentRef{{Name: "researcher"}, {Name: "coder"}},
		ArtifactStrategy: middlewarex.ArtifactStrategySession,
	},
	&middlewarex.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.

1 warning2d3 checks · Risk SAFE
  • Gen Agent Trust Hub3d

    The skill provides comprehensive documentation and code samples for developing AI applications with Genkit in Go. It includes instructions for installing the Genkit CLI from an official source and documents security features like tool approval and filesystem sandboxing. No malicious patterns were detected.

  • Socket2d

    No alerts

  • Snyk3d

    Risk: MEDIUM · 2 issues

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 5 days ago
metadata
{
  "version": "1.0.0",
  "category": "AiAndMachineLearning"
}

README badge

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