Skip to content

Commit 8b72e22

Browse files
- Replace CustomerContext to dataclass, - simplified main function by removing intermediate choice variable.
1 parent a4c125e commit 8b72e22

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

examples/basic/dynamic_system_prompt.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
import asyncio
22
import random
33
from typing import Literal
4-
54
from agents import Agent, RunContextWrapper, Runner
5+
from dataclasses import dataclass
66

7-
7+
@dataclass
88
class CustomContext:
9-
def __init__(self, style: Literal["haiku", "pirate", "robot"]):
10-
self.style = style
9+
style: Literal["haiku", "pirate", "robot"]
1110

1211

1312
def custom_instructions(
@@ -27,11 +26,9 @@ def custom_instructions(
2726
instructions=custom_instructions,
2827
)
2928

30-
3129
async def main():
32-
choice: Literal["haiku", "pirate", "robot"] = random.choice(["haiku", "pirate", "robot"])
33-
context = CustomContext(style=choice)
34-
print(f"Using style: {choice}\n")
30+
context = CustomContext(style=random.choice(["haiku", "pirate", "robot"]))
31+
print(f"Using style: {context.style}\n")
3532

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

43+
4644
"""
4745
$ python examples/basic/dynamic_system_prompt.py
4846

0 commit comments

Comments
 (0)