KatInterview

Expose a Local FastAPI Service as Tools for a Voice AI Agent

System DesignModel answer
MediumModel answerSystem Designfastapillm-toolsapi-design

Last updated

Design and harden two HTTP tool endpoints that let a hosted conversational agent store a user's reported problem and recite earlier ones, with a local server made reachable.

Wiring a Voice Agent to a Local Service

You have a small Python project built on FastAPI running on your laptop. A third-party hosted platform runs conversational AI agents that talk with end users, possibly over a phone call. Your goal is to let the agent do two things mid-conversation:

  1. Record a problem the user describes (an "issue").
  2. Recite the user's earlier issues when they ask about them.

Plan and build a working round trip from the hosted agent to your local service and back for both operations. Then explain how you would make it robust.

Assumptions

  • The platform lets you register custom tools that the agent's language model can invoke during a conversation. Each tool has a name, a plain-language description, an argument schema, and an HTTPS URL. The platform calls that URL with the arguments the model extracted, and whatever you return is passed back to the model, which then speaks to the user.
  • The conversation may be spoken, so anything read aloud must be short and easy to say.
  • If the codebase has no issue storage, an in-memory store or SQLite is fine.
  • The exact request and response formats of the platform are unknown. Confine any dependence on them to a single place in your code.

What to cover

  • How the hosted platform reaches a server running on your machine.
  • Tool names, descriptions, argument schemas, and the agent instructions that tell the model when to call each tool.
  • The FastAPI endpoints, validation, and storage.
  • How the user is identified so nobody hears another person's issues.
  • How read-back output is shaped for speech, including the empty case.
  • Failure handling: request authentication, duplicate saves from retries, slow or failing endpoints, and what the agent says when a tool fails.
  • How you would test locally before connecting the platform.

You may also list the clarifying questions you would ask first.

Hints

Hint 1

Separate the platform-specific envelope (how arguments, call metadata and the response are wrapped) from your business logic, so only one small adapter changes if the format differs from your guess.

Hint 2

Never let the model supply the user's identity as a tool argument. Take it from trusted call metadata (such as a caller number or session ID) that the platform sends, and scope every query by it.

Hint 3

Platforms may retry on timeouts, so make the save operation idempotent using a call/tool-call ID or a content hash, and keep read-back responses short, ordered newest first and capped at a small number.