Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions py/packages/genkit/src/genkit/_ai/_generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ async def generate_action_fn(
ctx: ActionRunContext,
) -> ModelResponse:
on_chunk = cast(Callable[[ModelResponseChunk], None], ctx.streaming_callback) if ctx.is_streaming else None
return await generate_action(
return await _generate_action(
registry=registry,
raw_request=input,
on_chunk=on_chunk,
Expand All @@ -131,7 +131,11 @@ async def generate_action(
middleware: list[ModelMiddleware] | None = None,
context: dict[str, Any] | None = None,
) -> ModelResponse:
"""Execute a generation request with tool calling and middleware support."""
"""Run generation with a util ``generate`` span.

The registered ``/util/generate`` action calls `_generate_action` directly
so reflection runs do not stack another util span on the action span.
"""
span_name = 'generate'
with run_in_new_span(
SpanMetadata(name=span_name),
Expand Down Expand Up @@ -335,9 +339,7 @@ def message_parser(msg: Message) -> Any: # noqa: ANN401
# No message in response, return as-is
return response

# Stamp output format metadata on message for Dev UI rendering.
# Mirrors JS GenerateResponse constructor which sets message.metadata.generate.output
# so the Dev UI knows to render the output as formatted JSON vs plain text.
# Stamp output format metadata on message so the Dev UI can render formatted JSON vs plain text.
out = raw_request.output
if out and (out.content_type or out.format):
generate_output: dict[str, str] = {}
Expand Down
Loading