Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(core): add copilotkit.runTool() for programmatic tool execution#3286

Open
tylerslaton wants to merge 4 commits intomainfrom
claude/condescending-turing
Open

feat(core): add copilotkit.runTool() for programmatic tool execution#3286
tylerslaton wants to merge 4 commits intomainfrom
claude/condescending-turing

Conversation

@tylerslaton
Copy link
Contributor

Adds a new runTool() method to CopilotKitCore that allows programmatic execution of registered frontend tools without requiring an LLM turn. This enables UI-driven tool invocations (e.g., button clicks triggering tool handlers) while maintaining proper message history and subscriber notifications.

Key changes:

  • Extract executeToolHandler helper from duplicated logic in executeSpecificTool to share with runTool
  • Add runTool() on RunHandler with tool/agent lookup, message creation, handler execution, and optional follow-up support
  • Add TOOL_NOT_FOUND and AGENT_NOT_FOUND error codes
  • Add CopilotKitCoreRunToolParams and CopilotKitCoreRunToolResult types
  • Add delegation method on CopilotKitCore
  • Add 16 comprehensive tests covering all runTool behaviors

Adds a new `runTool()` method to `CopilotKitCore` that allows programmatic
execution of registered frontend tools without requiring an LLM turn. This
enables UI-driven tool invocations (e.g., button clicks triggering tool
handlers) while maintaining proper message history and subscriber notifications.

Key changes:
- Extract `executeToolHandler` helper from duplicated logic in
  `executeSpecificTool` to share with `runTool`
- Add `runTool()` on `RunHandler` with tool/agent lookup, message creation,
  handler execution, and optional follow-up support
- Add `TOOL_NOT_FOUND` and `AGENT_NOT_FOUND` error codes
- Add `CopilotKitCoreRunToolParams` and `CopilotKitCoreRunToolResult` types
- Add delegation method on `CopilotKitCore`
- Add 16 comprehensive tests covering all runTool behaviors

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@vercel
Copy link
Contributor

vercel bot commented Feb 26, 2026

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

Project Deployment Actions Updated (UTC)
docs Ready Ready Preview, Comment Mar 3, 2026 9:55pm
travel Ready Ready Preview, Comment Mar 3, 2026 9:55pm

Request Review

@changeset-bot
Copy link

changeset-bot bot commented Feb 26, 2026

🦋 Changeset detected

Latest commit: 374696e

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 23 packages
Name Type
@copilotkit/react-core Patch
@copilotkitnext/core Patch
@copilotkit/a2ui-renderer Patch
@copilotkit/react-textarea Patch
@copilotkit/react-ui Patch
@copilotkitnext/angular Patch
@copilotkitnext/react Patch
@copilotkitnext/web-inspector Patch
@copilotkit-storybook/angular Patch
@copilotkitnext/next-pages-router Patch
@copilotkit/runtime-client-gql Patch
@copilotkit/runtime Patch
@copilotkit/sdk-js Patch
@copilotkit/shared Patch
@copilotkit/voice Patch
@copilotkitnext/agent Patch
@copilotkitnext/demo-agents Patch
@copilotkitnext/eslint-config Patch
@copilotkitnext/runtime Patch
@copilotkitnext/shared Patch
@copilotkitnext/sqlite-runner Patch
@copilotkitnext/typescript-config Patch
@copilotkitnext/node-express Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Feb 26, 2026

Open in StackBlitz

@copilotkit/a2ui-renderer

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/a2ui-renderer@3286

@copilotkit/react-core

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/react-core@3286

@copilotkit/react-textarea

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/react-textarea@3286

@copilotkit/react-ui

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/react-ui@3286

@copilotkit/runtime

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/runtime@3286

@copilotkit/runtime-client-gql

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/runtime-client-gql@3286

@copilotkit/sdk-js

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/sdk-js@3286

@copilotkit/shared

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/shared@3286

@copilotkitnext/agent

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkitnext/agent@3286

@copilotkitnext/angular

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkitnext/angular@3286

@copilotkitnext/core

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkitnext/core@3286

@copilotkitnext/react

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkitnext/react@3286

@copilotkitnext/runtime

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkitnext/runtime@3286

@copilotkitnext/shared

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkitnext/shared@3286

@copilotkitnext/sqlite-runner

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkitnext/sqlite-runner@3286

@copilotkit/voice

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkit/voice@3286

@copilotkitnext/web-inspector

pnpm add https://pkg.pr.new/CopilotKit/CopilotKit/@copilotkitnext/web-inspector@3286

commit: acaa0f2

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Comment on lines +357 to +396
await (this.core as unknown as CopilotKitCoreFriendsAccess).emitError({
error: parseError,
code: CopilotKitCoreErrorCode.TOOL_ARGUMENT_PARSE_FAILED,
context: {
agentId,
toolCallId: toolCall.id,
toolName: toolCall.function.name,
rawArguments: handlerArgs,
toolType,
...(messageId ? { messageId } : {}),
},
});
}

await (
this.core as unknown as CopilotKitCoreFriendsAccess
).notifySubscribers(
(subscriber) =>
subscriber.onToolExecutionStart?.({
copilotkit: this.core,
toolCallId: toolCall.id,
agentId,
toolName: toolCall.function.name,
args: parsedArgs,
}),
"Subscriber onToolExecutionStart error:",
);

if (!errorMessage) {
try {
parsedArgs = JSON.parse(toolCall.function.arguments);
const result = await tool.handler!(parsedArgs as any, {
toolCall: toolCall as any,
agent,
});
if (result === undefined || result === null) {
toolCallResult = "";
} else if (typeof result === "string") {
toolCallResult = result;
} else {
toolCallResult = JSON.stringify(result);
Copy link
Contributor

Choose a reason for hiding this comment

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

this code snippet has so many type casts, can we maybe remove this, llms pick this up constantly and think it's okay to do

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, let me give that a try.

@nx-cloud
Copy link

nx-cloud bot commented Mar 3, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 374696e


☁️ Nx Cloud last updated this comment at 2026-03-03 22:01:41 UTC

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.

2 participants