Create and manage intelligent multilingual AI assistants.
Agents allow you to create, manage, and interact with intelligent multilingual AI assistants.
Follow the example below to create a simple agent and start speaking with it.
Navigate the tabs to see how you can easily change from english speaking agents to any available language.
Copy
Ask AI
import osimport asyncio# See AgentConfig model for full list of parameters to configure the agentfrom pyneuphonic import Neuphonic, Agent, AgentConfigasync def main(): client = Neuphonic(api_key=os.environ.get('NEUPHONIC_API_KEY')) agent_id = client.agents.create( name='Agent 1', prompt='You are a helpful agent. Answer in 10 words or less.', greeting='Hi, how can I help you today?' ).data['agent_id'] # All additional keyword arguments (such as `agent_id` and `tts_model`) are passed as # parameters to the model. See AgentConfig model for full list of parameters. agent = Agent(client, agent_id=agent_id, tts_model='neu_hq') try: await agent.start() while True: await asyncio.sleep(1) except KeyboardInterrupt: await agent.stop()asyncio.run(main())
Copy
Ask AI
import osimport asyncio# See AgentConfig model for full list of parameters to configure the agentfrom pyneuphonic import Neuphonic, Agent, AgentConfigasync def main(): client = Neuphonic(api_key=os.environ.get('NEUPHONIC_API_KEY')) agent_id = client.agents.create( name='Agent 1', prompt='You are a helpful agent. Answer in 10 words or less.', greeting='Hi, how can I help you today?' ).data['agent_id'] # All additional keyword arguments (such as `agent_id` and `tts_model`) are passed as # parameters to the model. See AgentConfig model for full list of parameters. agent = Agent(client, agent_id=agent_id, tts_model='neu_hq') try: await agent.start() while True: await asyncio.sleep(1) except KeyboardInterrupt: await agent.stop()asyncio.run(main())
Copy
Ask AI
import osimport asyncio# See AgentConfig model for full list of parameters to configure the agentfrom pyneuphonic import Neuphonic, Agent, AgentConfigasync def main(): client = Neuphonic(api_key=os.environ.get('NEUPHONIC_API_KEY')) agent_id = client.agents.create( name='Asistente', # Assistant prompt='Eres un agente español útil.', # You are a helpful spanish agent. greeting='¿Cómo puedo ayudarte hoy?', # How can I help you today? ).data['agent_id'] # All additional keyword arguments (such as `agent_id`) are passed as # parameters to the model. See AgentConfig model for full list of parameters. agent = Agent( client, agent_id=agent_id, lang_code='es', voice_id='<VOICE_ID>', ) try: await agent.start() while True: await asyncio.sleep(1) except KeyboardInterrupt: await agent.stop()asyncio.run(main())s
Arabic ar is currently not available in Agents.
When you run the example, the agent will greet you with “Hi, how can I help you today?”.
Your spoken input is then converted into text by a speech recognition system.
The prompt you set above is used as the system prompt for a GPT-4o model, which generates the
responses.
These responses are then converted to audio using Neuphonic’s TTS and played back to you.
You can keep the conversation going for as long as you want!
After creating an agent with client.agents.create, you can access and manage it in the
Voice Agents dashboard. The returned agent_id allows you to
reuse this agent configuration across multiple sessions or applications. You can also modify the agent’s
prompt, greeting, and other settings directly through the dashboard interface for quick iterations
without changing your code.
The Agent interface described above utilizes a WebSocket connection to facilitate real-time audio
streaming between your microphone and the server.
The server processes this audio and sends back responses, which can be categorized into the following
types:
This message contains the text transcription of your spoken input.
It is sent by the server once the speech recognition system detects a pause long enough to
consider your turn complete.
You will receive one of these messages for each turn in the conversation.
This message contains the text transcription of your spoken input.
It is sent by the server once the speech recognition system detects a pause long enough to
consider your turn complete.
You will receive one of these messages for each turn in the conversation.
This message is sent by the server when it detects that the user has started speaking.
You will always receive exactly one of these messages before every user_transcript message.
This indicates that you should stop any playback from the agent.
Copy
Ask AI
{ "type": "stop_audio_response",}
This message includes the response generated by the language model based on your transcribed
input.
You will receive one of these messages for each turn in the conversation.
This message provides the audio bytes of the language model’s response.
Since the audio is streamed, you might receive multiple messages of this type for a single turn
in the conversation.
The Agent class, by default, plays audio_response messages and prints llm_response and
user_transcript messages to the console. To add custom behavior, you can attach a custom event handler
which perform extra actions on each event, as shown below.
Copy
Ask AI
import osimport asynciofrom pyneuphonic import Neuphonic, Agent, AgentConfigfrom pyneuphonic.models import APIResponse, AgentResponsedef on_message(message: APIResponse[AgentResponse]): if message.data.type == 'user_transcript': print(f'Received user_transcript') elif message.data.type == 'llm_response': print(f'Received llm_response') elif message.data.type == 'audio_response': print(f'Received audio_response. Playing audio.') elif message.data.type == 'stop_audio_response': print(f'Received stop_audio_response.')async def main(): client = Neuphonic(api_key=os.environ.get('NEUPHONIC_API_KEY')) agent_id = client.agents.create( name='Agent 1', prompt='You are a helpful agent. Answer in 10 words or less.', greeting='Hi, how can I help you today?' ).data['agent_id'] agent = Agent( client, agent_id=agent_id, tts_model='neu_hq', on_message=on_message, # attach the custom callback ) try: await agent.start() while True: await asyncio.sleep(1) except KeyboardInterrupt: await agent.stop()asyncio.run(main())
If you need more control than the Agent class provides, you can implement a custom solution using the
underlying websocket API. This approach gives you direct control over audio input/output through
custom websocket event handlers, allowing for more advanced or specialized implementations.
For an example on how to do this, see
this
example on the pyneuphonic GitHub examples section.
curl -X GET "https://eu-west-1.api.neuphonic.com/agents" \ -H "X-API-KEY: <API_KEY>"
The previous response does not include prompt and greeting because they can be quite lengthy,
especially for complex agents with extensive system prompts.
The following request will return all details for the specified agent_id.
Copy
Ask AI
curl -X GET "http://eu-west-1.api.neuphonic.com/agents/<AGENT_ID>" \ -H "X-API-KEY: <API_KEY>"