Add a tool
Give the agent a tool that runs your code, choose how the agent calls it, and draw its calls as your own card.
A tool is a function in your plugin's engine part that the agent can call. This guide builds ticket_read, which
reads a ticket from your tracker by its id.
Copy this prompt into your agent. It builds this in your project from this page.
Build this in my project with conciv. conciv is a dev-only AI agent widget, and it already runs in my app. 1. Read https://conciv.dev/docs/plugins/guides/tool.md and follow it. It is the source of truth for the API. 2. If the project has the conciv-develop skill (conciv init installs it with the @conciv/skills docs pack), load it too. 3. Add a tool to my plugin in conciv/plugins. 4. If I did not say what it should do, ask me before you write code. 5. Give it a zod input, and fail with a clear message when it cannot do its job, as the page shows. 6. Install only the packages the page lists, with the package manager this project uses. 7. Check that the engine sees it: run `npx @conciv/cli tools --help` while the dev server runs. The new tool must be listed. 8. When you are done, tell me what you changed and how to see it.
Write the tool
Add tools inside ctx.tool.transform. Each tools.add call adds one:
import {} from 'zod'
import {Plugin, } from '@conciv/backend-plugin-api'
const = .({: .(), : .()})
export default Plugin.({
: 'tickets',
async () {
await ..(() => {
.({
: 'ticket_read', // <- letters, digits and _
: 'Read a ticket from the tracker by its id, such as OPS-42.',
: .({: .().(/^OPS-[0-9]+$/)}), // <- checked before your code runs
: ,
: {: false},
: async ({}, ) => {
try {
const = await (`https://tickets.example.com/api/${}`, {: .})
return {: .(await .())}
} catch {
throw .({: `The tracker did not answer for ${}.`})
}
},
})
})
},
})import {} from 'effect'
import {} from 'zod'
import {Plugin} from '@conciv/backend-plugin-api/effect'
import * as from '@conciv/protocol/schema/tool'
const = .
export default Plugin.({
: 'tickets',
: () =>
..(() => {
.
: 'ticket_read', // <- letters, digits and _
: 'Read a ticket from the tracker by its id, such as OPS-42.',
: .
:
: {: false},
: ({
.
: async () => {
const = await (`https://tickets.example.com/api/${
return .(
},
Ask the agent "What is the status of OPS-42?". It calls ticket_read and answers from the ticket.
A few things to notice:
descriptionis how the agent decides when to call the tool. Say what it does and what input it expects.- What you return as
outputis what the agent reads. It must match theoutputschema. - A network error and a bad shape both fail the call with the same message, in both tabs.
- The signal aborts when the user stops the turn. Pass it to
fetchso the request stops too.
Direct or code mode
A tool is a code-mode tool unless you set codemode: false. In code mode the agent writes a short TypeScript program
that calls your tool as external_ticket_read. The call shows inside its code card. The agent calls a direct tool by
its name. Each call gets its own card.
A tool called directly, then from code mode
A scripted session in the real panel. It plays in your browser, with no server.
A tool called directly, then from code mode
You: Which version is this project?
The agent calls
project_versionCalled directly: vite-project 0.0.0.
You: Read it again from code mode.
The agent calls
project_versionFrom a code mode program.
Same answer. In code mode the call runs inside a TypeScript program, and its card sits inside the program card.
Pick direct when the user should see each call, or when you draw a card for it. Learn more in Tools and code mode.
Group tools under a namespace
A namespace puts related tools under one name and one description:
import {} from 'zod'
import {Plugin} from '@conciv/backend-plugin-api'
export default Plugin.
The agent reads the namespace's description to decide which group to look at. content is plain text for the
agent, in place of an output. A result can carry both.
Fail a call
Fail a call when the tool cannot do what was asked. The agent reads the message and can try something else:
import {} from 'zod'
import {Plugin, } from '@conciv/backend-plugin-api'
Tool.toolError makes the error. Its message is what the agent sees. In the Promise tab, any other thrown
error also fails the call, with that error's message. In the Effect tab the failure type is Tool.Error.
Errors of your own come from one evlog error catalog, in your plugin's errors.ts. Each entry has a message, and
why and fix where someone can act on it:
import {defineErrorCatalog} from 'evlog'
export const ticketErrors = defineErrorCatalog('tickets', {
TRACKER_DOWN: {
message: ({id}: {id: string}) =>
Fail with Effect.fail(ticketErrors.TRACKER_DOWN({id})). Turn it into a Tool.Error once, at the edge, and branch
on error.code, never on a tag:
Effect.catchIf(
(error) => error.code === ticketErrors.TRACKER_DOWN.code,
(error) => Effect.fail(Tool.toolError({message: error.message, error})),
)Draw a card
Each call of a direct tool shows as a card in the chat. Your plugin's browser part can draw its own. You write the browser part in Solid, React, Preact or plain DOM:
A few things to notice:
renderdraws one call. It runs again as the call moves on.props.inputis the input the agent sent.- A denied or cancelled call reaches
rendertoo, with text that is not JSON. The guarded parse keeps the card up. errorComponentdraws a failed call, with the message inprops.error. Without it the widget shows its error card.- A card that pulls in a large library can load on its first call: give
rendera component made with Solid'slazy(). Learn more in Load a part lazily.
Build or wire it as in Build or wire the browser part, then reload.
Next steps
- Ask for permission: make the user approve a call before it runs.
- Test your plugin: call your tool on a real engine in a test.
- Plugin API reference: every field of a tool and its context.