Skip to main content

Traces API

Traces represent conversation contexts for multi-turn interactions and execution tracking. They automatically track message history, state, and provide a unified interface for managing conversation flows.

Overview

Traces are the primary mechanism for:
  • Conversation Context: Multi-turn interactions with AI agents
  • Execution Tracking: Following the execution flow of receptors, neurons, and pathways
  • Message History: Storing and retrieving conversation messages
  • State Management: Maintaining context across multiple interactions
Traces are automatically created when the first message is added via engrams. No explicit creation is required.

List Traces

List traces with filtering and pagination.
GET /v1/traces

Query Parameters

ParameterTypeDescription
brain_idstringFilter by brain ID
receptor_idstringFilter by receptor ID (alias: synapse_id)
user_idstringFilter by user ID
searchstringSearch in trace_id and metadata.title
created_afterstringISO date; filter traces created after
created_beforestringISO date; filter traces created before
limitnumberMax traces to return (default: 20)
offsetnumberPagination offset
sortstringSort field: created_at, updated_at, message_count
orderstringSort order: asc or desc

Example Request

const { traces, total } = await auvy.traces.list({
  limit: 20,
  offset: 0,
  sort: 'created_at',
  order: 'desc',
})

Example Response

{
  "traces": [
    {
      "id": "trace-uuid",
      "trace_id": "trace-id",
      "tenant_id": "workspace-uuid",
      "user_id": "user-uuid",
      "api_key_id": null,
      "synapse_id": "receptor-uuid",
      "created_at": "2024-01-01T00:00:00Z",
      "updated_at": "2024-01-01T00:00:01Z",
      "message_count": 5,
      "cost_summary": {
        "total_cost_usd": 0.01,
        "total_tokens": 1000,
        "input_tokens": 500,
        "output_tokens": 500
      }
    }
  ],
  "total": 42,
  "limit": 20,
  "offset": 0,
  "has_more": true
}
Note: Trace summaries include synapse_id for compatibility; engrams store receptor_id. Use receptor_id when filtering.

Get Trace

Get a single trace by ID.
GET /v1/traces/:id

Path Parameters

ParameterTypeDescription
idstringTrace ID

Example Request

const { trace } = await auvy.traces.get('trace-id')

Example Response

{
  "trace": {
    "id": "trace-id",
    "tenant_id": "tenant-uuid",
    "user_id": "user-uuid",
    "trace_id": "trace-id",
    "created_at": "2024-01-01T00:00:00Z",
    "updated_at": "2024-01-01T00:00:00Z"
  }
}

Get Trace Messages

Get message history for a trace with pagination support.
GET /v1/traces/:id/messages

Path Parameters

ParameterTypeDescription
idstringTrace ID

Query Parameters

ParameterTypeDescription
limitnumberMaximum number of messages to return (default: unlimited)
cursorstringCursor for pagination (optional)

Example Request

// Get all messages
const { messages } = await auvy.traces.getMessages('trace-id')

// Get messages with limit
const { messages } = await auvy.traces.getMessages('trace-id', {
  signal: abortController.signal
})

Example Response

{
  "messages": [
    {
      "id": "msg-uuid",
      "trace_id": "trace-id",
      "role": "user",
      "content": "Hello",
      "metadata": {},
      "created_at": "2024-01-01T00:00:00Z"
    },
    {
      "id": "msg-uuid-2",
      "trace_id": "trace-id",
      "role": "assistant",
      "content": "Hi there!",
      "metadata": {
        "content_blocks": []
      },
      "created_at": "2024-01-01T00:00:01Z"
    }
  ]
}

Message Roles

Messages support the following roles:
  • user - User messages
  • assistant - AI assistant responses
  • system - System messages
  • neuron - Messages from neuron executions

Add Message to Trace

Add a message to a trace. This will automatically create the trace if it doesn’t exist.
POST /v1/traces/:id/messages

Path Parameters

ParameterTypeDescription
idstringTrace ID

Request Body

FieldTypeRequiredDescription
rolestringYesMessage role: user, assistant, system, or neuron
contentstringYesMessage content
metadataobjectNoAdditional metadata (e.g., content_blocks, tool call info)
memory_idsarrayNoArray of memory UUIDs to link to the trace

Example Request

// Simple message
const { message } = await auvy.traces.addMessage('trace-id', {
  role: 'user',
  content: 'Hello, AUVY!'
})

// Message with memory links
const { message } = await auvy.traces.addMessage('trace-id', {
  role: 'user',
  content: 'Analyze this document',
  memory_ids: ['memory-uuid-1', 'memory-uuid-2']
})

Example Response

{
  "message": {
    "id": "msg-uuid",
    "trace_id": "trace-id",
    "role": "user",
    "content": "Hello, AUVY!",
    "metadata": {},
    "created_at": "2024-01-01T00:00:00Z"
  }
}

Public Trace Access

Traces can be accessed via share tokens for public access without requiring full authentication.

Get Public Trace

Get a trace using a share token.
GET /v1/public/traces/:trace_id

Path Parameters

ParameterTypeDescription
trace_idstringTrace ID

Query Parameters

ParameterTypeDescription
tstringShare token (required)
workspacestringWorkspace slug (required)
receptorstringReceptor slug (required)

Example Request

const { trace } = await auvy.public.getTrace(
  'trace-id',
  'share-token',
  'receptor-slug'
)

Get Public Trace Messages

Get messages for a trace using a share token. This endpoint uses /v1/traces/:trace_id/messages with share token authentication via query parameters.
GET /v1/traces/:trace_id/messages

Path Parameters

ParameterTypeDescription
trace_idstringTrace ID

Query Parameters

ParameterTypeDescription
tstringShare token (required)
workspacestringWorkspace slug (required)
receptorstringReceptor slug (required)
limitnumberMaximum number of messages (optional)

Example Request

const { messages } = await auvy.public.getTraceMessages(
  'trace-id',
  'share-token',
  'receptor-slug'
)

Trace Lifecycle

Traces follow a simple lifecycle:
  1. Creation: Traces are automatically created when the first message is added
  2. Messages: Messages are added sequentially to build conversation history
  3. State: Trace state is maintained automatically through engrams
  4. Retrieval: Traces and their messages can be retrieved at any time

Integration with Receptors

Traces are created and managed when you invoke receptors with a trace_id:
const { job_id } = await auvy.receptors.invoke('my-workspace', 'my-receptor', {
  message: 'Hello',
  trace_id: 'trace-id'
})

const status = await auvy.jobs.getStatus(job_id)
const { messages } = await auvy.traces.getMessages('trace-id')

Memory Linking

Traces can be linked to memories for RAG (Retrieval-Augmented Generation):
// Add message with memory links
await auvy.traces.addMessage('trace-id', {
  role: 'user',
  content: 'What do you know about this?',
  memory_ids: ['memory-uuid-1', 'memory-uuid-2']
})

// Memories are automatically linked to the trace's recollection

Error Handling

Common error scenarios:
  • 404 Not Found: Trace doesn’t exist
  • 403 Forbidden: Insufficient permissions to access trace
  • 400 Bad Request: Invalid trace ID format or missing required fields