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()
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.
Agents are one level deep: an agent cannot create agents of its own, so create
agents with a top-level user’s credentials, not with an agent’s API key. If the
acting
user has a parent_user_id (an agent from agents.create(), a
plugin-provisioned agent, or a user created with
create_user(..., parent_user_id=...)), the call raises PermissionDeniedError
(HTTP 403 on POST /api/v1/agents/create). Requested datasets are checked
first, so a dataset error (such as ValueError for a name the caller does not
own) can surface before this one.
Returns a dict with the agent id, display email, and the one-time API key:
agents.list()
agent_id,
agent_email, and api_key_label.
agents.get()
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()
ValueError if the agent does not exist, or
PermissionDeniedError if the acting user is not authorized to delete it.
agents.register()
read access to every
supplied dataset (by id and by name) is validated before the connection is
created; a dataset the caller cannot read raises PermissionDeniedError
(HTTP 403). The check lives in the shared backend operation, so
POST /api/v1/agents/register applies the same rule and answers 403.
Three details of that check are worth knowing:
- Names resolve only among the caller’s own datasets, as everywhere else in
Cognee. A dataset that was shared with the caller does not resolve by name —
pass it in
dataset_idsinstead, or registration fails with403. A name that does not exist yet fails the same way. - A dataset id that is not a valid UUID counts as not accessible and raises
PermissionDeniedError, rather than aValueError. - Ids are stored in canonical UUID form on the connection’s dataset references, so an uppercase or hyphenless spelling still links to its memory source.
agents.unregister()
agents.list_connections()
- Sharing a dataset does not expose its connections. A connection that lists a dataset is not shown to the other readers of that dataset; dataset overlap grants no visibility.
- A connection with no owning user is visible to nobody.
- A persisted connection is trusted only inside its owner’s configuration. An
entry stored under one user’s
agent_configurationbut naming a differentuser_idis skipped, and an entry that fails validation is skipped with a debug log instead of failing the request.
total, has_more, and the connected_agent_ids on each memory source are all
built from the same filtered list, so they follow the same scope.
agents.get_connection()
None if no matching
connection is found. The detail is resolved from the same list
agents.list_connections() returns, so it carries
the same scope: a connection outside the acting user’s scope resolves to None
(HTTP 404 on GET /api/v1/agents/connections/{agent_id}), and the recent
sessions, Q&A, and traces hydrated from the session cache are never read for it.
When agent_session_name is given, the lookup also matches connections that
agents.unregister() has deactivated; they come back with
["agent"]["status"] set to "inactive" instead of None. Without agent_session_name, only
active connections are considered, as with the active_only=True default of
list_connections().
CLI
The same operations are available from the command line via thecognee-cli agents command.