---
title: "How to Orchestrate Multi-Call Conversations with an LLM and Twilio Conversation Memory with PHP"
description: "This tutorial shows how to build a PHP voice agent that retains caller context, preferences, and action history across separate inbound calls. It uses Twilio Conversation Memory with a Memory Store, an Open Swoole service, Twilio ConversationRelay, and an OpenAI integration using gpt-4o-mini; the example models an auto-repair shop assistant. The OpenAI service appends supplied prior customer context to its system prompt, while streamed responses are sent through a WebSocket and environment variables provide API credentials and the Memory Store ID. After running the service on port 9501, exposing it with ngrok, and configuring the phone-number webhook, the tutorial tests two calls from the same number and says the second call should remember details from the first."
---

# How to Orchestrate Multi-Call Conversations with an LLM and Twilio Conversation Memory with PHP

[Twilio](https://yomu.fyi/company/twilio) · Amanda Lange, Matthew Setter · Sep 11, 2026

**Type:** Tutorial

## Summary

This tutorial shows how to build a PHP voice agent that retains caller context, preferences, and action history across separate inbound calls. It uses Twilio Conversation Memory with a Memory Store, an Open Swoole service, Twilio ConversationRelay, and an OpenAI integration using gpt-4o-mini; the example models an auto-repair shop assistant. The OpenAI service appends supplied prior customer context to its system prompt, while streamed responses are sent through a WebSocket and environment variables provide API credentials and the Memory Store ID. After running the service on port 9501, exposing it with ngrok, and configuring the phone-number webhook, the tutorial tests two calls from the same number and says the second call should remember details from the first.

## Context

The tutorial addresses voice-agent interruptions caused by hangups or disconnections. Twilio Conversation Memory is presented as a way to persist context between calls, although it is not intended for sensitive information.

## Approach / What changed

Create a PHP project with Composer dependencies, configure a Twilio Memory Store and environment variables, then connect an Open Swoole WebSocket server to Twilio ConversationRelay and OpenAI. The OpenAI service uses gpt-4o-mini, incorporates prior memory context into its system prompt, streams response tokens, and logs the interaction. The application is run locally and exposed to Twilio through ngrok.

## Takeaways

- Twilio Conversation Memory persists context between separate calls, allowing a returning caller’s previous discussion to be used without repeating details.
- The OpenAI integration uses gpt-4o-mini with a 400-token limit and streams generated content through ConversationRelayHandler over a WebSocket.
- Conversation Memory is not intended for sensitive information, and testing requires two calls from the same phone number after configuring the Twilio webhook.

## FAQ

### How does the agent remember details after a caller hangs up?

Twilio Conversation Memory persists context between calls. On a later call, the prior customer context is appended to the OpenAI assistant’s system prompt.

### How are OpenAI responses delivered to the phone agent?

The PHP service creates a streamed gpt-4o-mini response. Each returned token is sent as JSON through the WebSocket handler, followed by a final message marking the stream complete.

### What is required to test the multi-call memory flow?

The tutorial requires a Twilio account and voice-capable number, PHP 8.5 or later, Composer, an OpenAI API key, and ngrok. After running the service and pointing the incoming-call webhook to the ngrok URL followed by /voice, make two calls from the same number.

**Tags:** [OpenAI API](https://yomu.fyi/topic/openai-api), [PHP](https://yomu.fyi/topic/php), [Twilio](https://yomu.fyi/topic/twilio), [WebSockets](https://yomu.fyi/topic/websockets)

- Source: [Twilio](https://www.twilio.com/en-us/blog/developers/tutorials/product/orchestrate-multi-call-conversations-with-llm-twilio-conversation-memory-php)
- Source URL: https://www.twilio.com/en-us/blog/developers/tutorials/product/orchestrate-multi-call-conversations-with-llm-twilio-conversation-memory-php
- Ingested by Yomu: 2026-09-15T12:01:06.828Z

[Read original post](https://www.twilio.com/en-us/blog/developers/tutorials/product/orchestrate-multi-call-conversations-with-llm-twilio-conversation-memory-php)
