Overview
ThebuildNavaiAgent function creates a fully configured RealtimeAgent instance with navigation tools, function execution capabilities, and backend integration. It processes frontend and backend function definitions, generates appropriate tools, and compiles agent instructions.
Import
Signature
Parameters
Configuration for building the agent.
Return Value
Result object containing the agent and any warnings.
Agent Tools
The built agent includes the following tools:Built-in Tools
navigate_to- Navigate to allowed routesexecute_app_function- Execute any registered frontend or backend function
Direct Function Tools
For each valid function, a direct alias tool is created (e.g.,get_user_profile) that internally calls execute_app_function. Functions are excluded from direct tools if:
- Name conflicts with reserved tools (
navigate_to,execute_app_function) - Name contains invalid characters (must match
/^[a-zA-Z0-9_-]{1,64}$/)
Function Execution
Frontend Functions
Frontend functions are loaded from module loaders and executed directly in the browser.Backend Functions
Backend functions are executed via HTTP request to the backend API.Example Usage
Agent Instructions
The agent receives generated instructions that include:- Base instructions (customizable)
- List of allowed routes with descriptions and synonyms
- List of allowed functions with descriptions
- Execution rules:
- Use
navigate_tofor navigation requests - Use
execute_app_functionor direct tools for function calls - Always include payload (use
nullwhen no arguments needed) - Use
payload.argsfor function arguments - Use
payload.constructorArgsandpayload.methodArgsfor class methods - Never invent routes or functions not in the list
- Ask clarifying questions when unclear
- Use
Payload Structure
Functions receive payloads with specific structures:Simple Function Call
Class Method Call
Object with Value
Conflict Resolution
Name Conflicts
- Frontend vs Backend: Frontend functions take precedence; backend functions with conflicting names are ignored with a warning
- Duplicate Names: Second occurrence is renamed with numeric suffix (e.g.,
get_user_2) - Reserved Names: Functions named
navigate_toorexecute_app_functionare only accessible viaexecute_app_function - Invalid Names: Functions with invalid characters are only accessible via
execute_app_function
Source Reference
Defined in:packages/voice-frontend/src/agent.ts:47