-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Open
Labels
bugSomething isn't workingSomething isn't workingdocumentationImprovements or additions to documentationImprovements or additions to documentationgood first issueGood for newcomersGood for newcomers
Description
Summary
In the Agents SDK Documentation for using dynamic_instructions while discussing the Agent, the following line is used:
def dynamic_instructions(
context: RunContextWrapper[UserContext], agent: Agent[UserContext]
) -> str:
return f"The user's name is {context.context.name}. Help them with their questions."
The line {context.context.name}
is used, however, the UserContext dataclass shown does not contain a name attribute:
@dataclass
class UserContext:
uid: str
is_pro_user: bool
This leads to a runtime error:
AttributeError: 'UserContext' object has no attribute 'name'
Suggested Fixes
You can resolve this by either:
Adding name: str to the UserContext model, OR
Changing the instruction function to use one of the fields that do exist, like uid or is_pro_user.
Example fix:
def dynamic_instructions(context: RunContextWrapper[UserContext], agent: Agent[UserContext]) -> str:
return f"User ID is {context.context.uid}. Help them accordingly."
Metadata
Metadata
Assignees
Labels
bugSomething isn't workingSomething isn't workingdocumentationImprovements or additions to documentationImprovements or additions to documentationgood first issueGood for newcomersGood for newcomers