

- Loads environment variables securely (do not hard-code API keys).
- Defines an Agent with clear role-based instructions.
- Uses an asynchronous main loop to run the agent via
Runner.run. - Stores and displays a simple chat history.
- Supports the
history,exit, andquitcommands.
Make sure you have a
.env file with OPENAI_API_KEY set, or set the environment variable in another secure way. Do not hard-code API keys in your script.python-dotenv to load the API key, defines an Agent with instructions, awaits Runner.run, and manages conversation memory.
- Loads environment variables safely via
python-dotenv. - Defines an Agent with a role-based instruction set so the model acts like a police sketch artist.
- Runs an asynchronous loop that:
- Accepts and validates user input.
- Handles
history,exit, andquitcommands. - Invokes the agent using
await Runner.run(agent, user_input). - Extracts the agent’s output (
final_outputoroutput) and appends each turn tochat_history. - Prints the agent response and usage reminders.
| Command | Description |
|---|---|
history | Prints the conversation history collected during this session |
exit / quit | Ends the chat session and exits the program |

- OpenAI Agents guide: https://platform.openai.com/docs/guides/agents
- OpenAI Agents SDK (examples & Quickstart): https://github.com/openai/agents
- python-dotenv: https://pypi.org/project/python-dotenv/
- Pydantic docs: https://docs.pydantic.dev/latest/
- Images guide (DALL·E): https://platform.openai.com/docs/guides/images