Skip to content

Optimize Prompts Cookbook #1939

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Jul 15, 2025

Conversation

CorwinCheung
Copy link
Contributor

Summary

Added Cookbook that outlines how Optimize Prompts Works and provides example of Agents-sdk usage, prompting best practices, and Pydantic models.

"source": [
"# Optimize Prompts\n",
"\n",
"This cookbook provides a look into an early version of OpenAI's prompt optimization system. Crafting effective prompts is a critical skill when working with AI models. Even experienced users can inadvertently introduce contradictions, ambiguities, or inconsistencies that lead to suboptimal results. The system demonstrated here helps identify and fix common issues, resulting in more reliable and effective prompts.\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tink we can edit the first sentence here - like This cookbook demonstrates how we used the Agents SDK together with Evals to build the first version of prompt optimization - aimed at addressing common issues

Obviously not quite like that but like starting off with what we're going to teach you

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I see we dont talk about evals in here right now - I feel like we probably should since it's a cookbook and usually those are talking about development workflows

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think putting this in Objective after providing some context makes sense here!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CleanShot 2025-07-14 at 09 42 57 Happy to get more feedback on if this is a good structure

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense to me!

"\n",
"4. **Dev-Rewriter**: After issues are identified, this agent rewrites the prompt to resolve contradictions and clarify format specifications while preserving the original intent.\n",
"\n",
"5. **Few-Shot-Rewriter**: Updates inconsistent example responses to align with the rules in the prompt, ensuring all examples properly comply with the new developer prompt.\n",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: developer or system prompt - this is in a few other places as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'm fairly consistent with developer prompt instead of system prompt here! I think that's the best wording to use

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah I was just saying that depending on the model it may be called developer or system prompt, but I'm ok with keeping it simple since all new models use developer prompt

@CorwinCheung CorwinCheung requested a review from jillian-oai July 14, 2025 22:40
Copy link
Contributor

@josiah-openai josiah-openai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small thing!

" developer_message: str,\n",
" messages: List[\"ChatMessage\"],\n",
") -> Dict[str, Any]:\n",
" \"\"\"\n",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you group these all in a overarching trace, like this example:

from agents import Agent, Runner, trace

async def main():
    agent = Agent(name="Joke generator", instructions="Tell funny jokes.")

    with trace("Joke workflow"): 
        first_result = await Runner.run(agent, "Tell me a joke")
        second_result = await Runner.run(agent, f"Rate this joke: {first_result.final_output}")
        print(f"Joke: {first_result.final_output}")
        print(f"Rating: {second_result.final_output}")

Should follow the BP a bit better for grouping these.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably just the whole function would work for this!

@CorwinCheung CorwinCheung merged commit 4736a0c into openai:main Jul 15, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants