Skip to content

docs(js/agents): added agents samples#5254

Draft
pavelgj wants to merge 47 commits into
pj/agents-middlewarefrom
pj/agents-sample
Draft

docs(js/agents): added agents samples#5254
pavelgj wants to merge 47 commits into
pj/agents-middlewarefrom
pj/agents-sample

Conversation

@pavelgj
Copy link
Copy Markdown
Member

@pavelgj pavelgj commented May 7, 2026

Parent PR: #5252

pavelgj added 16 commits May 6, 2026 20:34
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`
Add a custom Handlebars helper `roundRobin` that alternates between
two options on each invocation. Update the nameAgent's system prompt
to use the helper for switching between 'sarcastic' and 'business-like'
assistant personalities.
@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 comprehensive test application for Genkit Agents, featuring a React-based web UI and backend implementations for sub-agent delegation, background execution, session branching, and user interrupts. It also adds documentation for the Agents Middleware. Review feedback correctly identifies documentation errors in the README regarding incorrect and duplicated headers. Additionally, a concurrency issue was noted in the background agent's polling logic, where using setInterval with an asynchronous function could lead to overlapping requests; a recursive setTimeout pattern was recommended as a safer alternative.

Comment thread js/plugins/middleware/README.md Outdated
Comment thread js/plugins/middleware/README.md
stopPolling();
setPollCount(0);

pollTimerRef.current = setInterval(async () => {
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

Using setInterval with an async function can lead to multiple concurrent polling requests if a request takes longer than the interval (2 seconds). It is safer to use a recursive setTimeout pattern to ensure that the next poll only starts after the previous one has completed, preventing potential race conditions or server-side request spikes.

@pavelgj pavelgj changed the title samples(js/agents): added agents samples docs(js/agents): added agents samples May 7, 2026
@github-actions github-actions Bot added the root label May 7, 2026
pavelgj added 24 commits May 7, 2026 10:35
Add a new "Trip Planner" agent example that demonstrates defining
agents via `.prompt` files (dotprompt) instead of inline code. Includes
a new TripPlannerPage in the web UI, backend routes, and suggestion
chips in the ChatUI empty state for all agent pages.
Update regex patterns in copyright script to match `.tsx` and `.jsx`
file extensions in addition to `.ts` and `.js`, ensuring copyright
headers are applied to all TypeScript and JavaScript variants.
Update regex in copyright script to match plain .css files in
addition to .scss, and add missing license header to App.css.
Refactor the agents middleware demo to showcase new features:
- Per-agent delegation tools instead of a single `call_agent` tool
- Auto-discovered agent descriptions from registry metadata
- Explicit description overrides via middleware config
- `maxDelegations` guard rail and `historyLength` context forwarding
- Replace custom `getWebResults` tool with built-in Google Search
- Add `retry()` middleware and `maxTurns` to sub-agents
Adds a new coding agent test application featuring:
- Coding agent with file read/write, search/replace, and shell tools
- TypeScript skill definition for coding conventions
- React-based web UI with tool approval workflow
- .gitignore entry for agents workspace directory
Switch from InMemorySessionStore to FileSessionStore for session
persistence across restarts. Refactor test flow to use agent.run()
consistently with other test flows, replacing streamBidi pattern.
Auto-approve tool interrupts via the run-based resume API. Fix type
cast removal for ctx.metadata and use top-level fs import.
…web app

- Rename `Message` interface to `ChatMessage` to avoid conflicts
- Replace `any` typed refs and variables with `SessionState`,
  `MessageData`, `Part`, and `ChatMessage` from genkit/beta
- Add missing type imports across all agent page components
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 root

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant