Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 6 additions & 8 deletions examples/basic/dynamic_system_prompt.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
import asyncio
import random
from typing import Literal

from agents import Agent, RunContextWrapper, Runner
from dataclasses import dataclass


@dataclass
class CustomContext:
def __init__(self, style: Literal["haiku", "pirate", "robot"]):
self.style = style
style: Literal["haiku", "pirate", "robot"]


def custom_instructions(
Expand All @@ -27,11 +26,9 @@ def custom_instructions(
instructions=custom_instructions,
)


async def main():
choice: Literal["haiku", "pirate", "robot"] = random.choice(["haiku", "pirate", "robot"])
context = CustomContext(style=choice)
print(f"Using style: {choice}\n")
context = CustomContext(style=random.choice(["haiku", "pirate", "robot"]))
print(f"Using style: {context.style}\n")

user_message = "Tell me a joke."
print(f"User: {user_message}")
Expand All @@ -43,6 +40,7 @@ async def main():
if __name__ == "__main__":
asyncio.run(main())


"""
$ python examples/basic/dynamic_system_prompt.py

Expand Down
Loading