Skip to content

Bug: context.context.name used in dynamic instruction in Agent documentation, but name not in UserContext #1262

@Zubair-Ahmad-Atd

Description

@Zubair-Ahmad-Atd

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

No one assigned

    Labels

    bugSomething isn't workingdocumentationImprovements or additions to documentationgood first issueGood for newcomers

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions