Skip to main content
Version: 0.8 (next)

Agents and modules

Everything you do with Credo goes through an agent. This page explains what an agent holds, how modules extend it, and what agent contexts and tenants are.

The agent​

An agent is an instance of Agent from @credo-ts/core. It holds the configuration, the storage, the keys and the modules for one party, such as an issuer, a verifier, a wallet or a mediator. These roles all use the same Agent class. What an agent can do depends on the modules you register.

You pass three things to the constructor:

  • dependencies: platform-specific dependencies, such as file system access and fetch. Import agentDependencies from @credo-ts/node or @credo-ts/react-native. See Platforms.
  • modules: the modules to register, by key. A storage module is required.
  • config: optional agent-wide settings, such as the logger.
import { Agent } from '@credo-ts/core'
import { agentDependencies } from '@credo-ts/node'
import { OpenId4VcModule } from '@credo-ts/openid4vc'

const agent = new Agent({
dependencies: agentDependencies,
modules: {
...storage, // Storage and key management, see Agent setup
openid4vc: new OpenId4VcModule(),
},
})

await agent.initialize()

storage holds the storage and key management modules, such as Drizzle for the records and Askar for the keys on a server. Storage helps you choose, and Your first agent walks through a complete setup step by step.

Modules​

A module adds functionality to the agent: an API, services, storage records, and sometimes HTTP endpoints or message handlers. Credo is split into packages that each provide one or more modules, so you install only what you use.

  • Default modules are always registered: among others DIDs, W3C credentials, SD-JWT VC, mdoc, X.509 and key management. You use them through properties such as agent.dids, agent.sdJwtVc and agent.kms. Register a module under the same key to configure it, for example dids: new DidsModule({ ... }).
  • Other modules you register yourself, such as DrizzleStorageModule or AskarModule for storage, DidCommModule, OpenId4VcModule, AnonCredsModule and TenantsModule. Their APIs are available under agent.modules.<key>.
  • DidCommModule and OpenId4VcModule are also available as agent.didcomm and agent.openid4vc, but only when you register them under the keys didcomm and openid4vc.

The agent's type follows from the modules you pass, so TypeScript knows which APIs exist. Agent configuration covers storage, key management, caching and logging.

Agent context​

Credo keeps the data of one agent or tenant apart from others through an agent context. The context links storage, keys and configuration to an identifier, the contextCorrelationId. An agent has one root context. Credo passes the context along for you, so you only see it in callbacks, such as getTrustedIssuersForVerification(agentContext, ...), and when you write your own modules.

Tenants​

With @credo-ts/tenants, one agent can host many tenants. Each tenant gets its own agent context, so its own storage and keys, while all tenants share the modules, configuration and transports of the root agent. This uses fewer resources than running an agent per tenant, which matters for hosted issuers, verifiers and cloud wallets. See Multi-tenancy.