You're doing Agentic chat history wrong | OpenAI Agents SDK

The video explains the importance of effective prompting and chat history management in OpenAI’s Agents SDK, highlighting the shift from simple user-assistant exchanges to event-driven workflows using various message types. It emphasizes dynamic, context-aware instructions and the explicit handling of conversation history and function call messages to build robust, versatile AI agents.

The video begins by emphasizing the importance of prompting in AI systems, particularly when working with OpenAI’s Agents SDK. Although prompting might not seem exciting, it is a fundamental skill that cannot be avoided. The instructor demonstrates how to set up the environment, including installing the OpenAgent package and configuring the OpenAI API key, recommending using Google Colab for convenience but also showing how to set it up locally. The first example introduces static instructions, or system prompts, where the agent is instructed to speak like a pirate, illustrating the basic initialization and execution of an agent using asynchronous code.

Next, the video explores dynamic instructions, where prompts can change based on context, such as including the current date and time. This is achieved by passing a function that generates instructions at runtime, allowing the agent’s behavior to adapt dynamically—for example, speaking like a pirate only in the afternoon. This section highlights the flexibility of the Agents SDK in handling more complex and context-aware prompting scenarios, encouraging developers to think beyond static prompts.

A significant portion of the video is dedicated to rethinking how conversations with agents are structured. Instead of viewing chat history as a simple back-and-forth between user and assistant, the instructor suggests thinking of interactions as a sequence of events or a workflow execution engine. This perspective accommodates various triggers beyond user messages, such as system events or tool invocations, making the agent more versatile. The video then details the five primary message types used by OpenAI—developer (formerly system), user, assistant, function call, and function call output—explaining their roles and how they fit into the conversation or event log.

The instructor further explains how these message types are implemented in the Agents SDK, including the importance of typing messages correctly for robust applications. Examples show how to create user and developer messages, insert system instructions dynamically, and handle assistant responses. A key insight is that the SDK does not automatically maintain conversation history; developers must explicitly manage and pass chat history to preserve context across interactions. This understanding is crucial for building applications that require ongoing conversations or stateful interactions.

Finally, the video covers function call messages, illustrating how agents can invoke external tools or functions and handle their outputs. It stresses the necessity of pairing each function call with a corresponding function call output message, both sharing the same unique call ID, to ensure proper processing by OpenAI’s system. The video concludes by summarizing the complexity and structure behind prompting and message handling in the Agents SDK, encouraging developers to grasp these concepts thoroughly to avoid common pitfalls and to design more effective, event-driven AI workflows.