The Problem I Was Trying to Solve§

In multi-agent systems, agents communicate dynamically in natural language. While this allows for flexible problem solving, it often leads to communication chaos: agents talking past each other, sending redundant information, or getting stuck in infinite explanation cycles. We needed a framework to enforce strict, state-machine-based interaction protocols (e.g. a contract negotiation pattern) between independent agents. We implemented this using the Ahoy framework.

Our deployment stack consisted of:

  • Ahoy Framework for defining agent roles and protocol states.
  • LangGraph for tracking system graph state.
  • Supabase for persisting conversation state logs.
// Defining an Ahoy interaction protocol
const negotiationProtocol = {
  states: ['OFFER', 'COUNTER_OFFER', 'ACCEPT', 'REJECT'],
  validateTransition: (fromState, toState) => {
    if (fromState === 'OFFER' && toState === 'ACCEPT') return true;
    if (fromState === 'OFFER' && toState === 'COUNTER_OFFER') return true;
    return false; // Blocks invalid transitions
  }
};

Step-by-Step: What I Actually Did§

1. Protocol Modeling: We defined the allowed dialogue steps as a formal state machine inside the Ahoy configuration file. 2. Transition Interception: We injected a validation layer that checks every agent message against the protocol state. If an agent tries to reject an offer before an offer is made, the message is blocked and the agent is prompted to correct its state. 3. State Logging: We logged all valid messages to Supabase, enabling real-time inspection of active negotiations.

Results and Takeaways§

  • Structured Dialogues: Communication loops were reduced by 50% since agents were forced to follow predefined templates.
  • Reliable Outcomes: We achieved deterministic negotiation completions with zero state deadlocks.
  • Enforce Rules: Never let agents communicate without an overlaying protocol layer; structure is key to multi-agent reliability.