Swarm Ochestration
RealtimeAgent
, a powerful agent type that connects
seamlessly to OpenAI’s Realtime
API. With
RealtimeAgent
, you can add voice interaction and listening
capabilities to your swarms, enabling dynamic and natural communication.
AG2 provides an intuitive programming interface to build and orchestrate
swarms of agents. With RealtimeAgent
, you can enhance swarm
functionality, integrating real-time interactions alongside task
automation. Check the
Documentation
and Blog for
further insights.
In this notebook, we implement OpenAI’s airline customer service
example in
AG2 using the RealtimeAgent
for enhanced interaction.
ag2
with additional dependencies to run a fastAPI server:llm_config
and realtime_llm_config
LLMConfig.form_json
method loads a list of configurations from an environment variable or a
json file.
ON_CONDITION
class.
PORT
variable to 5050
, which will be
used for the server.FastAPI
instance named
app
, which serves as the main application.GET
endpoint at the root URL
(/
). When accessed, it returns a JSON response with the message
"WebRTC AG2 Server is running!"
.start-chat
endpointnotebook_path
as the current
working directory using os.getcwd()
.static
directory (inside
agentchat_realtime_webrtc
) to serve JavaScript, CSS, and other
static assets under the /static
path.templates
directory within agentchat_realtime_webrtc
./start-chat/
Endpoint: Define a GET
route that
serves the chat.html
template. Pass the client’s request
and the
port
variable to the template for rendering a dynamic page for the
audio chat interface./session
WebSocket
route to handle audio streaming.RealtimeAgent
with the
following:
Flight_Realtime_Agent
.realtime_llm_config
for language
model settings.RealtimeAgent
enabling
it to respond to basic flight queries.realtime_agent
to handle interactions
in real time.