Repository navigation
fix(py): accept positional steps and async callables in ai.run/Tool, and isolate child action context - #84
Merged
Conversation
huangjeff5
force-pushed
the
fix/py-1.0-pr3c-action-context-ai-run
branch
from
November 11, 2026 06:22
a44f8d2 to
4376044
Compare
huangjeff5
force-pushed
the
fix/py-1.0-pr3c-action-context-ai-run
branch
from
November 11, 2026 18:38
4376044 to
82db2b8
Compare
…t input, and max_turns - max_turns: validated up front. True, nan, inf, and 2.5 raise INVALID_ARGUMENT instead of running as 1 or leaking a ValidationError. A whole float like 3.0 from a .prompt file still works. Default stays 50 tool rounds. - restart(replace_input=...): history and the model's next turn carry the input the tool ran with. replacedInput is stripped from the history part so it doesn't read as a pending restart. A restart that pauses again pauses on the approved input. - system= with messages=: prepended; system messages already in history are sent as stored. system='' adds nothing. - prompt= with resume_respond/resume_restart: fails FAILED_PRECONDITION / INVALID_RESUME before the model runs, and the message names prompt=. - docs=: text only, `- [ref]: text`; metadata and media stay out of the prompt. Skipping docs= because a context part already exists now logs. - AgentInterrupt.metadata exposes the Interrupt(...) payload. - A bare restart() reads as resumed in ctx.is_resumed() and on the span. - Resume validation errors in reject_unanswered_interrupts set reason=INVALID_RESUME.
…ool, and isolate child action context
huangjeff5
force-pushed
the
fix/py-1.0-pr3c-action-context-ai-run
branch
from
November 12, 2026 07:26
82db2b8 to
766d5ea
Compare
apascal07
approved these changes
Nov 12, 2026
apascal07
reviewed
Nov 12, 2026
Base automatically changed from
fix/py-1.0-pr3b-generate-loop-invariants
to
main
November 13, 2026 03:18
# Conflicts: # packages/genkit/src/genkit/_ai/_aio.py # packages/genkit/src/genkit/_ai/_generate.py # packages/genkit/tests/genkit/ai/generate_loop_test.py
This was referenced Nov 15, 2026
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ai.runaccepts positional(name, fn)arguments and callables returning awaitables (including lambdas callingasync deffunctions and classes withasync def __call__), child flows get isolated context copies, and middleware hooks see the call's context.Main Changes
ai.run: In Python, lambdas are synchronous function objects that can return coroutine objects (e.g.lambda: fetch_menu(i)wherefetch_menuis anasync deffunction); checkinginspect.iscoroutinefunction(fn)rejected every lambda returning a coroutine. We changedai.run(name, fn)to accept arguments positionally or by keyword, inspect the returned value withinspect.isawaitable(), and reject named syncdeffunctions up front before execution.async def __call__inTool: Previously,Tool(...)relied strictly oninspect.iscoroutinefunction(), which evaluates toFalseon class instances even when their class defines anasync def __call__. We now inspecttype(func).__call__, allowing stateful callable objects to be registered as tools without wrapper functions.ActionRunContextpassed the parent flow's mutableself.contextdict directly to child flows, causing concurrent sibling tasks to overwrite each other's keys under async load. Child actions now receive a shallow copy (dict(parent.context)), isolating writes.ai.generate: Previously,Genkit.current_context()returnedNoneinside middleware hooks when context was passed directly toai.generate(context=...). We now bind the call's context for the duration of the generate action, making it visible to telemetry and audit middleware.