The MentisDB Agent Memory Cookbook

Patterns and recipes for building AI agents that remember

2.5 Webhook-Driven Workflows

Polling memory chains wastes time and misses urgency. Webhooks let an append wake another system immediately: a CI bot, indexing worker, monitoring process, or second agent. Delivery is asynchronous, so appending a thought does not wait for the downstream service.

The pattern

fn configure_webhook_filters() -> io::Result<()> {
    let dir = tempfile::tempdir()?;
    let manager = mentisdb::WebhookManager::new(dir.path().to_path_buf())?;

    let mut thought_types = std::collections::HashSet::new();
    thought_types.insert(mentisdb::ThoughtType::TaskComplete);
    thought_types.insert(mentisdb::ThoughtType::Mistake);

    let registration = manager.register_webhook(
        "https://example.com/mentisdb/events".to_string(),
        Some("prod-agent-memory".to_string()),
        Some(thought_types),
    )?;

    assert!(registration.active);
    assert_eq!(registration.chain_key_filter.as_deref(), Some("prod-agent-memory"));
    assert!(registration
        .thought_type_filter
        .as_ref()
        .unwrap()
        .contains(&mentisdb::ThoughtType::TaskComplete));

    let all = manager.list_webhooks();
    assert_eq!(all.len(), 1);
    assert_eq!(all[0].id, registration.id);

    assert!(manager.delete_webhook(registration.id)?);
    assert!(manager.list_webhooks().is_empty());
    Ok(())
}

Payload shape

{
  "event": "thought.appended",
  "chain_key": "prod-agent-memory",
  "thought": {
    "thought_type": "TaskComplete",
    "agent_id": "release-bot",
    "content": "Release candidate built and smoke-tested"
  }
}
Do not do critical writes inside the webhook handler only. If the action matters to future agents, append a follow-up thought that records the outcome.