Skip to main content

cognee.agents

Static class for managing agents and their connections. Each agent is backed by its own agent user with a one-time API key, and every operation is scoped to the acting user — permissions are enforced per acting user before any agent is created or any dataset is granted.
Agent emails are displayed in their {slug}@cognee.agent form. Internally each agent user is minted with a unique {slug}+{parent_id}@cognee.agent address; the SDK strips the +{parent_id} segment before returning the email.

Methods

agents.create()

Create a new agent and, optionally, grant it read and write access to one or more datasets. Each requested dataset is resolved and the calling user’s read access to it is verified before the agent user is minted, so a failed authorization never leaves an orphaned agent user with a live API key. Returns a dict with the agent id, display email, and the one-time API key:
agent_api_key is returned only on creation and cannot be retrieved again. Store it at creation time.

agents.list()

List the agents owned by the resolved user. Each entry contains agent_id, agent_email, and api_key_label.

agents.get()

Return details (agent_id, agent_email, api_key_label) for a single agent. Raises ValueError if the agent does not exist, or PermissionDeniedError if the acting user is not authorized to view it.

agents.delete()

Delete an agent by id. Raises ValueError if the agent does not exist, or PermissionDeniedError if the acting user is not authorized to delete it.

agents.register()

Register an agent connection (session). The acting user’s read access to every supplied dataset (by id and by name) is validated before the connection is created. Returns the connection as a JSON-serializable dict.

agents.unregister()

Unregister an agent connection by session name. Returns the number of remaining active connections.

agents.list_connections()

List active agent connections and their memory sources, scoped to the acting user. Connections that are bound neither to an owning user nor to any dataset are filtered out of the result so a caller never sees connections outside their own scope, and total/has_more are adjusted accordingly.

agents.get_connection()

Return the detail for a single agent connection, or None if no matching connection is found.

CLI

The same operations are available from the command line via the cognee-cli agents command.