Skip to content

feat(js/plugins/middleware): implement agents middleware#5252

Draft
pavelgj wants to merge 15 commits intopj/session-flow-take-2from
pj/agents-middleware
Draft

feat(js/plugins/middleware): implement agents middleware#5252
pavelgj wants to merge 15 commits intopj/session-flow-take-2from
pj/agents-middleware

Conversation

@pavelgj
Copy link
Copy Markdown
Member

@pavelgj pavelgj commented May 7, 2026

Parent PR: #5251

pavelgj added 12 commits May 6, 2026 19:33
Upgrade postcss from 8.4.31 to 8.5.12 across all workspaces and add
new markdown/MDX-related dependencies (remark, rehype, unified, etc.)
to the lockfile.
Introduce a new "Branching (Variants)" agent that generates multiple
name suggestions and lets users pick one. Adds the nameAgent backend
flow, Express API routes, a BranchingChat page with variant card UI,
and navigation/routing integration in the test app.
Replaced the translatorAgent with a more comprehensive writerAgent in the agents test application. The new writerPrompt utilizes multiple input variables (tone, format, audience) rather than a single language parameter.

This update better demonstrates how defineSessionFlowFromPrompt handles multiple prompt input variables. It showcases how a client can supply variables during initialization to dynamically reshape the agent's behavior at runtime without modifying server code. Related Express routes, console logs, and test flows have been updated to reflect the new agent and prompt names.
… apps

Export AgentInit, AgentInput, AgentOutput, and AgentStreamChunk types
from the genkit/beta entry point. Replace `as any` casts in the agents
test app with proper generic type parameters for runFlow/streamFlow,
improving type safety across BackgroundAgent and BankingInterrupt pages.
Add a new custom-state-agent (task tracker) to the agents test app,
including Express API routes, a React TaskTrackerPage component with
a chat + task sidebar UI, and associated styles for progress bars,
task lists, and state visualization.
…lify workspaceAgent

- Rename `simple-agent` to `custom-agent` and update all imports, routes,
  and log messages accordingly
- Refactor `workspace-builder.ts` to use `defineAgent` instead of
  `defineCustomAgent`, leveraging the standard agent API for model calls,
  tool dispatch, streaming, and message management
- Extract `emitArtifact` tool to module scope using `ai.defineTool`
@github-actions github-actions Bot added docs Improvements or additions to documentation js config labels May 7, 2026
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a new 'agents' middleware to the Genkit framework, enabling sub-agent delegation by injecting a delegation tool. The implementation includes the middleware logic, updated documentation, tests, and necessary dependency updates. The review feedback highlights a discrepancy between the documentation and the implementation regarding the method used to run sub-agents, suggests adopting stricter Zod validation for agent names and task descriptions, and advises aligning error handling with repository standards.

Comment thread js/plugins/middleware/README.md Outdated

export const AgentsOptionsSchema = z.object({
agents: z
.array(z.string())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The code correctly throws an error if the agents array is empty. To make this validation more declarative and fail earlier, you can enforce this constraint directly in the Zod schema using .min(1). This would also allow you to remove the manual check on lines 72-76.

    .array(z.string())
    .min(1)
References
  1. Stricter validation is preferable to maintain consistency between different API versions (e.g., v1 and v2).

.enum(agentNames as [string, ...string[]])
.describe('The name of the sub-agent to call.'),
task: z
.string()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

It is a good practice to ensure that the task delegated to a sub-agent is not an empty string. You can enforce this by adding .min(1) to the Zod schema.

Suggested change
.string()
.string().min(1)
References
  1. Stricter validation is preferable to maintain consistency between different API versions (e.g., v1 and v2).

pavelgj and others added 2 commits May 6, 2026 20:41
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

config docs Improvements or additions to documentation js

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant