Skip to content

docs(react-core): clarify system_prompt requirements for useFrontendTool - #5469

Merged
BenTaylorDev merged 2 commits into
CopilotKit:mainfrom
nuthalapativarun:docs/4950-usefrontendtool-system-prompt
Aug 20, 2026
Merged

BenTaylorDev merged 2 commits into
CopilotKit:mainfrom
nuthalapativarun:docs/4950-usefrontendtool-system-prompt

Conversation

@nuthalapativarun

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds documentation explaining that useFrontendTool may require explicit system_prompt guidance in LangGraph agents to be reliably called. Includes a working code example showing both a well-described useFrontendTool registration and the matching system prompt instruction. Addresses the confusion reported in #4950 where users implement tools with only a description and find the agent doesn't call them.

Changes:

  • docs/integrations/langgraph/frontend-tools.mdx — new section "Ensuring your agent reliably calls frontend tools" with a Callout, Python+TypeScript code examples, and a decision table (description vs. system_prompt)
  • reference/hooks/useFrontendTool.mdx — added "LangGraph agents: description vs. system_prompt" subsection linking to the full example
  • docs/troubleshooting/common-issues.mdx — expanded the "tool listed but agent never calls it" bullet to cross-link the new guide

Related PRs and Issues

Checklist

  • I have read the Contribution Guide
  • If the PR changes or adds functionality, I have updated the relevant documentation
  • "Allow edits by maintainers" is checked

@vercel

vercel Bot commented Jun 16, 2026 •

Copy link
Copy Markdown
Contributor

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Jun 16, 2026 6:25am

Request Review

@vercel

vercel Bot commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

@nuthalapativarun is attempting to deploy a commit to the CopilotKit Team on Vercel.

A member of the Team first needs to authorize it.

@nuthalapativarun

Copy link
Copy Markdown
Contributor Author

Just bumping this — the system_prompt docs clarification for useFrontendTool should be a quick read whenever someone has a few minutes. The Vercel check failure is just the auth-gated preview deploy for fork PRs, not an actual build issue. Thanks!

@nuthalapativarun

Copy link
Copy Markdown
Contributor Author

Hi team — following up on PR #5469 (useFrontendTool system_prompt docs, closes #4950). Mergeable, Vercel CI failures are auth-gated fork-PR false positives. 2nd bump. Happy to address any feedback. Thanks!

@BenTaylorDev

Copy link
Copy Markdown
Contributor

Thanks @nuthalapativarun — content looks reasonable. Two items:

  1. Dangling cross-link: the new section links to /langgraph/advanced/emit-api-hook-mapping, which only exists in your docs(langgraph): document emit API to v2 hook mapping end-to-end #5483 — merging this alone would produce a broken link. These two are coupled; let's land them together (or drop the link until docs(langgraph): document emit API to v2 hook mapping end-to-end #5483 is in).
  2. Please double-check the create_react_agent(middleware=[CopilotKitMiddleware()], prompt=...) / state_schema=CopilotKitState example against the current Python SDK signature, since the branch is a ways behind main.

@BenTaylorDev BenTaylorDev left a comment

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.

Thanks — the thesis is valuable and (nice) it's correctly authored against the current showcase/shell-docs/src/content/ tree and merges clean. But the code examples don't match the shipped API and wouldn't run as written:

  • They use from langgraph.prebuilt import create_react_agent with a middleware= kwarg — but in the pinned langchain 1.x, middleware= belongs to create_agent (langchain.agents), not create_react_agent; as written this likely raises TypeError. Every example on main uses create_agent/createAgent.
  • They pass prompt=/prompt: for the system prompt, which both contradicts the PR's own headline ("add it to system_prompt") and isn't the current param (system_prompt=/systemPrompt:).
  • The TypeScript example imports copilotkitMiddleware but never attaches it (no middleware: array) — so frontend tools wouldn't actually reach the agent in that snippet.
  • The added "Imperatively emitting tool calls" section links to /langgraph/advanced/emit-api-hook-mapping, which doesn't exist on main (dead link), and is scope creep beyond #4950 (system_prompt guidance).

Please align the examples with the current pinned API (create_agent/createAgent + system_prompt=/systemPrompt:, matching main.py/agent.ts), actually wire copilotkitMiddleware into the TS middleware: array, and either drop the emit section or fix its link. The prose is close — it's the examples that need to be made accurate and runnable.

…rent SDK

Switch the code samples from create_react_agent(middleware=..., prompt=...)
to create_agent/createAgent with system_prompt/systemPrompt, matching the
current pinned langchain 1.x API used elsewhere in the docs. Wire
copilotkitMiddleware into the TypeScript example's middleware array (it was
imported but never attached). Point the "Imperatively emitting tool calls"
link at the correct /integrations/langgraph/ prefixed route.

Addresses review feedback on CopilotKit#5469.
@nuthalapativarun

Copy link
Copy Markdown
Contributor Author

Thanks for the detailed review! Pushed a fix that:

  • Swaps create_react_agent(..., middleware=..., prompt=...) for create_agent/createAgent with system_prompt/systemPrompt, matching the current pinned langchain 1.x API (verified against the pattern already used in agent-app-context.mdx).
  • Wires copilotkitMiddleware into the TypeScript example's middleware array — it was imported but never attached, so frontend tools wouldn't have reached the agent.
  • Points the "Imperatively emitting tool calls" link at /integrations/langgraph/advanced/emit-api-hook-mapping, matching the actual route of the new page added in docs(langgraph): document emit API to v2 hook mapping end-to-end #5483 (also just updated) so the cross-link isn't dangling once both land.

Since you flagged these two as coupled, happy to have them merge together.

@BenTaylorDev BenTaylorDev left a comment

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.

Thanks — the API examples are now correct in both languages (create_agent/createAgent, system_prompt/systemPrompt, and the TS example actually attaches copilotkitMiddleware), matching the in-repo reference agents, and the docs are correctly under showcase/shell-docs. One item remains: the "Imperatively emitting tool calls from agent code" section still links to /integrations/langgraph/advanced/emit-api-hook-mapping, which doesn't exist on main (you fixed the URL prefix, but the target page isn't there). That page is the one #5483 creates — so either drop this section (it's outside the system_prompt scope of this PR) or sequence it to land after #5483 so the link resolves. Everything else looks good.

@BenTaylorDev BenTaylorDev left a comment

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.

Re-reviewed against current main. The one item I left open has resolved itself — #5483 merged about nine minutes after my last review, so /integrations/langgraph/advanced/emit-api-hook-mapping now exists on main, the link text matches that page's title verbatim, and the page does cover copilotkit_emit_tool_call and copilotkit_customize_config as promised. That was the sequencing option I offered, so nothing is left for you to do here. Sorry for the wait — the blocker expired the same afternoon I wrote it.

Everything else I checked holds up:

  • API accuracy — I verified the snippets against the pinned wheels, not just by eye. create_agent(model=, tools=, middleware=, state_schema=, system_prompt=) matches langchain/agents/factory.py exactly; CopilotKitMiddleware and CopilotKitState are real top-level copilotkit exports; the Python example matches examples/integrations/langgraph-python/agent/main.py line for line, imports included. The TypeScript example matches examples/integrations/langgraph-js/agent/src/agent.ts, and copilotkitMiddleware is genuinely wired into middleware: now. stateSchema: CopilotKitStateSchema is valid — it's a real StateSchema instance.
  • Placement — correctly authored under showcase/shell-docs/src/content/, and it merges into current main clean despite the branch being stale.
  • Conventions — <Tabs groupId="language_langgraph_agent" … persist>, <Callout>, and the [!code highlight:N] transformer all match what the surrounding pages already do. The anchor the two cross-links point at matches the new heading.

Two nits, neither blocking, both fine to leave:

  • model="openai:gpt-4o" — these docs otherwise use openai:gpt-5.4.
  • The [!code highlight:7] / :6 ranges each stop one line short, so the closing line of each block isn't highlighted.

One note for anyone reading this later, not a request: the # Works the same for "create_react_agent" or similar options comment isn't actually true — in the pinned langgraph, create_react_agent takes neither middleware nor system_prompt and raises on both. That comment already ships on main in two other files, so you were following the house style and this PR isn't the place to fix it; I'll file the tree-wide cleanup separately.

The prose is genuinely useful — the "description tells the model what, system_prompt tells it when" framing plus the decision table is the right shape for #4950. Thanks for sticking with this through two rounds.

I bless the code with a glad heart 🙏

@BenTaylorDev

Copy link
Copy Markdown
Contributor

Note: 2 failing tests are caused by the stale main base and are fixed on main, and these changes are docs-only and so wouldn't run afoul of them.

@BenTaylorDev
BenTaylorDev merged commit f2c9a2e into CopilotKit:main Aug 20, 2026
19 of 21 checks passed
tylerslaton added a commit that referenced this pull request Aug 25, 2026
…t" comments (7 sites) (#6614)

Closes #6607.

Verified against the pinned `langgraph_prebuilt` (1.1.0):
`create_react_agent` has neither `middleware` nor `system_prompt`
parameters, rejects `state_schema=CopilotKitState`, and is deprecated in
favour of `langchain.agents.create_agent`. Readers following the comment
hit an immediate `TypeError`.

All 7 occurrences on `main` are updated (4 sites noted in the issue plus
the 3 that landed with #5469):

-
`showcase/shell-docs/src/content/docs/integrations/langgraph/agent-app-context.mdx`
(Python + TypeScript)
-
`showcase/shell-docs/src/content/docs/integrations/langgraph/frontend-tools.mdx`
(Python + TypeScript)
-
`showcase/shell-docs/src/content/snippets/integrations/langgraph/frontend-tools.mdx`
(Python + TypeScript)
- `showcase/shell-docs/src/content/reference/hooks/useFrontendTool.mdx`
(Python)

Each comment is replaced with an accurate note (”`create_agent`
supersedes the deprecated `create_react_agent`, which accepts neither
`middleware=` nor `system_prompt=`”), and the TypeScript snippets now
reference `createReactAgent` (camelCase) instead of the Python
`create_react_agent` name — the second, smaller problem noted in the
issue.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

📚 Documentation: Clarify when useFrontendTool requires system-prompt guidance (sales dashboard month-range fetch)

2 participants