Skip to main content
Let’s build a production-ready voice agent that can respond to users and trigger function calls. Here’s a preview of what you will build:
  • Real-time speech-to-text, text-to-speech, turn-taking, and low-latency audio delivery powered by Layercode’s edge platform.
  • A sample agent backend that monitors conversation transcripts and responds based on your prompt and the tool calls you define. Deployable anywhere.

Next steps

Keep iterating—here are the next things builders usually tackle.

Customize your prompts

Adjust the prompt or welcome_message in layercode.config.json.
layercode.config.json
{
  "layercode_agent_id": "ibcjp4z0",
  "prompt": "You are having a spoken conversation with the user.",
  "welcome_message": "Hey, how can I help you today?"
}

Add a tool call

The project ships with an example tool in /app/api/agent/route.ts. Modify it or add your own.
/app/api/agent/route.ts
const weather = tool({
  description: 'Get the weather in a location',
  inputSchema: z.object({
    location: z.string().describe('The location to get the weather for')
  }),
  execute: async ({ location }) => {
    stream.data({ isThinking: true });
    // do something to get the weather
    stream.data({ isThinking: false });

    return {
      location,
      temperature: 72 + Math.floor(Math.random() * 21) - 10
    };
  }
});
Learn more about tool calling in Next.js or review the general tool calling guide.

Store your messages

Set up persistent storage for transcripts. A fast database or data store such as Cloudflare D1 or Redis works well. A dedicated guide is coming soon.

Deploy your voice agent backend

Layercode runs the voice pipeline in our cloud, but your backend APIs (and frontend, if you are not using Next.js or telephony) need to be deployed. Use the deployment guides: Remember to set your environment variables in the hosting platform and update the Layercode dashboard with the deployed webhook URL.

Set up telephony

Follow the Twilio setup guide to add phone-call support.

Use the Layercode tunnel

We provide a tunnel utility for local development.
# Start a tunnel for agent dtv3x3d2 on port 5173 with the API located at /api/voice-agent
npx @layercode/cli tunnel --agent=dtv3x3d2 --port=5173 --path=/api/voice-agent --tail
I