async def from_db_dict(
        cls, agent_dict: dict, locations: list[Location], context: WorldContext
    ):
        """Create an agent from a dictionary retrieved from the database."""
        database = await get_database()
        plans = await database.get_by_ids(Tables.Plans, agent_dict["ordered_plan_ids"])

        ordered_plans: list[dict] = sorted(
            plans, key=lambda plan: agent_dict["ordered_plan_ids"].index(plan["id"])
        )

        memories_data = await database.get_by_field(
            Tables.Memories, "agent_id", str(agent_dict["id"])
        )

        plans = []
        for plan in ordered_plans:
            location = [
                location
                for location in locations
                if str(location.id) == plan["location_id"]
            ][0]

            related_event = (
                await Event.from_id(plan["related_event_id"])
                if plan["related_event_id"] is not None
                else None
            )
            related_message = (
                AgentMessage.from_event(related_event, context)
                if related_event
                else None
            )
            plans.append(
                SinglePlan(
                    **{
                        key: value
                        for key, value in plan.items()
                        if (key != "location_id" and key != "related_event_id")
                    },
                    location=location,
                    related_message=related_message,
                )
            )

        agent_location = [
            location
            for location in locations
            if str(location.id) == agent_dict["location_id"]
        ][0]

        return cls(
            id=agent_dict["id"],
            full_name=agent_dict["full_name"],
            private_bio=agent_dict["private_bio"],
            public_bio=agent_dict["public_bio"],
            directives=agent_dict["directives"],
            last_checked_events=agent_dict["last_checked_events"],
            world_id=agent_dict["world_id"],
            location=agent_location,
            context=context,
            memories=[SingleMemory(**memory) for memory in memories_data],
            plans=plans,
            discord_bot_token=agent_dict["discord_bot_token"],
        )
Create an agent from a dictionary retrieved from the database.
src/agent/base.py