Introduction
About this book
Hey! We want to welcome you to the book Mastering Genkit: Go Edition. Thanks for picking it up! We hope you find it useful and enjoyable.
Authors
Nozomi Koborinai
Nozomi graduated from an IT technical college in March 2019, where he built his foundation in object-oriented programming with Java.
This book emerged from Xavierâs invitation as a collaborative effort. Driven by his passion for great products and developer communities, Nozomi feels a strong mission to spread their value worldwide. Deeply impressed by Firebaseâs exceptional developer experience, he explored Genkit and was captivated by its innovative approach. He now actively contributes to expanding the Genkit ecosystem, including developing the Dart client for Genkit.
In his 6 years of experience, the first four were spent developing electronic medical record systems using C#, teaching at Flutter University (Japanâs Flutter engineering community), and co-authoring books on Flutter design patterns. Currently, he works at a Google Cloud Partner company in Japan, specializing in Serverless Application development (Identity Platform, Firebase, Cloud Run, DevOps, IaC). His deep interest in software architecture has made him proficient in ensuring quality through DDD and clean architecture principles.
He was awarded Google Cloud Partner Top Engineer (Serverless App Development) 2025, a Japan-exclusive award program, and serves as a former instructor and current 1-on-1 mentor at Flutter University. With speaking experience at Google I/O Extended Tokyo and GDG DevFest, he believes that promoting good products is essential for energizing developer communities.
Beyond technology, he enjoys music (guitar and beat-making), reading, and contributing to open-source projects. Improving developer experience is at the heart of his work and brings him the greatest joy.
Xavier Portilla Edo
Xavier obtained his degree in Computer Engineering at the Polytechnic University of Valencia (UPV) in 2014. He then completed his masterâs degree in application software development in 2017 at the aforementioned university. During his academic journey, he had the chance to work on several team projects. The Hyperloop UPV âthe future of transportation, is one of them.
This book means a creation whose purpose is to showcase his work and allow readers to dive in his experience and knowledge. This is Xavierâs way of showing the details behind the projects and businesses in which he has successfully been part of.
Xavier began his career in the AI in October 2019, after developing 4 applications for Alexa. Since then, he has been working on the development of AI applications, as well as in the creation of tools for the AI community. Recognized speaker in several events.
He has +10 years of experience with a focus on Cloud, Kubernetes, DevOps, Q&A, microservices, Generative AI & Conversational AI and mentoring startups thanks to the Google & Microsoft For Startups Program. He is an organizer of GDG Madrid, DevopsDays Madrid. He has been recognized as a Microsoft MVP, GitHub Star, AWS Alexa Champion & Community Builder, and Google Developer Expert in AI and Cloud.
To fulfill his passion for music and friendship, he enjoys live concerts, football (soccer), team sports and many other activities. Starting to play the guitar is on his bucket list. For Xavier, it has been always rewarding to help others learn everything about the trends in new technologies.
Acknowledgments
We want to thank the vast community of developers who dedicate their time to write or talk about certain topics on their own sites or communities. Your huge contribution gave us enough motivation to start doing the same and we find great satisfaction in sharing our knowledge. You all inspire us to keep doing it.
We would also like to make a special mention to the entire Genkit team. Their uplifting technical dissemination inspired us to do the same through articles, events and online sessions, which in sum gave birth to the idea of creating this book.
In addition, it is only fair to dedicate a few words to all the people we stopped seeing or frequenting because of the time we spent on this book. There are friends and relatives who patiently encouraged us to devote time in this work instead of being with them. We have no words to express how enormously grateful we are to you.
Finally, we thank you, dear reader, for placing your complete confidence in this work. We hope you enjoy the lessons and learning of the concepts described here as much as we have enjoyed writing them.
How to read this book
This book is structured in 15 chapters which address specific topics about programming in Go, with the main focus on creating AI Applications using Genkit.
This book deals with basic development related topics, as it has been conceived not only to be read, but also to act as a structured guide that provides a series of exercises, activities, etc. It is possible to find part of this material and other additional resources on the following blogs: https://medium.com/@nozomi-koborinai - https://xavidop.me/
In them we will publish news, errata and complementary information related to this book. You can also find new tutorials, videos, references, etc., which are not included here.
Code examples
All the material published in this book has been produced by using the latest version of Genkit Go, which is open-source. The sample programs shown in the pages of this book were carried out in late September 2025 being Genkit Go in beta. The source code for all these examples remains hosted in the following GitHub repository: https://github.com/mastering-genkit/mastering-genkit-go
We invite you to clone the directory structure to your local drive or device or to download the .zip file in order to run the examples correctly. We will try to keep the code up to date with the latest version and fix any bugs that may have slipped away. You can also report any bugs and give us any feedback about the book or the source code by clicking on the Issues button on GitHub.
It should be mentioned that, in order to submit a new issue, you need to have a GitHub account. Just in case you havenât got one yet.
Interactive book
This book is also available in an interactive format, which allows you to see the content directly in your browser. This format is designed to provide a more engaging reading experience, with features such as clickable code examples, and direct links to resources. Access the interactive version by visiting: https://mastering-genkit.github.io/mastering-genkit-go
Special thanks
We owe special thanks to our dear friend Iman Rahmati for agreeing to serve as the technical editor of the book youâre holding today. We know it wasnât an easy task.
His trust in our work, combined with his thoughtful guidance, has been invaluable throughout this journey. Iman has contributed not only to the development of this book, but also to our growth as authors.
Above all, weâre especially grateful for his patience and availability, which allowed us to learn and grow through many lively discussions. His involvement has enriched this projectâand marked the beginning of a lasting friendship.
Thank you, Iman!
We also extend our heartfelt gratitude to the entire Genkit team at Google. Your innovative work in creating this powerful framework has made this book possible. The teamâs dedication to building developer-friendly AI tools and their commitment to open-source principles has been very inspiring.
The Genkit teamâs responsiveness to community feedback, their documentation, and their vision for making AI development accessible to all Go developers has shaped not only this book but the future of AI application development.
Thank you to the Genkit team for making AI development in Go a reality!
New Choices in AI Development - Introduction to Genkit for Go Developers
The landscape of AI application development has fundamentally shifted. What began as experimental projects with ChatGPT has evolved into production-grade systems that demand reliability, performance, and maintainability. For Go developers, this evolution presents both challenges and opportunities.
This chapter explores why Genkit Go represents a significant advancement for building AI applications in Go. Youâll understand the current AI development ecosystem, learn where Genkit Go fits within it, and see concrete examples of what makes it uniquely suited for Go developers building production AI systems.
Prerequisites
Before diving into this book, you should have:
- Basic Go knowledge: Familiarity with Go syntax, error handling, and basic concurrency concepts
- Understanding of REST APIs: Experience building or consuming HTTP services
- General AI awareness: Basic understanding of what LLMs (Large Language Models) are and their capabilities
- Command line proficiency: Comfortable with terminal/command line operations
No prior AI development experience is required. Weâll build your AI engineering knowledge from the ground up.
Current State of AI Application Development
In 2025, AI development has entered a new phase. More than two years have passed since the emergence of ChatGPT, and many companies are beginning to transition from experimental stages to full-scale implementation.
What has become clear in this process is that AI application development comes with its own unique challenges. Unlike traditional software development, we face new types of problems: non-deterministic outputs, response latency, and difficulty in predicting costs.
The developer community has seen the emergence of various approaches to address these challenges, with frameworks optimized for different languages and ecosystems.
The Diversifying AI Development Framework Landscape
The AI framework ecosystem has matured significantly, with each framework carving out its specialized niche. Understanding these frameworks helps contextualize where Genkit Go fits in the broader landscape.
The Major Players
LangChain has emerged as the most comprehensive framework, supporting Python, TypeScript, and Java. Its strength lies in flexibility and extensive third-party integrations, making it ideal for complex chatbots and workflow automation. However, this comprehensiveness comes with a steeper learning curve and frequent breaking changes as the framework rapidly evolves.
LlamaIndex (formerly GPT Index) takes a different approach, focusing specifically on search and retrieval tasks. It excels at RAG applications with sophisticated vector store integrations and efficient data processing pipelines. Production teams often choose LlamaIndex when their primary need is connecting LLMs to large document repositories.
Semantic Kernel represents Microsoftâs enterprise-focused approach. With tight Azure integration and robust telemetry features, itâs the natural choice for organizations already invested in the Microsoft ecosystem. Its planning and orchestration capabilities are particularly strong, though the community is smaller compared to open-source alternatives.
Haystack by deepset emphasizes production readiness and scalability. Built with a modular pipeline architecture, itâs designed for teams building serious NLP systems at scale. While it requires more setup than simpler frameworks, it offers industrial-strength reliability for question-answering and semantic search systems.
The Rise of Agent Frameworks
Beyond traditional AI frameworks, specialized agent development platforms have emerged:
Mastra, created by the Gatsby team, brings TypeScript-native agent development to the JavaScript ecosystem. With built-in memory persistence, workflow orchestration, and type-safe integrations, it allows web developers to build sophisticated AI agents without leaving their familiar toolchain. Its deployment flexibility makes it particularly attractive for teams already using React or Next.js.
Agent Development Kit (ADK) represents Googleâs vision for enterprise-grade agent development. Launched in 2025, this code-first framework supports both Python and Java, offering sophisticated multi-agent orchestration capabilities. Its integration with Google Cloudâs Agent Engine provides a fully managed runtime, while the Agent2Agent protocol enables cross-platform agent collaboration - a crucial feature for complex enterprise systems.
The Framework Selection Challenge
Each framework represents different philosophical approaches to AI development:
- Flexibility vs. Simplicity: LangChain maximizes flexibility at the cost of complexity
- Specialization vs. Generalization: LlamaIndex specializes in retrieval while others aim for broader use cases
- Ecosystem Lock-in vs. Portability: Semantic Kernel works best within Microsoftâs ecosystem
- Research vs. Production: Some frameworks prioritize cutting-edge features while others focus on stability
This fragmentation creates a dilemma for development teams: choosing a framework often means committing to its specific paradigms, tooling, and limitations.
Production Environment Challenges
When deploying AI applications to production environments, developers face common challenges.
-
Performance and Scalability: LLM inference costs increase proportionally with the number of requests. Balancing response time and cost becomes a critical challenge, especially when dealing with long contexts or complex reasoning requirements.
-
Integration Complexity: Communication between components written in different languages, protocol standardization, and data format unification present numerous technical challenges.
-
Operational Considerations: Building monitoring, logging, error handling, and deployment pipelines requires consideration of AI-specific requirements. In particular, monitoring model output quality and dealing with unexpected responses are new challenges.
What is Genkit?
In 2024, Googleâs Firebase team announced âGenkitâ as a new approach to AI development. Genkit is an open-source framework aimed at simplifying AI application development and allowing developers to focus on their core business logic.
The distinctive concepts of Genkit include:
Unified Interface: Different LLM providers (OpenAI, Anthropic, Google, Vertex AI, etc.) can be handled with a unified API, making provider switching easy.
Vendor Lock-in Avoidance: Despite being developed by Googleâs Firebase team, Genkit is designed as an open-source framework that avoids vendor lock-in, allowing developers to choose any LLM provider or hosting platform.
Developer Experience Focus: Provides GUI tools for efficient debugging, testing, and evaluation in local development environments, addressing AI application-specific development challenges.
Production-Ready: Built with production operations in mind from the start, incorporating features like monitoring, tracing, and error handling.
Plugin Architecture: Various extensions such as vector databases, evaluation tools, and deployment targets can be added as plugins.
Genkit was initially developed in TypeScript/JavaScript, but its design philosophy was language-agnostic. And in 2025, the Go and Python language version has finally arrived.
A New Choice for Go Developers: Genkit Go
In this context, Google announced Genkit Go. This is the full-fledged framework that allows Go developers to build AI applications in a native Go environment.
Genkit Goâs design philosophy reflects Goâs core values. If youâve written Go code before, youâll immediately recognize the patterns. The framework embraces simplicity by offering clear, readable APIs that avoid unnecessary abstractions. Just like standard Go libraries, every operation returns errors that must be explicitly handled - thereâs no hidden magic or exceptions.
Type safety is paramount, with compile-time guarantees for structured inputs and outputs, preventing runtime surprises. The architecture favors composition over inheritance, building complex functionality from small, composable functions rather than deep class hierarchies. And true to Goâs nature, it maintains minimal overhead with predictable performance characteristics.
// Simple and readable API
response, err := genkit.Generate(ctx, g,
ai.WithPrompt("Explain the basic concepts of quantum computing")
)
if err != nil {
return fmt.Errorf("generation error: %w", err)
}
// Type-safe structured output
type Recipe struct {
Name string `json:"name"`
Ingredients []string `json:"ingredients"`
Steps []string `json:"steps"`
}
recipe, resp, err := genkit.GenerateData[Recipe](ctx, g,
ai.WithPrompt("Create a healthy breakfast recipe")
)
Why It Matters for Go Developers
-
Limited Production-Ready Options for Go: Unlike Python or JavaScript ecosystems that offer numerous AI frameworks, Go developers have historically had limited choices for production-ready AI development. Most AI frameworks focus on Python first, leaving Go developers to either write bindings, use REST APIs, or switch languages entirely. Genkit Go changes this landscape by providing a native, production-ready framework specifically designed for Go - and with Googleâs backing, itâs here to stay.
-
Integration with Existing Infrastructure: Many companies already operate high-performance backend systems built with Go. Genkit Go can natively integrate AI capabilities into these systems.
-
Predictable Performance: Goâs efficient memory management and concurrency model allow precise control over AI inference latency and resource usage.
-
Deployment Simplicity: Compilation to a single binary, minimal dependencies, and container-friendly design make deployment to any hosting platform straightforward - from cloud services like Cloud Run and Kubernetes to traditional servers and container orchestration platforms.
-
Ecosystem Consistency: If your team is already familiar with Go, thereâs no need to learn new languages or paradigms.
Common Misconceptions About AI Development
Misconception 1: AI Calls Are Just Like API Calls
Many developers initially treat AI model interactions like traditional API calls - send a request, get a response. However, AI systems introduce fundamentally different characteristics:
- Non-deterministic responses: The same prompt can yield different results
- Variable latency: Response times can range from seconds to minutes
- Token limits and context windows: Constraints that donât exist in traditional APIs
Successful AI applications acknowledge these differences from the start, designing systems that embrace rather than fight against these characteristics.
Misconception 2: One Model Fits All Use Cases
The temptation to use the most powerful model for every task is strong but misguided. In production:
- Cost scales linearly with usage: What works in development can bankrupt in production
- Latency matters: Faster, smaller models often provide better user experience
- Accuracy isnât everything: Sometimes consistency matters more than correctness
The art lies in matching model capabilities to specific use cases, not defaulting to maximum power.
Misconception 3: AI Solves Problems Automatically
Perhaps the biggest misconception is that AI systems automatically understand and solve problems. In reality:
- Context engineering is the new paradigm: While prompt engineering focuses on âhow you ask,â context engineering designs entire information ecosystems - managing what the AI knows, when it knows it, and how it accesses tools and data
- From prompts to systems: The shift from prompt engineering to context engineering reflects AIâs maturation - weâre no longer just crafting clever questions but building dynamic systems that provide the right context at the right time
- Evaluation is essential: Without systematic testing, AI systems degrade unpredictably
- Human-in-the-loop often necessary: Pure automation is rarely the answer
These misconceptions highlight why frameworks like Genkit Go, designed with production realities in mind, become essential for serious AI development.
Thinking About Language Choice
The important question is not âwhich language is the bestâ but âwhat is the optimal choice for your team and project.â
Python has rich AI libraries and community, making it ideal for R&D and experimental projects. JavaScript excels at full-stack web applications and real-time interactions. C# provides robustness in enterprise environments.
And Go offers a new option for teams that need native integration with high-performance backend systems, predictable performance, and operational simplicity.
What Weâll Build Throughout This Book
Rather than following a single project theme, this book takes a different approach. Each chapter introduces Genkit Goâs features through carefully chosen practical examples that best demonstrate the concepts at hand.
Learning Through Diverse Examples
Our philosophy is simple: the best way to understand a feature is through its ideal use case. This book is structured in five comprehensive parts:
Part 1: Foundation establishes your understanding of Genkit Goâs architecture and the AI development landscape. Youâll learn why Genkit Go matters and how to set up your development environment.
Part 2: Core Features dives into the essential capabilities - from basic generation and structured outputs to building flows and streaming responses. These chapters form the backbone of your Genkit Go knowledge.
Part 3: Advanced Features explores sophisticated patterns like tool calling, Model Context Protocol (MCP), RAG systems, evaluation frameworks, and building AI agents. Here youâll learn to create more intelligent and capable applications.
Part 4: Production Excellence focuses on real-world deployment concerns - observability, monitoring, deployment strategies, and cost optimization. These chapters ensure your applications are production-ready.
Part 5: Integration Patterns rounds out your knowledge with client integration strategies, showing how to connect Genkit Go applications with various frontend frameworks and architectural patterns.
Progressive Complexity
The examples progress from simple to complex, each building upon previous knowledge:
- Foundation: Start with basic AI generation and structured outputs
- Interaction: Add streaming, tool calling, and external integrations
- Intelligence: Implement RAG systems, evaluation, and multi-step reasoning
- Production: Deploy, monitor, and scale your AI applications
Why This Approach?
- Feature-focused learning: Each example is chosen to best demonstrate specific Genkit Go capabilities
- Practical diversity: Exposure to various AI application patterns prepares you for real-world projects
- Flexibility: Pick and choose examples relevant to your immediate needs
- Depth over breadth: Deep dive into Genkit Goâs internals rather than surface-level API usage
Key Takeaways
- AI development has evolved from experimentation to production, requiring new engineering approaches
- Genkit Go offers a Go-native solution that aligns with Goâs philosophy of simplicity and performance
- Framework choice matters - Genkit Go is optimal for teams already using Go who need production-grade AI
- Context engineering is the new paradigm - moving beyond simple prompts to designing information ecosystems
- Common misconceptions exist in AI development, but understanding them helps build better systems
- Production considerations like cost, latency, and non-determinism must be addressed from the start
Next Steps
In Chapter 2, weâll dive deep into Genkitâs architecture to understand why this framework feels so natural for Go developers. Youâll learn:
- How Genkitâs plugin system enables flexibility without complexity
- The design decisions that make Genkit Go production-ready
- Detailed comparisons with other AI frameworks from an architectural perspective
- Why Genkitâs approach aligns perfectly with Goâs design philosophy
Get ready to explore the technical foundations that make Genkit Go a powerful choice for AI application development.
Reflections: Toward the Future of AI Development
The world of AI development is evolving rapidly. Whatâs important is that this is not an entirely new field but an extension of existing software engineering. Like data engineering and DevOps before it, AI engineering is a field that anyone can tackle with the right tools and knowledge.
As a Go developer, you already have a solid engineering foundation. Genkit Go provides the tools to build AI capabilities on top of that foundation. Rather than dismissing other languages or frameworks, it provides the optimal choice for your skill set and requirements.
Letâs begin the journey of AI development for Go developers.