Function extractAgentContext

  • This function facilitates the use of contextually provided agent functionalities, such as managing the agent's state, authentication state, and user principal.

    Parameters

    • agentContext: Context<null | types.AgentContext>

      A React context object of type AgentContext or null, typically provided by an AgentProvider at a higher level in the component tree.

    Returns Omit<CreateAgentContextReturnType, "AgentProvider" | "AgentContext">

    An object containing the following hooks:

    • useAgent: Hook for accessing the current agent instance.
    • useAuthState: Hook for accessing the current authentication state.
    • useAgentState: Hook for accessing the current state of the agent.
    • useAuth: Hook for accessing the authentication client, optionally accepting arguments for configuration.
    • useAgentManager: Hook for accessing the AgentManager instance.
    • useUserPrincipal: Hook for accessing the user's principal.

    Each hook is designed to be used within components that are descendants of an AgentProvider, ensuring access to the necessary agent-related context.

    Throws:

    • Error if used outside of an AgentProvider context.

    Integration

    To use these hooks, ensure your components are wrapped in an AgentProvider that you've set up to supply the AgentContext. This context provides the necessary agent functionalities and state management capabilities required by the hooks.