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

/developing-genkit-python

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

Provides guidance on developing AI-powered applications using Genkit Python (0.13) and migrating Genkit Python 0.12 projects to 0.13. Use when building AI agents, flows, tools, structured outputs, or FastAPI routes in Python, upgrading from Genkit 0.12, or debugging Genkit imports, config errors, or traces. Don't use for Genkit in JavaScript/TypeScript, Go, or Dart.

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

Nothing lands on disk. Nothing to clean up.

Fork this Skill

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

referencesagents-sessions.md

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

Sessions & Persistence (Experimental)

See agents.md.

With a SessionStore, the server owns conversation history. Every turn writes a SessionSnapshot keyed by snapshot_id, enabling resume across restarts, branching, and detached background turns. Interrupts work with or without a store.


Choose a store

Import local stores from genkit.exp.agent and the production Firestore store from genkit_google_cloud.exp:

from genkit.exp.agent import FileSessionStore, InMemorySessionStore
from genkit_google_cloud.exp import FirestoreSessionStore

# 1. Local dev & tests (lost when the process exits)
mem_store = InMemorySessionStore()

# 2. Local disk persistence (one <snapshot_id>.json file per turn)
file_store = FileSessionStore(
    './.snapshots',
    max_persisted_chain_length=20,  # optional: prune oldest ancestors on save
    reject_ambiguous_session=True,  # optional: raise on session_id lookup after a fork
)

# 3. Production durable store (JSON Patch diffs + sharded checkpoints, ADC auth)
firestore_store = FirestoreSessionStore(
    collection='genkit-sessions',
    snapshot_path_prefix=lambda ctx: (ctx or {}).get('tenant_id', 'global'),
)

FirestoreSessionStore stores each turn as a JSON Patch diff from its parent with periodic sharded checkpoints so large sessions stay below Firestore's 1 MiB document limit without secondary indexes. Pass snapshot_path_prefix to isolate multi-tenant paths from action context.

Persist and rehydrate a chat

from genkit_google_genai import GoogleAI

from genkit.exp import Genkit
from genkit.exp.agent import FileSessionStore

ai = Genkit(plugins=[GoogleAI()], model=GoogleAI.gemini('gemini-flash-latest'))

agent = ai.define_agent(
    name='logbookAgent',
    system='You are a concise engineering logbook assistant.',
    store=FileSessionStore('./.snapshots'),
)


async def main() -> None:
    # 1. Run turn 1; save res.snapshot_id in your app database
    chat = agent.chat()
    res = await chat.send('Log: migrated auth service to token exchange.')
    checkpoint = res.snapshot_id
    assert checkpoint is not None

    # 2. Rehydrate full state (messages, state, artifacts) onto a fresh chat
    resumed = await agent.load_chat(snapshot_id=checkpoint)
    res2 = await resumed.send('Add note: latency p99 stayed at 14ms.')
    print(res2.text)


if __name__ == '__main__':
    ai.run_main(main())

Resume and lookup methods

  • await agent.load_chat(snapshot_id=...) / load_chat(session_id=...): reads the stored snapshot immediately and populates chat.messages, chat.state, and chat.artifacts. Pointing load_chat at a failed, aborted, or pending leaf loads that row as-is; calling send() on a non-completed snapshot returns res.error (SNAPSHOT_NOT_RESUMABLE).
  • agent.chat(session_id=...): attaches a lazy session handle without an upfront read. On the next send(), the server automatically walks back past any failed, aborted, or expired leaf to continue from the last completed turn (or starts a fresh session under session_id if no turn has completed yet).
  • agent.chat(snapshot_id=...): attaches a lazy resume handle to a specific completed snapshot.
  • await agent.get_snapshot(snapshot_id=...) / get_snapshot(session_id=...): inspects the raw SessionSnapshot without creating a chat.

Typed state and multi-user isolation

  • Typed state: Pass state_schema=MyModel on the agent. On a store-backed agent, agent.chat(state=...) raises AgentInitError immediately; mutate state from tools with current_session() from genkit.exp (see state).
  • Multi-user sessions: One Agent instance safely serves many users on a shared store. Each agent.chat() mints a distinct session_id; store session_id or snapshot_id per user in your application database.

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.

No alerts14d3 checks · Risk SAFE
  • Gen Agent Trust Hub14d

    The skill provides comprehensive documentation and code examples for developing AI applications with Genkit Python. It includes instructions for setting up environment variables and installing packages from trusted registries (NPM, PyPI). While it describes building agents that process untrusted user data, which creates a potential surface for indirect prompt injection, this is inherent to the technology described and is documented alongside safety features like human-in-the-loop approval.

  • Socket14d

    No alerts

  • Snyk14d

    Risk: LOW · No 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 5 days ago.

Activeupdated 2 weeks ago
metadata
{
  "version": "1.0.0",
  "category": "AiAndMachineLearning"
}

README badge

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