Skip to main content

DRPC Module

The @credo-ts/drpc package provides Distributed Remote Procedure Call (DRPC) functionality for secure agent-to-agent communication.

Installation

npm install @credo-ts/drpc

Registration

import { Agent } from '@credo-ts/core'
import { DrpcModule } from '@credo-ts/drpc'

const agent = new Agent({
  // ... config
  modules: {
    drpc: new DrpcModule(),
  },
})

What It Provides

The DRPC module enables:
  • Remote procedure calls between connected agents
  • Request-response patterns over DIDComm
  • Type-safe RPC definitions
  • Async/await style communication

Usage

Defining RPC Methods

interface MyRpcMethods {
  getUserInfo: (userId: string) => Promise<UserInfo>
  updateSettings: (settings: Settings) => Promise<void>
}

Calling Remote Methods

const result = await agent.modules.drpc.request<MyRpcMethods>({
  connectionId: connection.id,
  method: 'getUserInfo',
  params: ['user-123'],
})

console.log('User info:', result)

Handling RPC Requests

import { DrpcEventTypes } from '@credo-ts/drpc'

agent.events.on(DrpcEventTypes.DrpcRequest, async (event) => {
  const { method, params, connectionId } = event.payload
  
  let result
  
  switch (method) {
    case 'getUserInfo':
      result = await getUserInfo(params[0])
      break
    case 'updateSettings':
      await updateSettings(params[0])
      result = { success: true }
      break
  }
  
  await agent.modules.drpc.respond({
    connectionId,
    requestId: event.payload.requestId,
    result,
  })
})

Use Cases

  • Service Integration - Connect microservices via DIDComm
  • Agent Orchestration - Coordinate multiple agents
  • Data Synchronization - Sync data between agents
  • Distributed Workflows - Implement multi-agent workflows

Error Handling

try {
  const result = await agent.modules.drpc.request({
    connectionId: connection.id,
    method: 'riskyOperation',
    params: [],
  })
} catch (error) {
  if (error.code === 'METHOD_NOT_FOUND') {
    console.error('Remote method not found')
  } else if (error.code === 'EXECUTION_ERROR') {
    console.error('Remote execution failed:', error.message)
  }
}

Security Considerations

  • All RPC calls are authenticated via DIDComm
  • Requests are encrypted end-to-end
  • Validate input parameters on the server side
  • Implement rate limiting for public endpoints
  • Use timeouts to prevent hanging requests

See Also

Build docs developers (and LLMs) love