Genkit is Google's open-source framework for building full-stack, AI-powered and agentic applications for any platform.
Documentation | Samples | Discord | Report Issue
Install the SDK and model provider:
uv add genkit genkit-google-genai genkit-google-cloud genkit-middleware
export GEMINI_API_KEY="your-api-key"from genkit import Genkit
from genkit_google_genai import GoogleAI
ai = Genkit(plugins=[GoogleAI()])
async def main() -> None:
# 1. Stream text as the model writes it
stream = ai.generate_stream(
model="googleai/gemini-flash-latest",
prompt="Stream a 2-line poem about space.",
)
async for chunk in stream:
print(chunk.text, end="")
print()
# 2. Await the final response for usage and finish reason
response = await stream.response
print(response.finish_reason)
# => stop
if __name__ == "__main__":
ai.run_main(main())from pydantic import BaseModel, Field
from genkit import Genkit
from genkit_google_genai import GoogleAI
ai = Genkit(plugins=[GoogleAI()])
# 1. Define a tool with a Pydantic input
class WeatherInput(BaseModel):
city: str = Field(description="Target city name")
@ai.tool(description="Get current weather for a location")
async def get_weather(input: WeatherInput) -> str:
return f"Sunny, 72°F in {input.city}"
# 2. Define the structured output schema
class ActivityPlan(BaseModel):
activities: list[str]
outfit: str
async def main() -> None:
# 3. Stream; Genkit runs the tool calls and parses the output
stream = ai.generate_stream(
model="googleai/gemini-flash-latest",
prompt="Suggest activities for Seattle today.",
tools=[get_weather],
output_schema=ActivityPlan,
)
async for chunk in stream:
if chunk.text:
print(chunk.text, end="")
print()
# 4. Read the validated Pydantic object
response = await stream.response
print(response.output)
# => activities=['Kayak on Lake Union', 'Discovery Park'] outfit='Light jacket'
if __name__ == "__main__":
ai.run_main(main())from pydantic import BaseModel
from genkit.exp import Genkit
from genkit_google_genai import GoogleAI
from genkit_middleware import Middleware, ToolApproval
ai = Genkit(plugins=[GoogleAI(), Middleware()])
tool_approval = ToolApproval(allowed_tools=[])
# 1. A tool takes one input, so group the fields in a model
class Transfer(BaseModel):
amount: float
to_account: str
@ai.tool(description="Transfer money to an account")
async def transfer_money(transfer: Transfer) -> str:
return f"Transferred ${transfer.amount} to {transfer.to_account}"
# 2. Every tool call pauses for approval (allowed_tools=[])
agent = ai.define_agent(
name="bankingAgent",
model="googleai/gemini-flash-latest",
system="Banking assistant. Call transfer_money when requested.",
tools=[transfer_money],
use=[tool_approval],
)
async def main() -> None:
# 3. The turn stops at the pending transfer
chat = agent.chat()
out1 = await chat.send("Transfer $100 to account 999.")
print(out1.finish_reason)
# => interrupted
# 4. Approve the pending calls and resume
restarts = [intr.restart(resumed_metadata={"tool_approved": True}) for intr in out1.interrupts]
out2 = await chat.resume(restart=restarts)
print(out2.text)
# => $100 has been transferred to account 999.
if __name__ == "__main__":
ai.run_main(main())Agents are experimental, and FirestoreSessionStore needs the firestore extra:
uv add 'genkit-google-cloud[firestore]'from genkit.exp import Genkit
from genkit_google_cloud.exp import FirestoreSessionStore
from genkit_google_genai import GoogleAI
ai = Genkit(plugins=[GoogleAI()])
# 1. Persist multi-turn session history in Cloud Firestore
store = FirestoreSessionStore()
# 2. Define an agent backed by the store
agent = ai.define_agent(
name="supportAgent",
model="googleai/gemini-flash-latest",
system="You are a helpful customer support agent.",
store=store,
)
async def main() -> None:
# 3. Each turn is saved; the next one sees the history
chat = agent.chat()
await chat.send("Hi, my name is Alex.")
res = await chat.send("What was my name again?")
print(res.text)
# => Your name is Alex.
if __name__ == "__main__":
ai.run_main(main())| Type-Safe by Design | Native Python type annotations and Pydantic models drive structured inputs, outputs, and tool schemas. |
| Unified Model API | Switch between Google Gemini, Anthropic Claude, OpenAI, Ollama, and Vertex AI with one interface. |
| Integrated Observability | Built-in OpenTelemetry tracing. Inspect execution graphs, token usage, latency, and step inputs/outputs locally in real-time. |
| Production Deployment | Expose flows as standard ASGI/WSGI applications compatible with FastAPI, Flask, Django, Cloud Run, or any serverless platform. |
Run flows, prompts and tools locally with the Genkit Developer UI and CLI.
genkit start -- uv run main.pyKey features:
- Playground: Run and experiment with Genkit flows, prompts, and tools in dedicated playgrounds.
- Trace Inspector: Analyze detailed execution traces, including step-by-step breakdowns of complex flows.
Reference implementations live in samples/:
- Basic Flows: Typed flows, named
ai.runsteps, streaming, and serving over FastAPI. No model or API key needed - Agents: Autonomous multi-turn agents, session state persistence, and memory
- Multimodal & Advanced Gemini: Multimodal media processing, context caching, and code execution
- Tool Interrupts: Pausing tool calls for human approval and resuming the turn
Clone the repository and launch any sample with the interactive Dev UI:
cd samples/<sample-name>
genkit start -- uv run src/main.pyIf you're contributing to the Python SDK:
- Prerequisites: Python 3.10+ and
uv(curl -LsSf https://astral.sh/uv/install.sh | sh) - Install Dependencies:
uv sync - Run Linters & Tests:
just lintandjust test
For coding standards and detailed guidelines, see CONTRIBUTING.md.
- Follow us on X/Twitter – News, updates, and tips.
- Join us on Reddit – Community discussion and Q&A.
- Join us on Discord – Get real-time help and chat with developers.
- Contribute on GitHub – Report bugs, suggest features, or submit PRs.
Apache 2.0


