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-artifacts.md

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

Agent Artifacts (Experimental)

See agents.md · sessions.

Artifacts are named session deliverables — markdown reports, SQL migrations, generated files — persisted in SessionState.artifacts and exposed as chat.artifacts, res.artifacts, and streamed chunk.artifact. Writing an artifact whose name already exists replaces the previous version in place.


Artifacts middleware (genkit_middleware.exp)

Import Artifacts from genkit_middleware.exp (Middleware() does not register it). On every model call, Artifacts() appends an <artifacts> listing of the session's current artifacts (name, size, source) to the system prompt, and gives the model write_artifact and read_artifact tools. Pass Artifacts(readonly=True) to expose only read_artifact. Outside an agent session the tools return an error result instead of raising.

On a store-backed agent, agent.chat(artifacts=...) raises AgentInitError (FAILED_PRECONDITION); have the model write artifacts on a turn, or write them from a tool or custom agent. Store-less agents can seed artifacts= (state).

from genkit_google_genai import GoogleAI
from genkit_middleware.exp import Artifacts

from genkit.exp import Genkit
from genkit.exp.agent import InMemorySessionStore

ai = Genkit(plugins=[GoogleAI()])

agent = ai.define_agent(
    name='workspaceAgent',
    model=GoogleAI.gemini('gemini-flash-latest'),
    system='Use write_artifact to save deliverables and read_artifact to inspect them.',
    use=[Artifacts()],
    store=InMemorySessionStore(),
)


async def main() -> None:
    chat = agent.chat()

    # 1. Stream the turn and observe artifacts as they are written
    turn = chat.send_stream('Write schema.sql for a multi-tenant invoices table.')
    async for chunk in turn.stream:
        if chunk.artifact is not None:
            print('wrote artifact:', chunk.artifact.name)
            # => wrote artifact: schema.sql
    await turn.response

    # 2. Inspect persisted session artifacts
    print([a.name for a in chat.artifacts])
    # => ['schema.sql']


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

Writing artifacts from tools and custom agents

Inside an @ai.tool(), get the active session with current_session() from genkit.exp (None outside an agent turn). Inside a custom agent, call the same method on the SessionRunner. add_artifacts takes a list[Artifact], replaces by name, and emits one chunk.artifact per artifact to streaming callers:

from genkit import Part
from genkit.exp import current_session
from genkit.exp.agent import Artifact


@ai.tool(name='exportAuditReport', description='Save an audit report as a session artifact.')
async def export_audit_report(markdown_body: str) -> dict[str, object]:
    sess = current_session()
    if sess is None:
        return {'ok': False, 'error': 'no active agent session'}

    await sess.add_artifacts([
        Artifact(
            name='audit-report.md',
            parts=[Part.from_text(markdown_body)],
            metadata={'source': 'exportAuditReport'},
        )
    ])
    return {'ok': True, 'name': 'audit-report.md'}

From a custom agent's handle_turn:

from genkit import Part
from genkit.exp.agent import Artifact, SessionRunner


async def save_report(sess: SessionRunner, body: str) -> None:
    await sess.add_artifacts([Artifact(name='report.md', parts=[Part.from_text(body)])])

Reading artifact text

Part.text is str | None. This matches what read_artifact returns to the model:

from genkit.exp.agent import Artifact


def artifact_text(artifact: Artifact) -> str:
    return '\n'.join(p.text for p in artifact.parts if p.text)

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