You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the Agents SDK Documentation for using dynamic_instructions while discussing the Agent, the following line is used:
defdynamic_instructions(
context: RunContextWrapper[UserContext], agent: Agent[UserContext]
) ->str:
returnf"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:
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:
defdynamic_instructions(context: RunContextWrapper[UserContext], agent: Agent[UserContext]) ->str:
returnf"User ID is {context.context.uid}. Help them accordingly."