ChatBots· By

From Pirates to Nobleman: Simulating Multi-Agent Conversations using OpenAI's ChatGPT and Python

From Pirates to Nobleman: Simulating Multi-Agent Conversations using OpenAI's ChatGPT and Python

A multi-agent conversation can be simulated by alternating character instructions over shared context. This tutorial keeps the playful pirate-and-nobleman setup while updating the code to the current OpenAI Responses API and adding an offline deterministic mode.

Define the characters

Each character has a name, voice, and goal. The response from one turn becomes context for the next turn, but the application still controls the maximum number of rounds.

characters = [
    {"name": "James", "voice": "measured nobleman", "goal": "seek a principled answer"},
    {"name": "Blackbeard", "voice": "blunt pirate captain", "goal": "relate every answer to treasure"},
]

Use the current OpenAI client

response = OpenAI().responses.create(
    model=os.getenv("OPENAI_TEXT_MODEL", "gpt-4.1-mini"),
    input=prompt,
)
text = response.output_text.strip()

The default responder uses fixed lines, so the notebook executes without credentials or network calls. Set RUN_LIVE_OPENAI=1 only when you intend to make billable requests.

Conversation turn lengths

Autonomous conversations can drift, repeat, or produce unsafe content. Production systems need turn limits, moderation, logging, cost controls, and human review before generated dialogue is published or used for decisions.

Florian Follonier

Florian Follonier · Cloud Solution Architect at Microsoft

Florian Follonier (PhD) is a Cloud Solution Architect at Microsoft based in Zurich and the author of relataly.com, writing hands-on tutorials on machine learning, Python, RAG, and AI agents.