packages/domain, wrap it in a tool in packages/agent-core, and decide which conversations get it. Phone calls, browser calls, website chat, Instagram and text replies all run the same agent, so the tool works on each of them once you add it. Understand how LobbyStack is built explains where the agent runs.
The example tool, checkServiceArea, tells a caller whether the business serves their postal or ZIP code. Swap in your own operation as you follow the steps.
Before you start
You need:- a clone of your fork, with
pnpm installrun and the stack running locally, as the repository README describes - the data the tool reads. This guide assumes a
serviceAreastable withbusinessIdandpostalPrefixcolumns. A new table needs a hand-written migration that turns on row-level security; the database section ofAGENTS.mdlists each step.
snapshot in createAgentTools and skip the domain function. Calls read the snapshot once, so a tool that uses it answers faster.
Write the domain function
Business operations live inpackages/domain, where the admin, the worker and the agent can all call them. Each one takes a DomainContext and runs its queries inside withBusinessTransaction, which sets the business for row-level security:
packages/domain/src/server/serviceAreas.ts
configured: false when the business has listed no areas, so the agent can tell “we don’t serve you” apart from “we don’t know”. Export it from packages/domain/src/server/index.ts with export * from "./serviceAreas";.
Decide which conversations get the tool
packages/agent-core/src/capabilities.ts holds the one decision about which tools a conversation gets. Add the tool at the end of TOOL_USE, with its kind and the line a call’s progress update uses:
packages/agent-core/src/capabilities.ts
action for a tool that changes something, such as a booking, and other for a lookup.
Then add the tool at the end of the offered record in agentCapabilities. pnpm typecheck fails until you do, because the record needs an entry for each name in TOOL_USE. A read-only lookup can run in every conversation, test chats and prospect demos included:
packages/agent-core/src/capabilities.ts
live list that agentCapabilities returns:
packages/agent-core/src/capabilities.ts
Define the tool
Tools live increateAgentTools in packages/agent-core/src/tools.ts. Each one has a description the model reads, a Zod input schema, and an execute function. Add yours as the last tool, before return tools;, behind the offered check, and import servesPostalCode from @lobbystack/domain at the top of the file:
packages/agent-core/src/tools.ts
Test each part
The repository runs Vitest, with each test file next to its source. Test the tool, the capability decision and the domain function. Start with the tool.packages/agent-core/src/tools.test.ts mocks @lobbystack/domain at the top of the file, so add your function to that mock:
packages/agent-core/src/tools.test.ts
packages/agent-core/src/tools.test.ts
creates exactly the tools capabilities.ts offers in the same file compares the tools createAgentTools builds with the list agentCapabilities returns, in order. It fails if you skip the offered check, or if the tool’s place in tools.ts doesn’t match its place in offered.
capabilities.test.ts lists the exact tools that some conversations get, such as the default web chat, a test chat and a prospect demo. Add your tool to each list it now joins, or narrow its offered entry if it doesn’t belong there. Then add a test for the conversations that shouldn’t get it, if any.
Test the domain function against PostgreSQL in serviceAreas.integration.test.ts. Copy the setup of an existing integration test, such as packages/domain/src/server/appointmentRequests.integration.test.ts: it seeds a business inside a transaction, calls the function with { db: tx as unknown as Database }, and rolls the transaction back. Integration tests skip unless LOBBYSTACK_RELIABILITY_TEST_DATABASE_URL points at a dedicated test database. Against that database, pnpm db:check and pnpm db:verify-rls check your migration and its row-level security policy.
Run the tests for both packages:
Check the tool on a call
Changing thelive list changes GPT-Live’s instructions, so run the voice evaluation before you merge. It plays scripted callers against the real GPT-Live model:
live.delegation, with the tools it called in tools. The voice testing notes cover each scenario and pnpm voice:call, which places real phone calls.
On a call, the agent takes a second model step to put a tool’s result into words. For a result GPT-Live can say as it is, add a formatter to FORMATTERS in packages/agent-core/src/live/directAnswer.ts, and the agent skips that step.
Next steps
The tool now answers on every channel the agent runs on. To let other software use the same domain function:- API clients: add an operation in
packages/shared/src/publicApi/operations.tsand its route inapps/admin/app/api/v1 - AI assistants: add an MCP tool in
apps/admin/src/lib/mcp/tools.ts, with the scope it needs - Operators: add a settings page in
apps/adminwhere the business lists its areas, with its copy in the locale files