Open
Description
Describe the feature
The twilio start event has important information like the callSid
and customParameters
. It would be great to be able to have dynamic instructions for the agent based on customParameters
.
https://www.twilio.com/docs/voice/twiml/stream#custom-parameters
Current behavior
The agent/session is instantiated prior to the twilio start event so you can't use the twilio_message
event to set the context.
Example of desired behavior
import { TwilioRealtimeTransportLayer } from '@openai/agents-extensions';
import { RealtimeAgent, RealtimeSession } from '@openai/agents/realtime';
const agent = new RealtimeAgent({
name: 'My Agent',
instructions: ({ context: ctx }) => `Thank you for calling the ${ctx.customParameters.name} store!`
});
const twilioTransport = new TwilioRealtimeTransportLayer({
twilioWebSocket: websoketConnection,
});
// Not sure what the interface should look like, but it'd be nice if the twilio/openai connect weren't so tightly coupled
const { start } = await twilioTransport.twilioConnect();
const session = new RealtimeSession(agent, {
// set your own transport
transport: twilioTransport,
context: {
callSid: start.callSid,
customParameters: start.customParameters
}
});
await session.connect({ apiKey: 'your-openai-api-key' });
another option would be to store the whole start data on the transport and include the transport in the RunContext
const agent = new RealtimeAgent({
name: 'My Agent',
instructions: ({ transport }) => `Thank you for calling the ${transport.start.customParameters.name} store!`
});