Skip to main content
The Agent class is the main entry point for Credo. This guide covers how to configure your agent with various options and settings.

Basic Configuration

Every Credo agent requires two main things:
  1. Configuration - Settings for the agent behavior
  2. Dependencies - Platform-specific implementations
  3. Modules - Feature modules to enable functionality
import { Agent } from '@credo-ts/core'
import { agentDependencies } from '@credo-ts/node'

const agent = new Agent({
  config: {
    // Agent configuration options
  },
  dependencies: agentDependencies,
  modules: {
    // Feature modules
  }
})

await agent.initialize()

Configuration Options

The InitConfig interface defines all available configuration options:

Logger

Control logging output and verbosity:
import { ConsoleLogger, LogLevel } from '@credo-ts/core'

const agent = new Agent({
  config: {
    logger: new ConsoleLogger(LogLevel.info),
  },
  dependencies: agentDependencies,
  modules: {},
})
Available log levels:
  • LogLevel.test - Most verbose
  • LogLevel.trace
  • LogLevel.debug
  • LogLevel.info
  • LogLevel.warn
  • LogLevel.error
  • LogLevel.fatal
  • LogLevel.off - No logging

Auto-Update Storage

Automatically update storage schema on startup:
const agent = new Agent({
  config: {
    autoUpdateStorageOnStartup: true,
  },
  dependencies: agentDependencies,
  modules: {},
})
Enabling autoUpdateStorageOnStartup will automatically migrate your storage when Credo versions change. Only use this in development or if you have proper backups.

Allow Insecure HTTP URLs

Permit HTTP URLs in contexts that normally require HTTPS:
const agent = new Agent({
  config: {
    allowInsecureHttpUrls: true, // Only for development!
  },
  dependencies: agentDependencies,
  modules: {},
})
Only use allowInsecureHttpUrls: true in development environments. Production agents should always use HTTPS.

Validity Skew Seconds

Allow clock skew tolerance for JWT and credential validation:
const agent = new Agent({
  config: {
    validitySkewSeconds: 60, // Allow 60 seconds of clock skew
  },
  dependencies: agentDependencies,
  modules: {},
})
This is useful for:
  • Mobile devices with inaccurate clocks
  • Distributed systems with slight time differences
  • SD-JWT VC validation
  • Token Status List validation
Default: 30 seconds

Complete Example

Here’s a complete configuration example from the Credo demo:
import { Agent, ConsoleLogger, LogLevel } from '@credo-ts/core'
import { agentDependencies } from '@credo-ts/node'
import { AskarModule } from '@credo-ts/askar'
import { DidCommModule } from '@credo-ts/didcomm'
import { askar } from '@openwallet-foundation/askar-nodejs'

const agent = new Agent({
  config: {
    logger: new ConsoleLogger(LogLevel.info),
    autoUpdateStorageOnStartup: false,
    allowInsecureHttpUrls: false,
    validitySkewSeconds: 30,
  },
  dependencies: agentDependencies,
  modules: {
    askar: new AskarModule({
      askar,
      store: {
        id: 'my-agent',
        key: 'my-secret-key',
      },
    }),
    didcomm: new DidCommModule({
      endpoints: ['http://localhost:3000'],
      connections: {
        autoAcceptConnections: true,
      },
    }),
  },
})

await agent.initialize()
console.log('Agent initialized successfully!')

Accessing Configuration

Once the agent is initialized, you can access its configuration:
// Access the logger
agent.config.logger.info('Hello from agent')

// Check configuration values
const allowsInsecure = agent.config.allowInsecureHttpUrls
const autoUpdate = agent.config.autoUpdateStorageOnStartup
const skewSeconds = agent.config.validitySkewSeconds

Extending Configuration

You can extend the agent configuration after creation:
const extendedConfig = agent.config.extend({
  allowInsecureHttpUrls: true,
})

Agent Lifecycle

1
Create the Agent
2
Instantiate the agent with configuration:
3
const agent = new Agent({ config, dependencies, modules })
4
Initialize
5
Initialize the agent to start all modules and transports:
6
await agent.initialize()
7
Use the Agent
8
Interact with the agent through its API:
9
const connection = await agent.didcomm.connections.createConnection(...)
10
Shutdown
11
Gracefully shutdown when done:
12
await agent.shutdown()

Next Steps

DIDComm Setup

Configure DIDComm messaging and connections

Platform Setup

Set up for Node.js or React Native

Multi-Tenancy

Configure multi-tenant agents

AnonCreds

Enable privacy-preserving credentials

Build docs developers (and LLMs) love