Urgent.News

What's breaking now, across thousands of outlets.

AI

Building an Agentic System in .NET, Part 5: Designing an Agent Bus in ASP.NET Core

Multi-agent systems fail in boring ways: two agents claim the same task, a disconnected agent misses its hand-off, a heartbeat proves the TCP socket is open but not that the agent is actually doing anything. Before adding the fifth agent to your workflow, you need a bus with defined delivery guarantees, not an improvised pub/sub over in-memory channels. This is Part 5 of the series. We now have…

This is Part 5 of a series building an agentic system in .NET. The focus is on designing an agent bus using ASP.NET Core. The bus provides defined delivery guarantees, addressing common issues in multi-agent systems such as agents claiming the same task, disconnected agents missing hand-offs, and heartbeat checks that only verify socket status.

The four responsibilities of the bus are registration, direct messages, topic channels, and task hand-offs. Registration allows agents to announce their capabilities and maintain a heartbeat. Direct messages are guaranteed at-least-once delivery. Topic channels enable agents to subscribe to specific topics, receiving broadcast messages from all active subscribers. Hand-offs ensure exactly one agent claims a task for delegation, with self-contained payload allowing a cold agent to resume without additional calls.

SignalR serves as the notification layer, pushing live updates to connected agents. The Postgres database serves as the source of truth, while SignalR enhances the user experience.

To implement the bus, four EF Core entities are defined: Agent, BusMessage, ChannelSubscription, and Handoff. The Agent entity stores agent details like ID, name, capabilities, status, heartbeat timestamp, and SignalR connection ID. AgentStatus includes three possible states: Offline, Online, and Stale.

The BusMessage entity represents messages exchanged between agents. It includes a message ID, target agent ID (null for channel broadcast), channel name, sender agent ID, payload (JSON), processed status, and creation timestamp. The ChannelSubscription entity links agents to their subscriptions to specific channels, including subscribed agent ID, channel name, and subscription timestamp.

The Handoff entity manages task delegation between agents. It includes a unique handoff ID, origin agent ID, conversation ID, objective, message history (JSON), tool context (JSON), context version, status, claimed agent ID, and timestamps. The HandoffStatus enum defines four possible states: Unclaimed, Claimed, Completed, and Expired.

To ensure task claims are unique, a SELECT FOR UPDATE SKIP LOCKED query is used within an explicit transaction, avoiding concurrent agents attempting to claim the same task. The model is mapped to PostgreSQL using EF Core 10, with MessageHistory and ToolContext columns defined as jsonb data types and an index added on Handoff.Status to optimize claim queries under load.

Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.

Read the original at dev.to →

More in AI

How to build a Financial Research Agent with SEC Filings and Market Data

Day 5 of 30 Days of Search. Quick Summary: You read the company’s filings, check the share price, and work through the numbers in a spreadsheet.

  • Use Valyu SDK and Vercel AI SDK for financial search tools
  • Combine secSearch, financeSearch, and economicsSearch for research reports
  • Adjust stepCountIs to control output length and tool usage

More from Monday 5 October →