ISEK icon indicating copy to clipboard operation
ISEK copied to clipboard

[RFC] Decoupling Agent / Node / Protocol to Improve Flexibility and Lightweight Testing

Open SparkssL opened this issue 1 year ago • 1 comments

[RFC] Decoupling Agent / Node / Protocol to Improve Flexibility and Lightweight Testing

🧱 Current Problem (V1)

The current architecture introduces several tight couplings that make development, testing, and deployment unnecessarily heavy:

  1. Agent is tightly coupled with Node
    → Even running a single Agent requires spinning up a full Node.

  2. Node is tightly coupled with gRPC and the Registry
    → Even for simple local tests, a full registry and gRPC transport must be started.


🎯 Goals (V2 Architecture)

To make the framework more modular and test-friendly, we propose the following design changes:

✅ 1. Decouple Agent from Node

  • Agents should be runnable independently (e.g., for local unit tests, K8s jobs).
  • Introduce a Squad class to group one or more Agents that collaborate on a single task.
agent1 = Agent("Painter")
agent2 = Agent("Manager")
result = agent2.run("prompt")

squad = Squad([agent1, agent2])
result = squad.run("prompt")

✅ 2. Decouple Node from Protocol and Registry

  • Node becomes a standalone communication component:
    • Can act as a service gateway (with Squad)
    • Or as a relay-only node without any attached logic
  • Protocols (A2A, RPC, etc.) are injected, not hardcoded.
a2a_protocol = A2AProtocol.with_p2p()
node = Node(protocol=a2a_protocol)
node.run()
node.attach(squad)  # optional: attach a Squad to handle requests

🧩 Protocol Layer Design

class A2AProtocol:
    def __init__(self, transport):
        self.transport = transport

    @classmethod
    def with_p2p(cls):
        return cls(P2PTransport(libp2p_node))

    @classmethod
    def with_rpc(cls):
        return cls(RPCTransport(rpc_client))

✅ Expected Benefits

  • Local, offline testing becomes easy (no networking dependencies)
  • Node becomes protocol-agnostic (supporting P2P, gRPC, WebRTC, etc.)
  • Deployable in diverse environments: local dev, cloud, edge, MCP
  • Modular design improves maintainability and contributor onboarding

Feedback welcome!
Let us know your thoughts, ideas, or alternative suggestions 🙌

SparkssL avatar Jun 01 '25 14:06 SparkssL

New framwork version pushed to V2 branch.

Moshiii avatar Jun 22 '25 06:06 Moshiii